public class SMIMECapability extends java.lang.Object implements ASN1Type
S/MIMEv3 (RFC 4262)
specifies the SMimeCapability
to be used within
an SMIMECapabilities
certificate extension
to announce the ability to handle some particular algorithm capabilities
for S/MIME based applications. For that purpose a SMIMECapability object is
created where some particular algorithm is referenced by its object identifier.
If necessary the SMIMECapability object additionally may
include parameters providing information required to differentiate
between two instances of the same algorithm (for instance key length
for RC2). Any SMIMECapability to be announced is collected
and included into a SMIMECapabilities
extension in preference order.
SMIMECapability ::= SEQUENCE { capabilityID OBJECT IDENTIFIER, parameters ANY DEFINED BY capabilityID OPTIONAL } SMIMECapabilities ::= SEQUENCE OF SMIMECapabilityWhen
creating
a SMIMECapability object
the OID of the algorithm has to be specified for announcing to be capable
to handle the corresponding algorithm. Any parameters (e.g. key length
supported for some particular algorithm) to be additionally announced can
be included by calling method setParameters
.
Since the parameters may have any ASN.1 representation, method setParameters
simple expects them as an ASN1Object.
So, for instance, paramters announcing that the ability to handle RC2
for a key length of 128 bits, would be an ASN.1 INTEGER:
SMIMECapability rc2_128Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_128Capability.setParameters(new INTEGER(128));If you also want to announce RC2 for key lengths of 40 and 64 bits, create SMIMECapability objects for these two key lengths, too, and -- together with any further capabilities to be announced -- subsequently set it for the
SMIMECapabilities
extension, e.g.:
// RC2 128 SMIMECapability rc2_128Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_128Capability.setParameters(new INTEGER(128)); // RC2 64 SMIMECapability rc2_64Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_64Capability.setParameters(new INTEGER(64)); // RC2 40 SMIMECapability rc2_40Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_40Capability.setParameters(new INTEGER(40)); // any further capabilities ... // add the capabilities in preference order to an SMIMECapabilities extension: SMIMECapability[] capabilities = { ..., rc2_128Capability, rc2_64Capability, rc2_40Capability, ...}; SMIMECapabilities smimeCapabilities = new SMIMECapabilities(capabilities);
SMIMECapabilities
Constructor and Description |
---|
SMIMECapability()
Empty default constructor.
|
SMIMECapability(ASN1Object obj)
Creates an SMIMECapability from an ASN1Object.
|
SMIMECapability(ObjectID capabilityID)
Creates an SMIMECapability for the given capability (algorithm) id.
|
Modifier and Type | Method and Description |
---|---|
void |
decode(ASN1Object obj)
Decodes an SMIMECapability from an ASN1Object.
|
boolean |
equals(java.lang.Object obj)
Compares this
SMIMECapability to the specified object. |
ObjectID |
getCapabilityID()
Gets the capability ID of this SMIMECapability object.
|
ASN1Object |
getParameters()
Gets the algorithm specific parameters (if included) announced by this
SMIMECapability.
|
int |
hashCode()
Returns a hashcode for this SMIMECapability.
|
void |
setParameters(ASN1Object parameters)
Sets the algorithm specific parameters (if required) to be announced by this
SMIMECapability.
|
ASN1Object |
toASN1Object()
Returns this SMIMECapability as ASN1Object.
|
java.lang.String |
toString()
Returns a string representation of this SMIMECapability.
|
public SMIMECapability()
public SMIMECapability(ObjectID capabilityID)
Use method setParameters
for
setting any parameters to be included, if required.
capabilityID
- the capabilty oid identifying the algorithm for
which to create a SMimeCapabililtypublic SMIMECapability(ASN1Object obj) throws CodingException
obj
- the SMIMECapability as ASN1ObjectCodingException
- if an error occurs while parsing the ASN1Objectpublic ObjectID getCapabilityID()
public ASN1Object getParameters()
Since the parameters may have any ASN.1 representation this method simple returns the parameters as ASN1Object. So, for instance, paramters announcing the ability to handle RC2 for a key length of 128 bits, would be encoded as an ASN.1 INTEGER:
INTEGER rc2KeyLength = (INTEGER)capability.getParameters(); int keyLength = ((BigInteger)rc2KeyLength.getValue()).intValue();
null
if no
parameters are includedpublic void setParameters(ASN1Object parameters)
Since the parameters may have any ASN.1 representation this method simple expects them as an ASN1Object. So, for instance, paramters announcing the ability to handle RC2 for a key length of 128 bits, would be an ASN.1 INTEGER:
SMIMECapability rc2_128Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_128Capability.setParameters(new INTEGER(128));If the RC2 for key lengths of 40 and 64 bits shall be also announced, create a SMIMECapability object for these two key lengths, too, and -- together with any further capabilities to be announced -- subsequently set it for the
SMIMECapabilities
extension, e.g.:
// RC2 128 SMIMECapability rc2_128Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_128Capability.setParameters(new INTEGER(128)); // RC2 64 SMIMECapability rc2_64Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_64Capability.setParameters(new INTEGER(64)); // RC2 40 SMIMECapability rc2_40Capability = new SMIMECapability(AlgorithmID.rc2_CBC.getAlgorithm()); rc2_40Capability.setParameters(new INTEGER(40)); // any further capabilities ... // add the capabilities in preference order to an SMIMECapabilities extension: SMIMECapability[] capabilities = { ..., rc2_128Capability, rc2_64Capability, rc2_40Capability, ...}; SMIMECapabilities smimeCapabilities = new SMIMECapabilities(capabilities);
parameters
- the parameters to be announced with this SMIMECapabilitypublic ASN1Object toASN1Object() throws CodingException
toASN1Object
in interface ASN1Type
CodingException
- if the ASN1Object cannot be created because
no capability ID is setpublic void decode(ASN1Object obj) throws CodingException
decode
in interface ASN1Type
obj
- the SMIMECapability as ASN1ObjectCodingException
- if an error occurs while parsing the ASN1Objectpublic boolean equals(java.lang.Object obj)
SMIMECapability
to the specified object.equals
in class java.lang.Object
obj
- the object to compare this SMIMECapability
against.true
, if the given object is equal to this
SMIMECapability
,
false
otherwisepublic int hashCode()
The hashcode is calculated from the capabilityID only.
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object