signingPrivateKey.writeBytes(fileOutputStream);
@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(); }
/** * 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) {} } } }
@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 testShortData() throws Exception{ SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); byte data[] = new byte[56]; for (int i = 0; i < data.length; i++) data[i] = (byte)(i); exception.expect(IllegalArgumentException.class); exception.expectMessage("Bad data length: 56; required: " + SigningPrivateKey.KEYSIZE_BYTES); signingPrivateKey.setData(data); signingPrivateKey.writeBytes(new ByteArrayOutputStream()); }
@Test public void testNullData() throws Exception{ SigningPrivateKey signingPrivateKey = new SigningPrivateKey(); signingPrivateKey.toString(); exception.expect(DataFormatException.class); exception.expectMessage("No data to write out"); signingPrivateKey.writeBytes(new ByteArrayOutputStream()); }
d.writeBytes(out); priv.writeBytes(out); signingPrivKey.writeBytes(out); try { out.close(); } catch (IOException ioe) {}
signingPrivKey.writeBytes(destKeyStream); destKeyStream.flush();