public void readBytes(InputStream rawConfig) throws DataFormatException, IOException { _destination = Destination.create(rawConfig); _options = DataHelper.readProperties(rawConfig); _creationDate = DataHelper.readDate(rawConfig); _signature = new Signature(_destination.getSigningPublicKey().getType()); _signature.readBytes(rawConfig); }
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); }
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); }
public DataStructure createDataStructure() throws DataFormatException { Destination dest = new Destination(); StructureTest tst = new CertificateTest(); dest.setCertificate((Certificate)tst.createDataStructure()); tst = new PublicKeyTest(); dest.setPublicKey((PublicKey)tst.createDataStructure()); tst = new SigningPublicKeyTest(); dest.setSigningPublicKey((SigningPublicKey)tst.createDataStructure()); return dest; } public DataStructure createStructureToRead() { return new Destination(); }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_destination == null) || (_options == null) || (_signature == null) || (_creationDate == null)) throw new DataFormatException("Not enough data to create the session config"); _destination.writeBytes(out); DataHelper.writeProperties(out, _options, true); // UTF-8 DataHelper.writeDate(out, _creationDate); _signature.writeBytes(out); }
public DataStructure createDataStructure() throws DataFormatException { LeaseSet leaseSet = new LeaseSet(); leaseSet.setDestination((Destination)(new DestinationTest()).createDataStructure()); leaseSet.setEncryptionKey((PublicKey)(new PublicKeyTest()).createDataStructure()); leaseSet.setSignature((Signature)(new SignatureTest()).createDataStructure()); leaseSet.setSigningKey((SigningPublicKey)(new SigningPublicKeyTest()).createDataStructure()); //leaseSet.setVersion(42l); return leaseSet; } public DataStructure createStructureToRead() { return new LeaseSet(); }
/** * 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 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); }
public String toBase64() { byte data[] = toByteArray(); if (data == null) return null; return Base64.encode(data); }
public void readBytes(InputStream in) throws DataFormatException, IOException { int size = (int) DataHelper.readLong(in, 4); if (size < 0 || size > MAX_LENGTH) throw new DataFormatException("payload size out of range (" + size + ")"); _encryptedData = new byte[size]; int read = read(in, _encryptedData); if (read != size) throw new DataFormatException("Incorrect number of bytes read in the payload structure"); //if (_log.shouldLog(Log.DEBUG)) // _log.debug("read payload: " + read + " bytes"); }
protected void readHeader(InputStream in) throws DataFormatException, IOException { _destination = Destination.create(in); _published = DataHelper.readLong(in, 4) * 1000; _expires = _published + (DataHelper.readLong(in, 2) * 1000); _flags = (int) DataHelper.readLong(in, 2); if (isOffline()) readOfflineBytes(in); }
/** * 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 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); }
@Override public boolean equals(Object object) { if (object == this) return true; if ((object == null) || !(object instanceof MetaLeaseSet)) return false; MetaLeaseSet ls = (MetaLeaseSet) object; return DataHelper.eq(_signature, ls.getSignature()) && DataHelper.eq(_leases, ls._leases) && DataHelper.eq(_destination, ls.getDestination()); }
/** * If true, we received this LeaseSet by a remote peer publishing it to * us, AND the unpublished flag is not set. * Default false. * * @since 0.9.39 overridden */ @Override public boolean getReceivedAsPublished() { return super.getReceivedAsPublished() && !isUnpublished(); }