FileDocCategorySizeDatePackage
X500Principal.javaAPI DocAndroid 1.5 API7358Wed May 06 22:41:02 BST 2009javax.security.auth.x500

X500Principal

public final class X500Principal extends Object implements Serializable, Principal
Represents an X.500 principal, which holds the distinguished name of some network entity. An example of a distinguished name is {@code "O=Google, OU=Android, C=US"}. The class can be instantiated from a byte representation of an object identifier (OID), an ASN.1 DER-encoded version, or a simple string holding the distinguished name. The representations must follow either RFC 2253, RFC 1779, or RFC2459.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
public static final String
CANONICAL
Defines a constant for the canonical string format of distinguished names.
public static final String
RFC1779
Defines a constant for the RFC 1779 string format of distinguished names.
public static final String
RFC2253
Defines a constant for the RFC 2253 string format of distinguished names.
private transient org.apache.harmony.security.x501.Name
dn
Constructors Summary
public X500Principal(byte[] name)
Creates a new X500Principal from a given ASN.1 DER encoding of a distinguished name.

param
name the ASN.1 DER-encoded distinguished name
throws
IllegalArgumentException if the ASN.1 DER-encoded distinguished name is incorrect


                                                                 
       
        super();
        if (name == null) {
            throw new IllegalArgumentException(Messages.getString("auth.00")); //$NON-NLS-1$
        }
        try {
            // FIXME dn = new Name(name);
            dn = (Name) Name.ASN1.decode(name);
        } catch (IOException e) {
            IllegalArgumentException iae = new IllegalArgumentException(Messages
                    .getString("auth.2B")); //$NON-NLS-1$
            iae.initCause(e);
            throw iae;
        }
    
public X500Principal(InputStream in)
Creates a new X500Principal from a given ASN.1 DER encoding of a distinguished name.

param
in an {@code InputStream} holding the ASN.1 DER-encoded distinguished name
throws
IllegalArgumentException if the ASN.1 DER-encoded distinguished name is incorrect

        super();
        if (in == null) {
            throw new NullPointerException(Messages.getString("auth.2C")); //$NON-NLS-1$
        }
        try {
            // FIXME dn = new Name(is);
            dn = (Name) Name.ASN1.decode(in);
        } catch (IOException e) {
            IllegalArgumentException iae = new IllegalArgumentException(Messages
                    .getString("auth.2B")); //$NON-NLS-1$
            iae.initCause(e);
            throw iae;
        }
    
public X500Principal(String name)
Creates a new X500Principal from a string representation of a distinguished name.

param
name the string representation of the distinguished name
throws
IllegalArgumentException if the string representation of the distinguished name is incorrect

        super();
        if (name == null) {
            throw new NullPointerException(Messages.getString("auth.00")); //$NON-NLS-1$
        }
        try {
            dn = new Name(name);
        } catch (IOException e) {
            IllegalArgumentException iae = new IllegalArgumentException(Messages
                    .getString("auth.2D")); //$NON-NLS-1$
            iae.initCause(e);
            throw iae;
        }
    
Methods Summary
public booleanequals(java.lang.Object o)

        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        X500Principal principal = (X500Principal) o;
        return dn.getName(CANONICAL).equals(principal.dn.getName(CANONICAL));
    
public byte[]getEncoded()
Returns an ASN.1 DER-encoded representation of the distinguished name contained in this X.500 principal.

return
the ASN.1 DER-encoded representation

        byte[] src = dn.getEncoded();
        byte[] dst = new byte[src.length];
        System.arraycopy(src, 0, dst, 0, dst.length);
        return dst;
    
public java.lang.StringgetName()
Returns a human-readable string representation of the distinguished name contained in this X.500 principal.

return
the string representation

        return dn.getName(RFC2253);
    
public java.lang.StringgetName(java.lang.String format)
Returns a string representation of the distinguished name contained in this X.500 principal. The format of the representation can be chosen. Valid arguments are {@link #RFC1779}, {@link #RFC2253}, and {@link #CANONICAL}. The representations are specified in RFC 1779 and RFC 2253, respectively. The canonical form is based on RFC 2253, but adds some canonicalizing operations like removing leading and trailing whitespace, lower-casing the whole name, and bringing it into a normalized Unicode representation.

param
format the name of the format to use for the representation
return
the string representation
throws
IllegalArgumentException if the {@code format} argument is not one of the three mentioned above

        return dn.getName(format);
    
public inthashCode()

        return dn.getName(CANONICAL).hashCode();
    
private voidreadObject(java.io.ObjectInputStream in)


        dn = (Name) Name.ASN1.decode((byte[]) in.readObject());
    
public java.lang.StringtoString()

        return dn.getName(RFC1779);
    
private voidwriteObject(java.io.ObjectOutputStream out)

        out.writeObject(dn.getEncoded());