public abstract class OtherName extends java.lang.Object implements ASN1Type
OtherName
type as specified by the X.509 Certificate profile (RFC 3280) to maybe used within a
GeneralName
.
Any class which implements some specific OtherName value must be derived
from this class.
OtherName ::= SEQUENCE { type-id OBJECT IDENTIFIER, value [0] EXPLICIT ANY DEFINED BY type-id } }
Any class implementing a particular OtherName value has to extend this
class and therefore has to implement the methods decode
and toASN1Object
for translating an OtherName from
or to its ASN.1 representation, respectively. The OtherName type-id to
be returned by method getTypeId
is the one identifying the
particular OtherName and shall be used for registering
the corresponding class as implemenation for the particular
OtherName e.g.:
public class MyOtherName extends OtherName { ... // the type id: public static final ObjectID TYPE_ID = ...; ... } ... // register the implementation: OtherName.register(MyOtherName.TYPE_ID, MyOtherName.class);When implementing an OtherName by extending this class please be aware that methods
toASN1Object
decode
have to
convert the whole OtherName SEQUENCE (including type-id and value) into
respectively from an ASN1Object.
For example, the toASN1Object
/decode
methods
of an OtherName implementation with an UTF8String value may look like:
public class MyOtherName extends OtherName { ... // the type id: public static final ObjectID TYPE_ID = ...; ... // the value (as String) private String value_; // default constructor (required for dynamic object creation) public MyOtherName() { } // Constructor with String value. public MyOtherName(String value) { if (value == null) { throw new IllegalArgumentException("Value must not be null!"); } value_ = value; } // Decode method public void decode(ASN1Object obj) throws CodingException { ObjectID typeId = (ObjectID)obj.getComponentAt(0); // right type-id? if (typeId.equals(TYPE_ID) == false) { throw new CodingException("Invalid OtherName type. Expected " + TYPE_ID); } // OtherName value is context specific tagged ASN1Object value = obj.getComponentAt(1); if (value.isA(ASN.CON_SPEC) == false) { throw new CodingException("Value component must be context-specifix tagged"); } CON_SPEC conSpec = (CON_SPEC)value; if (conSpec.getAsnType().getTag() != 0) { throw new CodingException("Invalid tag of value component! Must be 0"); } // CON_SPEC value is UTF8String value = (ASN1Object)conSpec.getValue(); if (value.isA(ASN.UTF8String) == false) { throw new CodingException("Value must be UTF-8 String"); } value_ = (String)value.getValue(); } // Get ASN.1 representation public ASN1Object toASN1Object() throws CodingException { SEQUENCE asn1OtherName = new SEQUENCE(); asn1OtherName.addComponent(TYPE_ID); asn1OtherName.addComponent(new CON_SPEC(0, new UTF8String(value_))); return asn1OtherName; } // Get value as String public String getValue() { return value_; } // Gets a String representation public String toString() { StringBuffer buf = new StringBuffer(); buf.append("\n Type-Id: " + getName()); buf.append("\n Value: " + value_); return buf.toString(); } }If you would
register
this OtherName
implementation as shown above, and then parsing a GeneralName
of type OtherName with this specific type-id, you can cast
to your MyOtherName
class when calling GeneralName.getName()
:
// register specific OtherName implementation OtherName.register(MyOtherName.TYPE_ID, MyOtherName.class); ... // the GeneralName GeneralName generalName = ...; // GeneralName of type OtherName? if (generalName.getType() == GeneralName.otherName) { // get the inherent name Object name = generalName.getName(); if (name instanceof OtherName) { OtherName otherName = (OtherName)name; // check OtherName type (only required if you have more OtherNames registered) if (otherName.getTypeId().equals(MyOtherName.TYPE_ID)) { myOtherName = (MyOtherName)otherName; String value = myOtherName.getValue(); } } else { // no OtherName for the specific type-id is registered ASN1Object asn1OtherName = (ASN1Object)name; } }As you see in this example, if the GeneralName represents an OtherName for which no implementation is registered,
GeneralName.getName()
returns an ASN1Object
. This is
necessary because of backwards compatibility to previous versions of
IAIK-JCE. For the name reason methods toASN1Object
decode
have to convert the whole OtherName SEQUENCE (including type-id and value) into
respectively from an ASN1Object.GeneralName
Constructor and Description |
---|
OtherName() |
Modifier and Type | Method and Description |
---|---|
static OtherName |
create(ObjectID typeId)
Returns the implementation of the requested OtherName defined through an
ASN.1 ObjectID (the OtherName type-id).
|
java.lang.String |
getName()
Returns the OtherName type name.
|
abstract ObjectID |
getTypeId()
Returns the type OID identifying the type of the OtherName.
|
static void |
register(ObjectID typeId,
java.lang.Class cl)
Registers a class for implementing a particular OtherName.
|
abstract java.lang.String |
toString()
Returns a String representation of the OtherName.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
decode, toASN1Object
public static OtherName create(ObjectID typeId) throws java.lang.InstantiationException
typeId
- the OID identifying the OtherName typejava.lang.InstantiationException
- if no instance of the requested type could be createdpublic static void register(ObjectID typeId, java.lang.Class cl) throws java.lang.IllegalArgumentException
typeId
- the OID identifying the OtherName typecl
- the class which implements the OtherName in mindjava.lang.IllegalArgumentException
public abstract ObjectID getTypeId()
public abstract java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getName()