@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if ((_sessionId == null) || (_signingPrivateKey == null) || (_privateKey == null) || (_leaseSet == null)) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); int size = 4 // sessionId + _signingPrivateKey.length() + PrivateKey.KEYSIZE_BYTES + _leaseSet.size(); ByteArrayOutputStream os = new ByteArrayOutputStream(size); try { _sessionId.writeBytes(os); _signingPrivateKey.writeBytes(os); _privateKey.writeBytes(os); _leaseSet.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { int type = _leaseSet.getType(); if (_sessionId == null || _leaseSet == null || (type != DatabaseEntry.KEY_TYPE_META_LS2 && (_signingPrivateKey == null || _privateKey == null))) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); int size = 4 // sessionId + 1 // type + _leaseSet.size() + _signingPrivateKey.length() + _privateKey.length(); ByteArrayOutputStream os = new ByteArrayOutputStream(size); try { _sessionId.writeBytes(os); os.write(_leaseSet.getType()); _leaseSet.writeBytes(os); if (type != DatabaseEntry.KEY_TYPE_META_LS2) { _signingPrivateKey.writeBytes(os); for (PrivateKey pk : getPrivateKeys()) { pk.writeBytes(os); } } } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Test public void testNullData() throws Exception{ PrivateKey privateKey = new PrivateKey(); privateKey.toString(); exception.expect(DataFormatException.class); exception.expectMessage("No data to write out"); privateKey.writeBytes(new ByteArrayOutputStream()); }
/** * Copied from I2PClientImpl.createDestination() */ public void write() throws IOException, DataFormatException { OutputStream out = null; try { out = new SecureFileOutputStream(this.file); this.dest.writeBytes(out); this.privKey.writeBytes(out); this.signingPrivKey.writeBytes(out); if (isOffline()) { DataHelper.writeLong(out, 4, _offlineExpiration / 1000); DataHelper.writeLong(out, 2, _transientSigningPubKey.getType().getCode()); _transientSigningPubKey.writeBytes(out); _offlineSignature.writeBytes(out); _transientSigningPrivKey.writeBytes(out); } } finally { if (out != null) { try { out.close(); } catch (IOException ioe) {} } } }
priv.writeBytes(out); signingPrivKey.writeBytes(out); try { out.close(); } catch (IOException ioe) {}
keys[0].writeBytes(keyStream); // signing pub Certificate.NULL_CERT.writeBytes(keyStream); priv.writeBytes(keyStream); keys[1].writeBytes(keyStream); // signing priv } catch (GeneralSecurityException e) {
privateKey.writeBytes(destKeyStream); signingPrivKey.writeBytes(destKeyStream); destKeyStream.flush();
keys[0].writeBytes(keyStream); // signing pub Certificate.NULL_CERT.writeBytes(keyStream); priv.writeBytes(keyStream); keys[1].writeBytes(keyStream); // signing priv } catch (GeneralSecurityException e) {