/** * @param payload 4 bytes minimum if non-null * @throws DataFormatException */ public KeyCertificate(byte[] payload) throws DataFormatException { super(CERTIFICATE_TYPE_KEY, payload); if (payload != null && payload.length < HEADER_LENGTH) throw new DataFormatException("data"); }
/** * Overridden for efficiency. * @param data non-null * @throws DataFormatException if null or wrong length */ @Override public void fromByteArray(byte data[]) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); if (data.length != 4) throw new DataFormatException("Bad data length"); _tunnelId = (int) DataHelper.fromLong(data, 0, 4); }
public void fromByteArray(byte data[]) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); try { ByteArrayInputStream bais = new ByteArrayInputStream(data); readBytes(bais); } catch (IOException ioe) { throw new DataFormatException("Error reading the byte array", ioe); } }
/** * Up-convert this to a KeyCertificate * * @throws DataFormatException if cert type != CERTIFICATE_TYPE_KEY * @since 0.9.12 */ public KeyCertificate toKeyCertificate() throws DataFormatException { if (_type != CERTIFICATE_TYPE_KEY) throw new DataFormatException("type"); return new KeyCertificate(this); }
public void fromBase64(String data) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); byte bytes[] = Base64.decode(data); if (bytes == null) throw new DataFormatException("Bad Base64 \"" + data + '"'); fromByteArray(bytes); }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_encryptedData == null) throw new DataFormatException("Not yet encrypted. Please set the encrypted data"); DataHelper.writeLong(out, 4, _encryptedData.length); out.write(_encryptedData); //if (_log.shouldLog(Log.DEBUG)) // _log.debug("wrote payload: " + _encryptedData.length); }
/** * Overridden for efficiency. * @param data non-null * @throws DataFormatException if null or wrong length */ @Override public void fromByteArray(byte data[]) throws DataFormatException { if (data == null) throw new DataFormatException("Null data passed in"); if (data.length != 8) throw new DataFormatException("Bad data length"); _flags = (int) DataHelper.fromLong(data, 0, 2); _date = DataHelper.fromLong(data, 2, 6); }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { try { writeMessage(out); } catch (I2CPMessageException ime) { throw new DataFormatException("Error writing the message", ime); } }
public void readBytes(InputStream in) throws DataFormatException, IOException { try { readMessage(in); } catch (I2CPMessageException ime) { throw new DataFormatException("Error reading the message", ime); } }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_type < 0) throw new DataFormatException("Invalid certificate type: " + _type); //if ((_type != 0) && (_payload == null)) throw new DataFormatException("Payload is required for non null type"); out.write((byte) _type); if (_payload != null) { DataHelper.writeLong(out, 2, _payload.length); out.write(_payload); } else { DataHelper.writeLong(out, 2, 0L); } }
@Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_gateway == null) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); // flags DataHelper.writeLong(out, 2, 0); out.write(_type); out.write(_cost); DataHelper.writeLong(out, 4, _end.getTime() / 1000); }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_certificate == null) || (_publicKey == null) || (_signingKey == null)) throw new DataFormatException("Not enough data to format the router identity"); _publicKey.writeBytes(out); if (_padding != null) out.write(_padding); else if (_signingKey.length() < SigningPublicKey.KEYSIZE_BYTES) throw new DataFormatException("No padding set"); _signingKey.writeTruncatedBytes(out); _certificate.writeBytes(out); }
/** * Without sig. This does NOT validate the signature */ protected void writeBytesWithoutSig(OutputStream out) throws DataFormatException, IOException { if (_destination == null || _encryptionKey == null) throw new DataFormatException("Not enough data to write out a LeaseSet"); // LS2 header writeHeader(out); // LS2 part writeBody(out); }
/** * Including sig. This does NOT validate the signature */ @Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if (_signature == null) throw new DataFormatException("Not enough data to write out a LeaseSet"); writeBytesWithoutSig(out); _signature.writeBytes(out); }
/** * Up-convert a cert to this class * * @param cert payload 4 bytes minimum if non-null * @throws DataFormatException if cert type != CERTIFICATE_TYPE_KEY */ public KeyCertificate(Certificate cert) throws DataFormatException { this(cert.getPayload()); if (cert.getCertificateType() != CERTIFICATE_TYPE_KEY) throw new DataFormatException("type"); }
@Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_gateway == null) || (_tunnelId == null)) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); _tunnelId.writeBytes(out); DataHelper.writeLong(out, 4, _end.getTime() / 1000); }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_gateway == null) || (_tunnelId == null)) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); _tunnelId.writeBytes(out); DataHelper.writeDate(out, _end); }
protected void writeOfflineBytes(OutputStream out) throws DataFormatException, IOException { if (_transientSigningPublicKey == null || _offlineSignature == null) throw new DataFormatException("No offline key/sig"); DataHelper.writeLong(out, 4, _transientExpires / 1000); DataHelper.writeLong(out, 2, _transientSigningPublicKey.getType().getCode()); _transientSigningPublicKey.writeBytes(out); _offlineSignature.writeBytes(out); }
/** * Overridden because we have a blinded key, not a dest */ @Override protected void writeOfflineBytes(OutputStream out) throws DataFormatException, IOException { if (_transientSigningPublicKey == null || _offlineSignature == null) throw new DataFormatException("No offline key/sig"); DataHelper.writeLong(out, 4, _transientExpires / 1000); DataHelper.writeLong(out, 2, _signingKey.getType().getCode()); _transientSigningPublicKey.writeBytes(out); _offlineSignature.writeBytes(out); }
protected void readOfflineBytes(InputStream in) throws DataFormatException, IOException { _transientExpires = DataHelper.readLong(in, 4) * 1000; int itype = (int) DataHelper.readLong(in, 2); SigType type = SigType.getByCode(itype); if (type == null) throw new DataFormatException("Unknown sig type " + itype); _transientSigningPublicKey = new SigningPublicKey(type); _transientSigningPublicKey.readBytes(in); SigType stype = _destination.getSigningPublicKey().getType(); _offlineSignature = new Signature(stype); _offlineSignature.readBytes(in); }