|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.asn1.structures.AVA
This class implements the ASN.1 type AttributeValueAssertion.
An AttributeValueAssertion gives one component of a RelativeDistinguishedName
structure:
RelativeDistinguishedName ::= SET OF AttributeValueAssertion AttributeValueAssertion ::= SEQUENCE { AttributeType OBJECT IDENTIFIER, AttributeValue ANY }
When creating a new AVA
object, the attribute type has to
be specified as ObjectID
, and the value
has to be supplied as a Java object of matching type (i.e. compatible to
the type expected by the setValue
method of the corresponding
ASN.1 type), e.g.:
AVA ava = new AVA(ObjectID.commonName, "John Doe");The example above will create an AVA for the X.500 attribute type commonName. Since, per default, the commonName value will be encoded as PrintableString, the value has to be specified as java.lang.String object since the
setValue
method of class PrintableString expects a String object. Alternatively immediately
a PrintableString ASN1Object may be supplied (and will be encoded unchanged):
AVA ava = new AVA(ObjectID.commonName, new PrintableString("John Doe"));
When DER encoding an AVA
object where the value is not
immediately given as ASN1Object, the inherent value per
default will be encoded as ASN.1 character string of type
PrintableString
, except for
the X.500 attribute type uniqueIdentifier and the PKCS#9
attribute type emailAddress which per default will be encoded as
BIT_STRING
, and IA5String
, respectively.
An application wishing to use another encoding type than PrintableString
for encoding some specific attribute value, may register the ASN.1
encoding type in mind by means of the static defineEncoding(ObjectID type, ASN encodingType)
method, e.g.:
AVA.defineEncoding(ObjectID.title, ASN.VisibleString);will enforce that any AVA value of X.500 attribute type title will be encoded as
VisibleString
instead of
PrintableString}.
If you want to use a different encoding type only for one specific AVA object
you may specify the particular encoding type when creating
a new AVA object; e.g.:
AVA ava = new AVA(ObjectID.commonName, "John Doe", ASN.IA5String);will enforce that the value of this specific AVA object will be encoded as IA5String.
Special care has to taken when using an attribute of type type
uniqueIdentifier. Since the uniqueIdentifier value has to be
encoded as BIT_STRING
, per default the
value has to be specified as byte array as expected by the setValue
method of the
BIT_STRING class:
byte[] value = ...; AVA ava = new AVA(ObjectID.uniqueIdentifier, value);However, since some certificates use a DER encoded PrintableString as value for the BIT_STRING uniqueIdentifier alternatively a string value may be supplied:
String s = ...; AVA ava = new AVA(ObjectID.uniqueIdentifier, s);In such cases, the AVA will encode the uniqueIdentifier value as BIT_STRING having a DER encoded PrintableString as its value.
Constructor Summary | |
AVA(ASN1Object obj)
Creates an AttributeValueAssertion from an ASN1Object. |
|
AVA(ObjectID type,
Object value)
Creates a new AttributeValueAssertion from a type and a value. |
|
AVA(ObjectID type,
Object value,
ASN encodingType)
Creates a new AttributeValueAssertion from a type and a value to be encoded using the given encoding type. |
Method Summary | |
void |
decode(ASN1Object obj)
Decodes an AVA from the given ASN1Object. |
static void |
defineEncoding(ObjectID type,
ASN encodingType)
Defines the ASN.1 encoding for a specified Attribute type. |
boolean |
equals(Object obj)
Compares two AttributeValueAssertions. |
ASN1Object |
getASN1Value()
Returns an ASN.1 representation of the value of this AttributeValueAssertion. |
static ASN |
getDefaultEncoding()
Gets the default encoding. |
static ASN |
getEncoding(ObjectID type)
Gets the encoding type associated with the given attribute type. |
static ASN |
getNonPrintableDefaultEncoding()
Gets the encoding that is used if a String attribute value has non printable chars. |
String |
getRFC2253String()
Returns a string representation of this AVA according to RFC 2253. |
ObjectID |
getType()
Returns the type of this AttributeValueAssertion. |
Object |
getValue()
Returns the value of this AttributeValueAssertion. |
int |
hashCode()
Returns the hashcode for this AttributeValueAssertion. |
static void |
setDefaultEncoding(ASN encodingType)
Sets the default encoding to be used. |
static void |
setNonPrintableDefaultEncoding(ASN encodingType)
Sets the encoding that shall be used if a String attribute value has non printable chars. |
ASN1Object |
toASN1Object()
Returns this AttributeValueAssertion as an ASN1Object. |
String |
toString()
Returns a string that represents the contents of this RDN. |
String |
toString(boolean detailed)
Returns a string that represents the contents of this AVA. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public AVA(ObjectID type, Object value) throws IllegalArgumentException
setValue
method of the corresponding ASN.1 type), e.g.:
AVA ava = new AVA(ObjectID.commonName, "John Doe");The example above will create an AVA for the X.500 attribute type commonName. Since, per default, the commonName value will be encoded as PrintableString, the value has to be specified as java.lang.String object since the
setValue
method of class PrintableString expects a String object. Alternatively immediately
a PrintableString ASN1Object may be supplied when creating the AVA:
AVA ava = new AVA(ObjectID.commonName, new PrintableString("John Doe"));If the supplied value constitutes a String and the default encoding type is set to ASN.1 PrintableString this constructor checks if the supplied string really consists only of printable characters. If not the encoding type for this string is set to ASN.1 UTF8String.
type
- the attribute type as an ObjectIDvalue
- the attribute valuepublic AVA(ObjectID type, Object value, ASN encodingType) throws IllegalArgumentException
The value has to be supplied as a Java object of matching type
(i.e. compatible to the type expected by the setValue
method of the corresponding ASN.1 type), e.g.:
AVA ava = new AVA(ObjectID.commonName, "John Doe", ASN.IA5String);The example above will create an AVA for the X.500 attribute type commonName. Since IA5String shall be used to encode the AVA, the value has to be supplied as Java String object.
Alternatively immediately a IA5String ASN1Object may be supplied when creating the AVA:
AVA ava = new AVA(ObjectID.commonName, new IA5String("John Doe"));If the supplied value constitutes a String and the default encoding type is set to ASN.1 PrintableString this constructor checks if the supplied string really consists only of printable characters. If not the encoding type for this string is set to ASN.1 UTF8String.
type
- the attribute type as an ObjectIDvalue
- the attribute valuepublic AVA(ASN1Object obj) throws CodingException
The supplied ASN1Object represents an already existing AVA
that may have been created by means of the toASN1Object
method.
obj
- the AttributeValueAssertion as ASN1ObjectCodingException
- if the AttributeValueAssertion can not be decodedMethod Detail |
public static void defineEncoding(ObjectID type, ASN encodingType)
PrintableString
, except for
the X.500 attribute type uniqueIdentifier and the PKCS#9
attribute type emailAddress which per default will be encoded as
BIT_STRING
, and IA5String
, respectively.
This method may be used to enforce another encoding scheme for some specific attribute type, e.g.:
AVA.defineEncoding(ObjectID.title, ASN.VisibleString);will enforce that any AVA value of X.500 attribute type title will be encoded as
VisibleString
instead of
PrintableString}.type
- the attribute type for which a new encoding scheme shall be definedencodingType
- the ASN.1 type for encoding itpublic static ASN getEncoding(ObjectID type)
This method asks if there has been registered a special encoding scheme for the given attribute type.
type
- the attribute type to be searched for an encoding schemepublic static void setDefaultEncoding(ASN encodingType)
encodingType
- the ASN.1 type to be used as default encodingpublic static void setNonPrintableDefaultEncoding(ASN encodingType)
The default
encoding used by this class
is ASN.1 PrintableString. If a String attribute value, however, has no
printable characters, the encoding automatically is switched to UTF8String
as recommended to RFC2459. This method may be used to set another "secondary"
default encoding than UTF8String.
encodingType
- the encoding type to be used if PrintableString is the
default encoding but a String value contains non printable
characterspublic static ASN getDefaultEncoding()
public static ASN getNonPrintableDefaultEncoding()
The default
encoding used by this class
is ASN.1 PrintableString. If a String attribute value, however, has no
printable characters, the encoding automatically is switched to UTF8String
as recommended to RFC2459. Method {@ink #This method setNonPrintableDefaultEncoding(ASN)
setNonPrintableDefaultEncoding} may be used to set another "secondary"
default encoding than UTF8String.
public void decode(ASN1Object obj) throws CodingException
The supplied ASN1Object represents an already existing AVA object that
may have been created by means of the toASN1Object()
method.
decode
in interface ASN1Type
obj
- the AttributeValueAssertion as ASN1ObjectCodingException
- if the AttributeValueAssertion can not be decodedpublic ASN1Object toASN1Object()
toASN1Object
in interface ASN1Type
public ObjectID getType()
public Object getValue()
public ASN1Object getASN1Value() throws CodingException
CodingException
- if an error occurs when getting the ASN.1 representationpublic int hashCode()
hashCode
in class Object
public boolean equals(Object obj)
equals
in class Object
obj
- the other AttributeValueAssertiontrue
, if the two AttributeValueAssertions are equal,
false
otherwisepublic String toString()
The string output is compatible to RFC 1779/2253 except for escaping. If desired, an application itself make take care for proper escaping.
Care has to be taken about attributes of type uniqueIdentifier. Since some certificates use a DER encoded PrintableString as value for the BIT_STRING uniqueIdentifier this method prints a string for such a uniqueIdentifier. Otherwise a binary string representation of the bit string value is printed, e.g.: "#'10010'B".
toString
in class Object
public String toString(boolean detailed)
The string output is compatible to RFC 1779/2253 except for escaping. If desired, an application itself make take care for proper escaping.
Care has to be taken about attributes of type uniqueIdentifier. Since some certificates use a DER encoded PrintableString as value for the BIT_STRING uniqueIdentifier this method prints a string for such a uniqueIdentifier. Otherwise a binary string representation of the bit string value is printed, e.g.: "#'10010'B".
detailed
- whether the short name of the full name of the
type shall be usedpublic String getRFC2253String() throws RFC2253NameParserException
RFC 2253 specifies a string representation of Distinguished Names as used for LDAP lookups.
The attribute type is represented as described in section 2.3 of RFC 2253. If there is no known name string for the attribute type a dotted-decimal encoding of the attribute type´s identifier.
The string representation of the attribute value is either a hexadecimal represenation of its BER encoding (introduced by a "#" character) or based on the algorithm given in section 2.4 of RFC 2253 applying the following escaping mechanisms:
RFC2253NameParserException
- if the AVA cannot be represented
according to the rules above
|
This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |