public class Certificate extends DataStructureImpl
Certificate offers flexible metadata attachment to I2P identities:
Supported Certificate Types:
CERTIFICATE_TYPE_NULL - No certificate (default)CERTIFICATE_TYPE_HIDDEN - Service should not be publishedCERTIFICATE_TYPE_SIGNED - Signed by certificate authorityCERTIFICATE_TYPE_MULTIPLE - Contains multiple certificatesCERTIFICATE_TYPE_KEY - Specifies key types (KeyCertificate)Common Use Cases:
Security Considerations:
Implementation Notes:
Related Structures:
Destination - Uses certificates for service identityRouterIdentity - Router certificatesKeyCertificate - Specialized certificate for key type specification| Modifier and Type | Field and Description |
|---|---|
protected byte[] | _payloadCertificate payload data |
protected int | _typeCertificate type identifier |
static int | CERTIFICATE_LENGTH_SIGNED_WITH_HASHLength of signed certificate with hash (signature + hash) |
static int | CERTIFICATE_TYPE_HIDDENwe should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us) |
static int | CERTIFICATE_TYPE_KEYKey certificate type. |
static int | CERTIFICATE_TYPE_MULTIPLEContains multiple certs |
static int | CERTIFICATE_TYPE_NULLSpecifies a null certificate type with no payload |
static int | CERTIFICATE_TYPE_SIGNEDSigned with 40-byte Signature and (optional) 32-byte hash |
static Certificate | NULL_CERTNull certificate singleton |
| Constructor and Description |
|---|
Certificate()Creates a new Certificate with default values. |
Certificate(int type,
byte[] payload)Construct a certificate with the given type and payload. |
| Modifier and Type | Method and Description |
|---|---|
static Certificate | create(byte[] data,
int off)If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new |
static Certificate | create(InputStream in)If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new |
boolean | equals(Object object) |
int | getCertificateType()Certificate type. |
byte[] | getPayload()Certificate payload, or null. |
int | hashCode() |
int | readBytes(byte[] source,
int offset)Reads the certificate from the source array. |
void | readBytes(InputStream in)Reads the certificate from an input stream. |
void | setCertificateType(int type)Certificate type to set. |
void | setPayload(byte[] payload)Certificate payload to set. |
int | size()Serialized size in bytes. |
KeyCertificate | toKeyCertificate()Up-convert this to a KeyCertificate |
String | toString() |
int | writeBytes(byte[] target,
int offset)Writes the certificate to the target array. |
void | writeBytes(OutputStream out)Write out the data structure to the stream, using the format defined in the
I2P data structure specification. |
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArrayprotected byte[] _payload
protected int _type
public static final int CERTIFICATE_LENGTH_SIGNED_WITH_HASH
public static final int CERTIFICATE_TYPE_HIDDEN
public static final int CERTIFICATE_TYPE_KEY
public static final int CERTIFICATE_TYPE_MULTIPLE
public static final int CERTIFICATE_TYPE_NULL
public static final int CERTIFICATE_TYPE_SIGNED
public static final Certificate NULL_CERT
public Certificate()
public Certificate(int type,
byte[] payload)type - the certificate typepayload - the certificate payload (may be null)IllegalArgumentException - if type < 0public static Certificate create(byte[] data, int off) throws DataFormatException
data - the source dataoff - the offset into dataDataFormatException - if not enough bytespublic static Certificate create(InputStream in) throws DataFormatException, IOException
in - the input streamDataFormatException - if the data is malformedIOException - if there is an I/O errorpublic int getCertificateType()
public byte[] getPayload()
public int readBytes(byte[] source,
int offset)
throws DataFormatExceptionsource - the sourceoffset - the starting offset in the sourceIllegalStateException - if already setDataFormatException - if the data is malformedpublic void readBytes(InputStream in) throws DataFormatException, IOException
in - stream to read fromIllegalStateException - if already setDataFormatException - if the data is improperly formattedIOException - if there was a problem reading the streampublic void setCertificateType(int type)
type - the certificate type to setIllegalArgumentException - if type < 0IllegalStateException - if already setpublic void setPayload(byte[] payload)
payload - the payload to setIllegalStateException - if already setpublic int size()
public KeyCertificate toKeyCertificate() throws DataFormatException
DataFormatException - if cert type != CERTIFICATE_TYPE_KEYpublic int writeBytes(byte[] target,
int offset)target - the output arrayoffset - the starting offset in the targetpublic void writeBytes(OutputStream out) throws DataFormatException, IOException
DataStructureout - stream to write toDataFormatException - if the data was incomplete or not yet ready to be writtenIOException - if there was a problem writing to the stream