示例#1
0
 /**
  * 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 with each
  * string value being converted to its associated ASN.1 type using the passed
  * in converter. If reverse is true the ASN.1 sequence representing the DN will
  * be built by starting at the end of the string, rather than the start.
  */
 public X509Name(
     bool reverse,
     string dirName,
     X509NameEntryConverter converter)
     : this(reverse, DefaultLookup, dirName, converter)
 {
 }
示例#2
0
        /**
         * Takes two vectors one of the oids and the other of the values.
         * <p>
         * The passed in converter will be used to convert the strings into their
         * ASN.1 counterparts.</p>
         */
        public X509Name(
            IList oids,
            IList values,
            X509NameEntryConverter converter)
        {
            this.converter = converter;

            if (oids.Count != values.Count)
            {
                throw new ArgumentException("'oids' must be same length as 'values'.");
            }

            for (int i = 0; i < oids.Count; i++)
            {
                this.ordering.Add(oids[i]);
                this.values.Add(values[i]);
                this.added.Add(false);
            }
        }
示例#3
0
        /**
         * Constructor from a table of attributes with ordering.
         * <p>
         * it's is assumed the table contains OID/string pairs, and the contents
         * of the table are copied into an internal table as part of the
         * construction process. The ordering ArrayList should contain the OIDs
         * in the order they are meant to be encoded or printed in ToString.</p>
         * <p>
         * The passed in converter will be used to convert the strings into their
         * ASN.1 counterparts.</p>
         */
        public X509Name(
            IList ordering,
            IDictionary attributes,
            X509NameEntryConverter converter)
        {
            this.converter = converter;

            foreach (DerObjectIdentifier oid in ordering)
            {
                object attribute = attributes[oid];
                if (attribute == null)
                {
                    throw new ArgumentException("No attribute for object id - " + oid + " - passed to distinguished name");
                }

                this.ordering.Add(oid);
                this.added.Add(false);
                this.values.Add(attribute); // copy the hash table
            }
        }
示例#4
0
        /**
         * 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. The passed in converter is used to convert the
         * string values to the right of each equals sign to their ASN.1 counterparts.
         * <br/>
         * @param reverse true if we should start scanning from the end, false otherwise.
         * @param lookUp table of names and oids.
         * @param dirName the string dirName
         * @param converter the converter to convert string values into their ASN.1 equivalents
         */
        public X509Name(
            bool reverse,
            IDictionary lookUp,
            string dirName,
            X509NameEntryConverter converter)
        {
            this.converter = converter;
            X509NameTokenizer nTok = new X509NameTokenizer(dirName);

            while (nTok.HasMoreTokens())
            {
                string token = nTok.NextToken();
                int    index = token.IndexOf('=');

                if (index == -1)
                {
                    throw new ArgumentException("badly formated directory string");
                }

                string name             = token.Substring(0, index);
                string value            = token.Substring(index + 1);
                DerObjectIdentifier oid = DecodeOid(name, lookUp);

                if (value.IndexOf('+') > 0)
                {
                    X509NameTokenizer vTok = new X509NameTokenizer(value, '+');
                    string            v    = vTok.NextToken();

                    this.ordering.Add(oid);
                    this.values.Add(v);
                    this.added.Add(false);

                    while (vTok.HasMoreTokens())
                    {
                        string sv  = vTok.NextToken();
                        int    ndx = sv.IndexOf('=');

                        string nm = sv.Substring(0, ndx);
                        string vl = sv.Substring(ndx + 1);
                        this.ordering.Add(DecodeOid(nm, lookUp));
                        this.values.Add(vl);
                        this.added.Add(true);
                    }
                }
                else
                {
                    this.ordering.Add(oid);
                    this.values.Add(value);
                    this.added.Add(false);
                }
            }

            if (reverse)
            {
//				this.ordering.Reverse();
//				this.values.Reverse();
//				this.added.Reverse();
                IList o     = Platform.CreateArrayList();
                IList v     = Platform.CreateArrayList();
                IList a     = Platform.CreateArrayList();
                int   count = 1;

                for (int i = 0; i < this.ordering.Count; i++)
                {
                    if (!((bool)this.added[i]))
                    {
                        count = 0;
                    }

                    int index = count++;

                    o.Insert(index, this.ordering[i]);
                    v.Insert(index, this.values[i]);
                    a.Insert(index, this.added[i]);
                }

                this.ordering = o;
                this.values   = v;
                this.added    = a;
            }
        }