/** * 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); }
/** without sig! */ @Override protected byte[] getBytes() { if (_byteified != null) return _byteified; if (_destination == null) return null; int len = size(); ByteArrayOutputStream out = new ByteArrayOutputStream(len); try { writeBytesWithoutSig(out); } catch (IOException ioe) { ioe.printStackTrace(); return null; } catch (DataFormatException dfe) { dfe.printStackTrace(); return null; } byte rv[] = out.toByteArray(); // if we are floodfill and this was published to us if (_receivedAsPublished) _byteified = rv; return rv; }
/** * Sign the structure using the supplied signing key. * Overridden because LS2 sigs cover the type byte. * * @throws IllegalStateException if already signed */ @Override public void sign(SigningPrivateKey key) throws DataFormatException { if (_signature != null) throw new IllegalStateException(); if (key == null) throw new DataFormatException("No signing key"); int len = size(); ByteArrayOutputStream out = new ByteArrayOutputStream(1 + len); try { // unlike LS1, sig covers type out.write(getType()); writeBytesWithoutSig(out); } catch (IOException ioe) { throw new DataFormatException("Signature failed", ioe); } byte data[] = out.toByteArray(); // now sign with the key _signature = DSAEngine.getInstance().sign(data, key); if (_signature == null) throw new DataFormatException("Signature failed with " + key.getType() + " key"); }
writeBytesWithoutSig(out); } catch (IOException ioe) { ioe.printStackTrace();