⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x509name.java

📁 说明: 1、里面有什么: 1.1、org.bouncycastle.*下的所有软件是bouncycastle组织开发的软件包 1.2、org.infosecurity.*下的软件包括
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        this(reverse, DefaultLookUp, dirName);    }    /**     * takes an X509 dir name as a string of the format "C=AU, ST=Victoria", or     * some such, converting it into an ordered set of name attributes. lookUp      * should provide a table of lookups, indexed by lowercase only strings and     * yielding a DERObjectIdentifier, other than that OID. and numeric oids     * will be processed automatically.     * <p>     * If reverse is true, create the encoded version of the sequence starting     * from the last element in the string.     */    public X509Name(        boolean     reverse,        Hashtable   lookUp,        String      dirName)    {        X509NameTokenizer   nTok = new X509NameTokenizer(dirName);        while (nTok.hasMoreTokens())        {            String  token = nTok.nextToken();            int     index = token.indexOf('=');            if (index == -1)            {                throw new IllegalArgumentException("badly formated directory string");            }            String              name = token.substring(0, index);            String              value = token.substring(index + 1);            DERObjectIdentifier oid = null;            if (name.toUpperCase().startsWith("OID."))            {                oid = new DERObjectIdentifier(name.substring(4));            }            else if (name.charAt(0) >= '0' && name.charAt(0) <= '9')            {                oid = new DERObjectIdentifier(name);            }            else            {                oid = (DERObjectIdentifier)lookUp.get(name.toLowerCase());                if (oid == null)                {                    throw new IllegalArgumentException("Unknown object id - " + name + " - passed to distinguished name");                }            }            this.ordering.addElement(oid);            this.values.addElement(value);        }        if (reverse)        {            Vector  o = new Vector();            Vector  v = new Vector();            for (int i = this.ordering.size() - 1; i >= 0; i--)            {                o.addElement(this.ordering.elementAt(i));                v.addElement(this.values.elementAt(i));            }            this.ordering = o;            this.values = v;        }    }    /**     * return false if we have characters out of the range of a printable     * string, true otherwise.     */    private boolean canBePrintable(        String  str)    {        for (int i = str.length() - 1; i >= 0; i--)        {            if (str.charAt(i) > 0x007f)            {                return false;            }        }        return true;    }    public DERObject getDERObject()    {        if (seq == null)        {            ASN1EncodableVector  vec = new ASN1EncodableVector();            for (int i = 0; i != ordering.size(); i++)            {                ASN1EncodableVector     v = new ASN1EncodableVector();                DERObjectIdentifier     oid = (DERObjectIdentifier)ordering.elementAt(i);                v.add(oid);                String  str = (String)values.elementAt(i);                if (oid.equals(EmailAddress))                {                    v.add(new DERIA5String(str));                }                else                {                    if (canBePrintable(str))                    {                        v.add(new DERPrintableString(str));                    }                    else                    {                        v.add(new DERUTF8String(str));                    }                }                vec.add(new DERSet(new DERSequence(v)));            }            seq = new DERSequence(vec);        }        return seq;    }    /**     * test for equality - note: case is ignored.     */    public boolean equals(Object _obj)     {        if (_obj == this)        {            return true;        }        if (_obj == null || !(_obj instanceof X509Name))        {            return false;        }                X509Name _oxn          = (X509Name)_obj;        int      _orderingSize = ordering.size();        if (_orderingSize != _oxn.ordering.size())         {			return false;		}				boolean[] _indexes = new boolean[_orderingSize];		for(int i = 0; i < _orderingSize; i++) 		{			boolean _found = false;			String  _oid   = ((DERObjectIdentifier)ordering.elementAt(i)).getId();			String  _val   = (String)values.elementAt(i);						for(int j = 0; j < _orderingSize; j++) 			{				if(_indexes[j] == true)				{					continue;				}								String _oOID = ((DERObjectIdentifier)_oxn.ordering.elementAt(j)).getId();				String _oVal = (String)_oxn.values.elementAt(j);                // was equalsIgnoreCase but MIDP doesn't like that.				if(_oid.equals(_oOID) && _val.toLowerCase().equals(_oVal.toLowerCase()))				{					_indexes[j] = true;					_found      = true;					break;				}			}			if(!_found)			{				return false;			}		}				return true;	}	    public int hashCode()    {        ASN1Sequence  seq = (ASN1Sequence)this.getDERObject();        Enumeration   e = seq.getObjects();        int           hashCode = 0;        while (e.hasMoreElements())        {            hashCode ^= e.nextElement().hashCode();        }        return hashCode;    }    private void appendValue(        StringBuffer        buf,        Hashtable           oidSymbols,        DERObjectIdentifier oid,        String              value)    {        String  sym = (String)oidSymbols.get(oid);        if (sym != null)        {            buf.append(sym);        }        else        {            buf.append(((DERObjectIdentifier)oid).getId());        }        buf.append("=");        int     index = buf.length();        buf.append(value);        int     end = buf.length();        while (index != end)        {            if ((buf.charAt(index) == ',')               || (buf.charAt(index) == '"')               || (buf.charAt(index) == '\\')               || (buf.charAt(index) == '+')               || (buf.charAt(index) == '<')               || (buf.charAt(index) == '>')               || (buf.charAt(index) == ';'))            {                buf.insert(index, "\\");                index++;                end++;            }            index++;        }    }    /**     * convert the structure to a string - if reverse is true the     * oids and values are listed out starting with the last element     * in the sequence (ala RFC 2253), otherwise the string will begin     * with the first element of the structure. If no string definition     * for the oid is found in oidSymbols the string value of the oid is     * added. Two standard symbol tables are provided DefaultSymbols, and     * RFC2253Symbols as part of this class.     *     * @param reverse if true start at the end of the sequence and work back.     * @param oidSymbols look up table strings for oids.     */    public String toString(        boolean     reverse,        Hashtable   oidSymbols)    {        StringBuffer            buf = new StringBuffer();        boolean                 first = true;        if (reverse)        {            for (int i = ordering.size() - 1; i >= 0; i--)            {                if (first)                {                    first = false;                }                else                {                    buf.append(",");                }                appendValue(buf, oidSymbols,                             (DERObjectIdentifier)ordering.elementAt(i),                            (String)values.elementAt(i));            }        }        else        {            for (int i = 0; i < ordering.size(); i++)            {                if (first)                {                    first = false;                }                else                {                    buf.append(",");                }                appendValue(buf, oidSymbols,                             (DERObjectIdentifier)ordering.elementAt(i),                            (String)values.elementAt(i));            }        }        return buf.toString();    }    public String toString()    {        return toString(DefaultReverse, DefaultSymbols);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -