Package net.i2p.data

Class KeysAndCert

All Implemented Interfaces:
Serializable, DataStructure
Direct Known Subclasses:
Destination, RouterIdentity

public class KeysAndCert extends DataStructureImpl
KeysAndCert has a public key, a signing key, and a certificate. In that order. We also store a cached Hash. Implemented in 0.8.2 and retrofitted over Destination and RouterIdentity. There's actually no difference between the two of them. As of 0.9.9 this data structure is immutable after the two keys and the certificate are set; attempts to change them will throw an IllegalStateException.
Since:
0.8.2
Author:
zzz
See Also:
  • Field Details

    • _publicKey

      protected PublicKey _publicKey
    • _signingKey

      protected SigningPublicKey _signingKey
    • _certificate

      protected Certificate _certificate
    • _padding

      protected byte[] _padding
  • Constructor Details

    • KeysAndCert

      public KeysAndCert()
  • Method Details

    • getCertificate

      public Certificate getCertificate()
    • setCertificate

      public void setCertificate(Certificate cert)
      Throws:
      IllegalStateException - if was already set
    • getSigType

      public SigType getSigType()
      Returns:
      null if not set or unknown
      Since:
      0.9.17
    • getEncType

      public EncType getEncType()
      Returns:
      null if not set or unknown
      Since:
      0.9.42
    • getPublicKey

      public PublicKey getPublicKey()
      Valid for RouterIdentities. May contain random padding for Destinations.
      Since:
      0.9.42
    • setPublicKey

      public void setPublicKey(PublicKey key)
      Throws:
      IllegalStateException - if was already set
    • getSigningPublicKey

      public SigningPublicKey getSigningPublicKey()
    • setSigningPublicKey

      public void setSigningPublicKey(SigningPublicKey key)
      Throws:
      IllegalStateException - if was already set
    • getPadding

      public byte[] getPadding()
      Since:
      0.9.16
    • setPadding

      public void setPadding(byte[] padding)
      Throws:
      IllegalStateException - if was already set
      Since:
      0.9.12
    • readBytes

      public void readBytes(InputStream in) throws DataFormatException, IOException
      Description copied from interface: DataStructure
      Load up the current object with data from the given stream. Data loaded this way must match the I2P data structure specification. Warning - many classes will throw IllegalStateException if data is already set.
      Parameters:
      in - stream to read from
      Throws:
      IllegalStateException - if data already set
      DataFormatException - if the data is improperly formatted
      IOException - if there was a problem reading the stream
    • combinePadding

      protected static byte[] combinePadding(byte[] pad1, byte[] pad2)
      Returns:
      null if both are null
      Since:
      0.9.42
    • writeBytes

      public void writeBytes(OutputStream out) throws DataFormatException, IOException
      Description copied from interface: DataStructure
      Write out the data structure to the stream, using the format defined in the I2P data structure specification.
      Parameters:
      out - stream to write to
      Throws:
      DataFormatException - if the data was incomplete or not yet ready to be written
      IOException - if there was a problem writing to the stream
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      the signing key has enough randomness in it to use it by itself for speed
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • calculateHash

      public Hash calculateHash()
      Throws IllegalStateException if keys and cert are not initialized, as of 0.9.12. Prior to that, returned null.
      Specified by:
      calculateHash in interface DataStructure
      Overrides:
      calculateHash in class DataStructureImpl
      Returns:
      SHA256 hash, or null if there were problems (data format or io errors)
      Throws:
      IllegalStateException
    • getHash

      public Hash getHash()
      Throws IllegalStateException if keys and cert are not initialized, as of 0.9.12. Prior to that, returned null.
      Throws:
      IllegalStateException