FileDocCategorySizeDatePackage
AttributeTypeAndValue.javaAPI DocAndroid 1.5 API18380Wed May 06 22:41:06 BST 2009org.apache.harmony.security.x501

AttributeTypeAndValue

public class AttributeTypeAndValue extends Object
X.501 AttributeTypeAndValue

Fields Summary
private static final org.apache.harmony.security.utils.ObjectIdentifier
C
private static final org.apache.harmony.security.utils.ObjectIdentifier
CN
private static final org.apache.harmony.security.utils.ObjectIdentifier
DC
private static final org.apache.harmony.security.utils.ObjectIdentifier
DNQ
private static final org.apache.harmony.security.utils.ObjectIdentifier
DNQUALIFIER
private static final org.apache.harmony.security.utils.ObjectIdentifier
EMAILADDRESS
private static final org.apache.harmony.security.utils.ObjectIdentifier
GENERATION
private static final org.apache.harmony.security.utils.ObjectIdentifier
GIVENNAME
private static final org.apache.harmony.security.utils.ObjectIdentifier
INITIALS
private static final org.apache.harmony.security.utils.ObjectIdentifier
L
private static final org.apache.harmony.security.utils.ObjectIdentifier
O
private static final org.apache.harmony.security.utils.ObjectIdentifier
OU
private static final org.apache.harmony.security.utils.ObjectIdentifier
SERIALNUMBER
private static final org.apache.harmony.security.utils.ObjectIdentifier
ST
private static final org.apache.harmony.security.utils.ObjectIdentifier
STREET
private static final org.apache.harmony.security.utils.ObjectIdentifier
SURNAME
private static final org.apache.harmony.security.utils.ObjectIdentifier
T
private static final org.apache.harmony.security.utils.ObjectIdentifier
UID
private static final int
CAPACITY
private static final int
SIZE
private static final org.apache.harmony.security.utils.ObjectIdentifier[]
KNOWN_OIDS
private static final HashMap
KNOWN_NAMES
private static final HashMap
RFC1779_NAMES
private static final HashMap
RFC2253_NAMES
private static final HashMap
RFC2459_NAMES
private final org.apache.harmony.security.utils.ObjectIdentifier
oid
private AttributeValue
value
public static org.apache.harmony.security.asn1.ASN1Type
AttributeValue
According to RFC 3280 (http://www.ietf.org/rfc/rfc3280.txt) X.501 AttributeTypeAndValue structure is defined as follows: AttributeTypeAndValue ::= SEQUENCE { type AttributeType, value AttributeValue } AttributeType ::= OBJECT IDENTIFIER AttributeValue ::= ANY DEFINED BY AttributeType ... DirectoryString ::= CHOICE { teletexString TeletexString (SIZE (1..MAX)), printableString PrintableString (SIZE (1..MAX)), universalString UniversalString (SIZE (1..MAX)), utf8String UTF8String (SIZE (1.. MAX)), bmpString BMPString (SIZE (1..MAX)) }
public static final org.apache.harmony.security.asn1.ASN1Sequence
ASN1
Constructors Summary
private AttributeTypeAndValue(int[] oid, AttributeValue value)


        ObjectIdentifier thisOid = getOID(oid);
        if (thisOid == null) {
            thisOid = new ObjectIdentifier(oid);
        }
        this.oid = thisOid;
        this.value = value;
    
public AttributeTypeAndValue(String sOid, AttributeValue value)
Creates AttributeTypeAndValue with OID and AttributeValue. Parses OID string representation

param
sOid string representation of OID
param
value attribute value
throws
IOException if OID can not be created from its string representation

        if (sOid.charAt(0) >= '0" && sOid.charAt(0) <= '9") {

            int[] array = org.apache.harmony.security.asn1.ObjectIdentifier
                    .toIntArray(sOid);

            ObjectIdentifier thisOid = getOID(array);
            if (thisOid == null) {
                thisOid = new ObjectIdentifier(array);
            }
            this.oid = thisOid;

        } else {
            this.oid = (ObjectIdentifier) KNOWN_NAMES.get(sOid.toUpperCase());
            if (this.oid == null) {
                throw new IOException(Messages.getString("security.178", sOid)); //$NON-NLS-1$
            }
        }
        this.value = value;
    
Methods Summary
private static voidaddOID(org.apache.harmony.security.utils.ObjectIdentifier oid)


        int[] newOid = oid.getOid();
        int index = hashIntArray(newOid) % CAPACITY;

        // look for OID in the pool 
        ObjectIdentifier[] list = KNOWN_OIDS[index];
        int i = 0;
        for (; list[i] != null; i++) {

            // check wrong static initialization: no duplicate OIDs
            if (Arrays.equals(newOid, list[i].getOid())) {
                throw new Error(Messages.getString("security.17B", //$NON-NLS-1$
                                oid.getName(), list[i].getName()));
            }
        }

        // check : to avoid NPE
        if (i == (CAPACITY - 1)) {
            throw new Error(Messages.getString("security.17C")); //$NON-NLS-1$
        }
        list[i] = oid;
    
public voidappendName(java.lang.String attrFormat, java.lang.StringBuffer buf)
Appends AttributeTypeAndValue string representation

param
attrFormat - format of DN
param
buf - string buffer to be used


        boolean hexFormat = false;
        if (attrFormat == X500Principal.RFC1779) {
            if (RFC1779_NAMES == oid.getGroup()) {
                buf.append(oid.getName());
            } else {
                buf.append(oid.toOIDString());
            }

            buf.append('=");
            if (value.escapedString == value.getHexString()) {
                //FIXME all chars in upper case
                buf.append(value.getHexString().toUpperCase());
            } else if (value.escapedString.length() != value.rawString.length()) {
                // was escaped
                value.appendQEString(buf);
            } else {
                buf.append(value.escapedString);
            }
        } else {
            Object group = oid.getGroup();
            // RFC2253 includes names from RFC1779
            if (RFC1779_NAMES == group || RFC2253_NAMES == group) {
                buf.append(oid.getName());

                if (attrFormat == X500Principal.CANONICAL) {
                    // only PrintableString and UTF8String in string format
                    // all others are output in hex format
                    int tag = value.getTag();
                    if (!ASN1StringType.UTF8STRING.checkTag(tag)
                            && !ASN1StringType.PRINTABLESTRING.checkTag(tag)) {
                        hexFormat = true;
                    }
                }

            } else {
                buf.append(oid.toString());
                hexFormat = true;
            }

            buf.append('=");

            if (hexFormat) {
                buf.append(value.getHexString());
            } else {
                if (attrFormat == X500Principal.CANONICAL) {
                    buf.append(value.makeCanonical());
                } else {
                    buf.append(value.escapedString);
                }
            }
        }
    
private static org.apache.harmony.security.utils.ObjectIdentifiergetOID(int[] oid)


    // returns known OID or null
         

        int index = hashIntArray(oid) % CAPACITY;

        // look for OID in the pool 
        ObjectIdentifier[] list = KNOWN_OIDS[index];
        for (int i = 0; list[i] != null; i++) {
            if (Arrays.equals(oid, list[i].getOid())) {
                return list[i];
            }
        }
        return null;
    
public org.apache.harmony.security.utils.ObjectIdentifiergetType()
Gets type of the AttributeTypeAndValue

return
ObjectIdentifier

        return oid;
    
private static inthashIntArray(int[] oid)

        int intHash = 0;
        for (int i = 0; i < oid.length && i < 4; i++) {
            intHash += oid[i] << (8 * i); //TODO what about to find better one?
        }
        return intHash & 0x7FFFFFFF; // only positive