Package net.i2p.data
Class KeysAndCert
java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.KeysAndCert
- All Implemented Interfaces:
Serializable
,DataStructure
- Direct Known Subclasses:
Destination
,RouterIdentity
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 Summary
Modifier and TypeFieldDescriptionprotected Certificate
protected byte[]
protected PublicKey
protected SigningPublicKey
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionThrows IllegalStateException if keys and cert are not initialized, as of 0.9.12.protected static byte[]
combinePadding
(byte[] pad1, byte[] pad2) boolean
getHash()
Throws IllegalStateException if keys and cert are not initialized, as of 0.9.12.byte[]
Valid for RouterIdentities.int
hashCode()
the signing key has enough randomness in it to use it by itself for speedvoid
readBytes
(InputStream in) Load up the current object with data from the given stream.void
setCertificate
(Certificate cert) void
setPadding
(byte[] padding) void
setPublicKey
(PublicKey key) void
toString()
void
writeBytes
(OutputStream out) Write out the data structure to the stream, using the format defined in the I2P data structure specification.Methods inherited from class net.i2p.data.DataStructureImpl
fromBase64, fromByteArray, read, toBase64, toByteArray
-
Field Details
-
_publicKey
-
_signingKey
-
_certificate
-
_padding
protected byte[] _padding
-
-
Constructor Details
-
KeysAndCert
public KeysAndCert()
-
-
Method Details
-
getCertificate
-
setCertificate
- Throws:
IllegalStateException
- if was already set
-
getSigType
- Returns:
- null if not set or unknown
- Since:
- 0.9.17
-
getEncType
- Returns:
- null if not set or unknown
- Since:
- 0.9.42
-
getPublicKey
Valid for RouterIdentities. May contain random padding for Destinations.- Since:
- 0.9.42
-
setPublicKey
- Throws:
IllegalStateException
- if was already set
-
getSigningPublicKey
-
setSigningPublicKey
- 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
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 setDataFormatException
- if the data is improperly formattedIOException
- 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
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 writtenIOException
- if there was a problem writing to the stream
-
equals
-
hashCode
public int hashCode()the signing key has enough randomness in it to use it by itself for speed -
toString
-
calculateHash
Throws IllegalStateException if keys and cert are not initialized, as of 0.9.12. Prior to that, returned null.- Specified by:
calculateHash
in interfaceDataStructure
- Overrides:
calculateHash
in classDataStructureImpl
- Returns:
- SHA256 hash, or null if there were problems (data format or io errors)
- Throws:
IllegalStateException
-
getHash
Throws IllegalStateException if keys and cert are not initialized, as of 0.9.12. Prior to that, returned null.- Throws:
IllegalStateException
-