protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException { if (size == 0) { _dest = null; _hash = null; } else { try { if (size == Hash.HASH_LENGTH) { _hash = Hash.create(in); } else { _dest = Destination.create(in); } } catch (DataFormatException dfe) { _dest = null; _hash = null; } } }
/** returns null on error */ public DestEntry construct(byte[] b) { DestEntry rv = new DestEntry(); ByteArrayInputStream bais = new ByteArrayInputStream(b); try { rv.props = DataHelper.readProperties(bais); //dest.readBytes(bais); // Will this flush the dest cache too much? rv.dest = Destination.create(bais); } catch (IOException ioe) { logError("DB Read Fail", ioe); return null; } catch (DataFormatException dfe) { logError("DB Read Fail", dfe); return null; } return rv; } }
/** returns null on error */ public DestEntry construct(byte[] b) { DestEntry rv = new DestEntry(); ByteArrayInputStream bais = new ByteArrayInputStream(b); try { int sz = bais.read() & 0xff; if (sz <= 0) throw new DataFormatException("bad dest count " + sz); rv.props = readProperties(bais); rv.dest = Destination.create(bais); if (sz > 1) { rv.propsList = new ArrayList<Properties>(sz); rv.destList = new ArrayList<Destination>(sz); rv.propsList.add(rv.props); rv.destList.add(rv.dest); for (int i = 1; i < sz; i++) { rv.propsList.add(readProperties(bais)); rv.destList.add(Destination.create(bais)); } } } catch (IOException ioe) { logError("DB Read Fail", ioe); return null; } catch (DataFormatException dfe) { logError("DB Read Fail", dfe); return null; } return rv; } }
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException { try { _sessionId = new SessionId(); _sessionId.readBytes(in); _reqID = DataHelper.readLong(in, 4); _code = (int) DataHelper.readLong(in, 1); if (_code == RESULT_SUCCESS) _dest = Destination.create(in); } catch (DataFormatException dfe) { throw new I2CPMessageException("bad data", dfe); } }
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); }
/** * Check whether a base64-encoded {dest,privkey,signingprivkey} is valid * * @param dest The base64-encoded destination and keys to be checked (same format as PrivateKeyFile) * @return true if valid */ public static boolean checkPrivateDestination(String dest) { byte[] b = Base64.decode(dest); if (b == null || b.length < 663) return false; ByteArrayInputStream destKeyStream = new ByteArrayInputStream(b); try { Destination d = Destination.create(destKeyStream); new PrivateKey().readBytes(destKeyStream); SigningPrivateKey spk = new SigningPrivateKey(d.getSigningPublicKey().getType()); spk.readBytes(destKeyStream); } catch (DataFormatException e) { return false; } catch (IOException e) { return false; } return destKeyStream.available() == 0; }
/** * Read the body into the data structures * * @throws IOException */ @Override public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOException { if (type != getType()) throw new I2CPMessageException("Invalid message type (found: " + type + " supported: " + getType() + " class: " + getClass().getName() + ")"); if (length < 0) throw new IOException("Negative payload size"); try { _sessionId = new SessionId(); _sessionId.readBytes(in); _destination = Destination.create(in); _payload = new Payload(); _payload.readBytes(in); _nonce = DataHelper.readLong(in, 4); } catch (DataFormatException dfe) { throw new I2CPMessageException("Unable to load the message data", dfe); } }
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); }
rxDest = Destination.create(dgStream); SigType type = rxDest.getSigningPublicKey().getType(); if (type == null)
if (_destination != null) throw new IllegalStateException(); _destination = Destination.create(in); _encryptionKey = PublicKey.create(in);
ByteArrayInputStream bais = new ByteArrayInputStream(buffer, cur, length - cur); try { Destination optionFrom = Destination.create(bais); cur += optionFrom.size(); _optionFrom = optionFrom;
ByteArrayInputStream bais = new ByteArrayInputStream(buffer, cur, length - cur); try { Destination optionFrom = Destination.create(bais); cur += optionFrom.size(); _optionFrom = optionFrom;