/** * 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) { }
/** * 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. */ public X509Name( ArrayList oids, ArrayList values, X509NameEntryConverter converter) { this.converter = converter; if (oids.Count != values.Count) { throw new ArgumentException("oids vector 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); } }
/** * 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 vector should contain the OIDs * in the order they are meant to be encoded or printed in toString. * <p> * The passed in converter will be used to convert the strings into their * ASN.1 counterparts. */ public X509Name( ArrayList ordering, Hashtable attributes, X509DefaultEntryConverter converter) { this.converter = converter; if (ordering != null) { for (int i = 0; i != ordering.Count; i++) { this.ordering.Add(ordering[i]); this.added.Add(false); } } else { IEnumerator e = attributes.Keys.GetEnumerator(); while (e.MoveNext()) { this.ordering.Add(e.Current); this.added.Add(false); } } for (int i = 0; i != this.ordering.Count; i++) { DERObjectIdentifier oid = (DERObjectIdentifier)this.ordering[i]; if (attributes[oid] == null) { throw new ArgumentException("No attribute for object id - " + oid.getId() + " - passed to distinguished name"); } this.values.Add(attributes[oid]); // copy the hash table } }
/** * 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, Hashtable 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, '+'); this.ordering.Add(oid); this.values.Add(vTok.nextToken()); 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) { ArrayList o = new ArrayList(); ArrayList v = new ArrayList(); ArrayList a = new ArrayList(); for (int i = this.ordering.Count - 1; i >= 0; i--) { o.Add(this.ordering[i]); v.Add(this.values[i]); a.Add(this.added[i]); } this.ordering = o; this.values = v; this.added = a; } }