Package net.i2p.data
Class Certificate
java.lang.Object
net.i2p.data.DataStructureImpl
net.i2p.data.Certificate
- All Implemented Interfaces:
Serializable,DataStructure
- Direct Known Subclasses:
KeyCertificate
public class Certificate extends DataStructureImpl
Defines a certificate that can be attached to various I2P structures, such
as RouterIdentity and Destination, allowing routers and clients to help
manage denial of service attacks and the network utilization. Certificates
can even be defined to include identifiable information signed by some
certificate authority, though that use probably isn't appropriate for an
anonymous network ;)
Todo: Properly support multiple certificates
- Author:
- jrandom
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected byte[]_payloadprotected int_typestatic intCERTIFICATE_LENGTH_SIGNED_WITH_HASHstatic intCERTIFICATE_TYPE_HASHCASHspecifies a Hashcash style certificatestatic intCERTIFICATE_TYPE_HIDDENwe should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us)static intCERTIFICATE_TYPE_KEYstatic intCERTIFICATE_TYPE_MULTIPLEContains multiple certsstatic intCERTIFICATE_TYPE_NULLSpecifies a null certificate type with no payloadstatic intCERTIFICATE_TYPE_SIGNEDSigned with 40-byte Signature and (optional) 32-byte hashstatic CertificateNULL_CERT -
Constructor Summary
Constructors Constructor Description Certificate()Certificate(int type, byte[] payload) -
Method Summary
Modifier and Type Method Description static Certificatecreate(byte[] data, int off)If null, P256 key, or Ed25519 key cert, return immutable static instance, else create newstatic Certificatecreate(InputStream in)If null, P256 key, or Ed25519 key cert, return immutable static instance, else create newbooleanequals(Object object)intgetCertificateType()byte[]getPayload()inthashCode()intreadBytes(byte[] source, int offset)voidreadBytes(InputStream in)Load up the current object with data from the given stream.voidsetCertificateType(int type)voidsetPayload(byte[] payload)intsize()KeyCertificatetoKeyCertificate()Up-convert this to a KeyCertificateStringtoString()intwriteBytes(byte[] target, int offset)voidwriteBytes(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
calculateHash, fromBase64, fromByteArray, read, toBase64, toByteArray
-
Field Details
-
NULL_CERT
-
_type
protected int _type -
_payload
protected byte[] _payload -
CERTIFICATE_TYPE_NULL
public static final int CERTIFICATE_TYPE_NULLSpecifies a null certificate type with no payload- See Also:
- Constant Field Values
-
CERTIFICATE_TYPE_HASHCASH
public static final int CERTIFICATE_TYPE_HASHCASHspecifies a Hashcash style certificate- See Also:
- Constant Field Values
-
CERTIFICATE_TYPE_HIDDEN
public static final int CERTIFICATE_TYPE_HIDDENwe should not be used for anything (don't use us in the netDb, in tunnels, or tell others about us)- See Also:
- Constant Field Values
-
CERTIFICATE_TYPE_SIGNED
public static final int CERTIFICATE_TYPE_SIGNEDSigned with 40-byte Signature and (optional) 32-byte hash- See Also:
- Constant Field Values
-
CERTIFICATE_LENGTH_SIGNED_WITH_HASH
public static final int CERTIFICATE_LENGTH_SIGNED_WITH_HASH -
CERTIFICATE_TYPE_MULTIPLE
public static final int CERTIFICATE_TYPE_MULTIPLEContains multiple certs- See Also:
- Constant Field Values
-
CERTIFICATE_TYPE_KEY
public static final int CERTIFICATE_TYPE_KEY- Since:
- 0.9.12
- See Also:
- Constant Field Values
-
-
Constructor Details
-
Certificate
public Certificate() -
Certificate
public Certificate(int type, byte[] payload)- Throws:
IllegalArgumentException- if type < 0
-
-
Method Details
-
create
If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new- Throws:
DataFormatException- if not enough bytes- Since:
- 0.8.3
-
create
If null, P256 key, or Ed25519 key cert, return immutable static instance, else create new- Throws:
DataFormatExceptionIOException- Since:
- 0.8.3
-
getCertificateType
public int getCertificateType() -
setCertificateType
public void setCertificateType(int type)- Throws:
IllegalArgumentException- if type < 0IllegalStateException- if already set
-
getPayload
public byte[] getPayload() -
setPayload
public void setPayload(byte[] payload)- Throws:
IllegalStateException- if already set
-
readBytes
Description copied from interface:DataStructureLoad 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 already setDataFormatException- if the data is improperly formattedIOException- if there was a problem reading the stream
-
writeBytes
Description copied from interface:DataStructureWrite 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
-
writeBytes
public int writeBytes(byte[] target, int offset)- Returns:
- the written length (NOT the new offset)
-
readBytes
- Throws:
IllegalStateException- if already setDataFormatException
-
size
public int size() -
toKeyCertificate
Up-convert this to a KeyCertificate- Throws:
DataFormatException- if cert type != CERTIFICATE_TYPE_KEY- Since:
- 0.9.12
-
equals
-
hashCode
public int hashCode() -
toString
-