/** * 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++) { ordering.Add(oids[i]); this.values.Add(values[i]); 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 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); added.Add(false); values.Add(attribute); // 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, IDictionary lookUp, string dirName, X509NameEntryConverter converter) { this.converter = converter; var 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) { var vTok = new X509NameTokenizer(value, '+'); string v = vTok.NextToken(); ordering.Add(oid); values.Add(v); 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); ordering.Add(DecodeOid(nm, lookUp)); values.Add(vl); added.Add(true); } } else { ordering.Add(oid); values.Add(value); 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 < ordering.Count; i++) { if (!((bool)added[i])) { count = 0; } int index = count++; o.Insert(index, ordering[i]); v.Insert(index, values[i]); a.Insert(index, added[i]); } ordering = o; values = v; added = a; } }
/** * 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 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; var 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) { var vTok = new X509NameTokenizer(value, '+'); string v = vTok.NextToken(); ordering.Add(oid); values.Add(v); 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); ordering.Add(DecodeOid(nm, lookUp)); values.Add(vl); added.Add(true); } } else { ordering.Add(oid); values.Add(value); 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 < ordering.Count; i++) { if (!((bool) added[i])) { count = 0; } int index = count++; o.Insert(index, ordering[i]); v.Insert(index, values[i]); a.Insert(index, added[i]); } ordering = o; values = v; added = a; } }