001package org.apache.commons.ssl.org.bouncycastle.asn1.x500;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Encodable;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier;
005
006/**
007 * It turns out that the number of standard ways the fields in a DN should be 
008 * encoded into their ASN.1 counterparts is rapidly approaching the
009 * number of machines on the internet. By default the X500Name class
010 * will produce UTF8Strings in line with the current recommendations (RFC 3280).
011 * <p>
012 */
013public interface X500NameStyle
014{
015    /**
016     * Convert the passed in String value into the appropriate ASN.1
017     * encoded object.
018     * 
019     * @param oid the OID associated with the value in the DN.
020     * @param value the value of the particular DN component.
021     * @return the ASN.1 equivalent for the value.
022     */
023    ASN1Encodable stringToValue(ASN1ObjectIdentifier oid, String value);
024
025    /**
026     * Return the OID associated with the passed in name.
027     *
028     * @param attrName the string to match.
029     * @return an OID
030     */
031    ASN1ObjectIdentifier attrNameToOID(String attrName);
032
033    /**
034     * Return an array of RDN generated from the passed in String.
035     * @param dirName  the String representation.
036     * @return  an array of corresponding RDNs.
037     */
038    RDN[] fromString(String dirName);
039
040    /**
041     * Return true if the two names are equal.
042     *
043     * @param name1 first name for comparison.
044     * @param name2 second name for comparison.
045     * @return true if name1 = name 2, false otherwise.
046     */
047    boolean areEqual(X500Name name1, X500Name name2);
048
049    /**
050     * Calculate a hashCode for the passed in name.
051     *
052     * @param name the name the hashCode is required for.
053     * @return the calculated hashCode.
054     */
055    int calculateHashCode(X500Name name);
056
057    /**
058     * Convert the passed in X500Name to a String.
059     * @param name the name to convert.
060     * @return a String representation.
061     */
062    String toString(X500Name name);
063
064    /**
065     * Return the display name for toString() associated with the OID.
066     *
067     * @param oid  the OID of interest.
068     * @return the name displayed in toString(), null if no mapping provided.
069     */
070    String oidToDisplayName(ASN1ObjectIdentifier oid);
071
072    /**
073     * Return the acceptable names in a String DN that map to OID.
074     *
075     * @param oid  the OID of interest.
076     * @return an array of String aliases for the OID, zero length if there are none.
077     */
078    String[] oidToAttrNames(ASN1ObjectIdentifier oid);
079}