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

📄 x509name.java

📁 进行与数字证书相关开发必须的java源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   X509Name.java

package jit.asn1.x509;

import java.util.*;
import jit.asn1.*;

// Referenced classes of package jit.asn1.x509:
//            X509NameTokenizer

public class X509Name
    implements DEREncodable
{

    public static final DERObjectIdentifier C;
    public static final DERObjectIdentifier O;
    public static final DERObjectIdentifier OU;
    public static final DERObjectIdentifier T;
    public static final DERObjectIdentifier CN;
    public static final DERObjectIdentifier SN;
    public static final DERObjectIdentifier L;
    public static final DERObjectIdentifier ST;
    public static final DERObjectIdentifier SURNAME;
    public static final DERObjectIdentifier GIVENNAME;
    public static final DERObjectIdentifier INITIALS;
    public static final DERObjectIdentifier GENERATION;
    public static final DERObjectIdentifier EmailAddress;
    public static final DERObjectIdentifier E;
    public static final DERObjectIdentifier DC;
    public static final DERObjectIdentifier UID;
    public static Hashtable OIDLookUp;
    public static boolean DefaultReverse = false;
    public static Hashtable DefaultSymbols;
    public static Hashtable RFC2253Symbols;
    public static Hashtable SymbolLookUp;
    public static Hashtable DefaultLookUp;
    private Vector ordering;
    private Vector values;
    private ASN1Sequence seq;

    public static X509Name getInstance(ASN1TaggedObject obj, boolean explicit)
    {
        return getInstance(ASN1Sequence.getInstance(obj, explicit));
    }

    public static X509Name getInstance(Object obj)
    {
        if(obj == null || (obj instanceof X509Name))
            return (X509Name)obj;
        if(obj instanceof ASN1Sequence)
            return new X509Name((ASN1Sequence)obj);
        else
            throw new IllegalArgumentException("unknown object in factory");
    }

    public X509Name(ASN1Sequence seq)
    {
        ordering = new Vector();
        values = new Vector();
        this.seq = seq;
        ASN1Sequence s;
        for(Enumeration e = seq.getObjects(); e.hasMoreElements(); values.addElement(((DERString)s.getObjectAt(1)).getString()))
        {
            ASN1Set set = (ASN1Set)e.nextElement();
            s = (ASN1Sequence)set.getObjectAt(0);
            ordering.addElement(s.getObjectAt(0));
        }

    }

    public X509Name(Hashtable attributes)
    {
        this(((Vector) (null)), attributes);
    }

    public X509Name(Vector ordering, Hashtable attributes)
    {
        this.ordering = new Vector();
        values = new Vector();
        if(ordering != null)
        {
            for(int i = 0; i != ordering.size(); i++)
                this.ordering.addElement(ordering.elementAt(i));

        } else
        {
            for(Enumeration e = attributes.keys(); e.hasMoreElements(); this.ordering.addElement(e.nextElement()));
        }
        for(int i = 0; i != this.ordering.size(); i++)
        {
            DERObjectIdentifier oid = (DERObjectIdentifier)this.ordering.elementAt(i);
            if(attributes.get(oid) == null)
                throw new IllegalArgumentException(String.valueOf(String.valueOf((new StringBuffer("No attribute for object id - ")).append(oid.getId()).append(" - passed to distinguished name"))));
            values.addElement(attributes.get(oid));
        }

    }

    public X509Name(Vector oids, Vector values)
    {
        ordering = new Vector();
        this.values = new Vector();
        if(oids.size() != values.size())
            throw new IllegalArgumentException("oids vector must be same length as values.");
        for(int i = 0; i < oids.size(); i++)
        {
            ordering.addElement(oids.elementAt(i));
            this.values.addElement(values.elementAt(i));
        }

    }

    public X509Name(String dirName)
    {
        this(DefaultReverse, DefaultLookUp, dirName);
    }

    public X509Name(boolean reverse, String dirName)
    {
        this(reverse, DefaultLookUp, dirName);
    }

    public X509Name(boolean reverse, Hashtable lookUp, String dirName)
    {
        ordering = new Vector();
        values = new Vector();
        String value;
        for(X509NameTokenizer nTok = new X509NameTokenizer(dirName); nTok.hasMoreTokens(); values.addElement(value))
        {
            String token = nTok.nextToken();
            int index = token.indexOf(61);
            if(index == -1)
                throw new IllegalArgumentException("badly formated directory string");
            String name = token.substring(0, index);
            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(String.valueOf(String.valueOf((new StringBuffer("Unknown object id - ")).append(name).append(" - passed to distinguished name"))));
            }
            ordering.addElement(oid);
        }

        if(reverse)
        {
            Vector o = new Vector();
            Vector v = new Vector();
            for(int i = ordering.size() - 1; i >= 0; i--)
            {
                o.addElement(ordering.elementAt(i));
                v.addElement(values.elementAt(i));
            }

            ordering = o;
            values = v;
        }
    }

    public Vector getOIDs()
    {
        Vector v = new Vector();
        for(int i = 0; i != ordering.size(); i++)
            v.addElement(ordering.elementAt(i));

        return v;
    }

    public Vector getValues()
    {
        Vector v = new Vector();
        for(int i = 0; i != values.size(); i++)
            v.addElement(values.elementAt(i));

        return v;
    }

    private boolean canBePrintable(String str)
    {
        for(int i = str.length() - 1; i >= 0; i--)
            if(str.charAt(i) > '\177')
                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;
    }

    public boolean equals(Object _obj, boolean inOrder)
    {
        if(_obj == this)
            return true;
        if(!inOrder)
            return equals(_obj);
        if(_obj == null || !(_obj instanceof X509Name))
            return false;
        X509Name _oxn = (X509Name)_obj;
        int _orderingSize = ordering.size();
        if(_orderingSize != _oxn.ordering.size())
            return false;
        for(int i = 0; i < _orderingSize; i++)
        {
            String _oid = ((DERObjectIdentifier)ordering.elementAt(i)).getId();
            String _val = (String)values.elementAt(i);
            String _oOID = ((DERObjectIdentifier)_oxn.ordering.elementAt(i)).getId();
            String _oVal = (String)_oxn.values.elementAt(i);
            if(!_oid.equals(_oOID))
                continue;
            _val = _val.trim().toLowerCase();
            _oVal = _oVal.trim().toLowerCase();
            if(_val.equals(_oVal))
                continue;

⌨️ 快捷键说明

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