public override void PerformTest() { string pseudonym = "pseudonym"; DirectoryString surname = new DirectoryString("surname"); Asn1Sequence givenName = new DerSequence(new DirectoryString("givenName")); NameOrPseudonym id = new NameOrPseudonym(pseudonym); checkConstruction(id, pseudonym, null, null); id = new NameOrPseudonym(surname, givenName); checkConstruction(id, null, surname, givenName); id = NameOrPseudonym.GetInstance(null); if (id != null) { Fail("null GetInstance() failed."); } try { NameOrPseudonym.GetInstance(new Object()); Fail("GetInstance() failed to detect bad object."); } catch (ArgumentException) { // expected } }
private void checkConstruction( NameOrPseudonym id, string pseudonym, DirectoryString surname, Asn1Sequence givenName) { checkValues(id, pseudonym, surname, givenName); id = NameOrPseudonym.GetInstance(id); checkValues(id, pseudonym, surname, givenName); Asn1InputStream aIn = new Asn1InputStream(id.ToAsn1Object().GetEncoded()); if (surname != null) { Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject(); id = NameOrPseudonym.GetInstance(seq); } else { IAsn1String s = (IAsn1String) aIn.ReadObject(); id = NameOrPseudonym.GetInstance(s); } checkValues(id, pseudonym, surname, givenName); }
public static DirectoryString GetInstance(Asn1TaggedObject obj, bool isExplicit) { if (!isExplicit) { throw new ArgumentException("choice item must be explicitly tagged"); } return(DirectoryString.GetInstance(obj.GetObject())); }
/** * Constructor from given details. * <p/> * All parameters can be combined. * * @param namingAuthorityID ObjectIdentifier for naming authority. * @param namingAuthorityUrl URL for naming authority. * @param namingAuthorityText Textual representation of naming authority. */ public NamingAuthority( DerObjectIdentifier namingAuthorityID, string namingAuthorityUrl, DirectoryString namingAuthorityText) { this.namingAuthorityID = namingAuthorityID; this.namingAuthorityUrl = new DerIA5String(namingAuthorityUrl, true); this.namingAuthorityText = namingAuthorityText; }
private void checkValues( NamingAuthority auth, DerObjectIdentifier namingAuthorityId, string namingAuthorityURL, DirectoryString namingAuthorityText) { checkOptionalField("namingAuthorityId", namingAuthorityId, auth.NamingAuthorityID); checkOptionalField("namingAuthorityURL", namingAuthorityURL, auth.NamingAuthorityUrl); checkOptionalField("namingAuthorityText", namingAuthorityText, auth.NamingAuthorityText); }
/** * Constructor from a given details. * <p/> * <p/> * Either <code>generalName</code> or <code>certRef</code> MUST be * <code>null</code>. * * @param country The country code whose laws apply. * @param typeOfSubstitution The type of procuration. * @param thirdPerson The GeneralName of the person who is represented. * @param certRef Reference to certificate of the person who is represented. */ public Procuration( string country, DirectoryString typeOfSubstitution, GeneralName thirdPerson, IssuerSerial certRef) { this.country = new DerPrintableString(country, true); this.typeOfSubstitution = typeOfSubstitution; this.thirdPerson = thirdPerson; this.certRef = certRef; }
/** * Constructor from a given details. * * @param surname The surname. * @param givenName An IEnumerable of strings of the given name */ public NameOrPseudonym( string surname, IEnumerable givenName) { this.surname = new DirectoryString(surname); this.givenName = new ArrayList(); foreach (string s in givenName) { this.givenName.Add(new DirectoryString(s)); } }
public override void PerformTest() { NameOrPseudonym nameOrPseudonym = new NameOrPseudonym("pseudonym"); BigInteger nameDistinguisher = BigInteger.ValueOf(10); DerGeneralizedTime dateOfBirth= new DerGeneralizedTime("20070315173729Z"); DirectoryString placeOfBirth = new DirectoryString("placeOfBirth"); string gender = "M"; DirectoryString postalAddress = new DirectoryString("address"); PersonalData data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); data = new PersonalData(nameOrPseudonym, null, dateOfBirth, placeOfBirth, gender, postalAddress); checkConstruction(data, nameOrPseudonym, null, dateOfBirth, placeOfBirth, gender, postalAddress); data = new PersonalData(nameOrPseudonym, nameDistinguisher, null, placeOfBirth, gender, postalAddress); checkConstruction(data, nameOrPseudonym, nameDistinguisher, null, placeOfBirth, gender, postalAddress); data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, null, gender, postalAddress); checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, null, gender, postalAddress); data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, null, postalAddress); checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, null, postalAddress); data = new PersonalData(nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, null); checkConstruction(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, null); data = PersonalData.GetInstance(null); if (data != null) { Fail("null GetInstance() failed."); } try { PersonalData.GetInstance(new Object()); Fail("GetInstance() failed to detect bad object."); } catch (ArgumentException) { // expected } }
/** * Constructor from a given details. * * @param nameOrPseudonym Name or pseudonym. * @param nameDistiguisher Name distinguisher. * @param dateOfBirth Date of birth. * @param placeOfBirth Place of birth. * @param gender Gender. * @param postalAddress Postal Address. */ public PersonalData( NameOrPseudonym nameOrPseudonym, BigInteger nameDistiguisher, DerGeneralizedTime dateOfBirth, string placeOfBirth, string gender, string postalAddress) { this.nameOrPseudonym = nameOrPseudonym; this.dateOfBirth = dateOfBirth; this.gender = new DerPrintableString(gender, true); this.nameDistiguisher = nameDistiguisher; this.postalAddress = new DirectoryString(postalAddress); this.placeOfBirth = new DirectoryString(placeOfBirth); }
/** * Constructor from a given details. * * @param nameOrPseudonym Name or pseudonym. * @param nameDistinguisher Name distinguisher. * @param dateOfBirth Date of birth. * @param placeOfBirth Place of birth. * @param gender Gender. * @param postalAddress Postal Address. */ public PersonalData( NameOrPseudonym nameOrPseudonym, IBigInteger nameDistinguisher, DerGeneralizedTime dateOfBirth, DirectoryString placeOfBirth, string gender, DirectoryString postalAddress) { this.nameOrPseudonym = nameOrPseudonym; this.dateOfBirth = dateOfBirth; this.gender = gender; this.nameDistinguisher = nameDistinguisher; this.postalAddress = postalAddress; this.placeOfBirth = placeOfBirth; }
private void checkValues( NameOrPseudonym id, string pseudonym, DirectoryString surname, Asn1Sequence givenName) { if (surname != null) { checkMandatoryField("surname", surname, id.Surname); checkMandatoryField("givenName", givenName, new DerSequence(id.GetGivenName()[0])); } else { checkOptionalField("pseudonym", new DirectoryString(pseudonym), id.Pseudonym); } }
private void checkConstruction( Restriction restriction, DirectoryString res) { checkValues(restriction, res); restriction = Restriction.GetInstance(restriction); checkValues(restriction, res); Asn1InputStream aIn = new Asn1InputStream(restriction.ToAsn1Object().GetEncoded()); IAsn1String str = (IAsn1String) aIn.ReadObject(); restriction = Restriction.GetInstance(str); checkValues(restriction, res); }
public override void PerformTest() { DirectoryString res = new DirectoryString("test"); Restriction restriction = new Restriction(res.GetString()); checkConstruction(restriction, res); try { Restriction.GetInstance(new Object()); Fail("GetInstance() failed to detect bad object."); } catch (ArgumentException) { // expected } }
private void checkConstruction( AdditionalInformationSyntax syntax, DirectoryString information) { checkValues(syntax, information); syntax = AdditionalInformationSyntax.GetInstance(syntax); checkValues(syntax, information); Asn1InputStream aIn = new Asn1InputStream(syntax.ToAsn1Object().GetEncoded()); IAsn1String info = (IAsn1String) aIn.ReadObject(); syntax = AdditionalInformationSyntax.GetInstance(info); checkValues(syntax, information); }
private void checkConstruction( NamingAuthority auth, DerObjectIdentifier namingAuthorityID, string namingAuthorityURL, DirectoryString namingAuthorityText) { checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); auth = NamingAuthority.GetInstance(auth); checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); Asn1InputStream aIn = new Asn1InputStream(auth.ToAsn1Object().GetEncoded()); Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject(); auth = NamingAuthority.GetInstance(seq); checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); }
public override void PerformTest() { string country = "AU"; DirectoryString typeOfSubstitution = new DirectoryString("substitution"); GeneralName thirdPerson = new GeneralName(new X509Name("CN=thirdPerson")); IssuerSerial certRef = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), new DerInteger(1)); ProcurationSyntax procuration = new ProcurationSyntax(country, typeOfSubstitution, thirdPerson); checkConstruction(procuration, country, typeOfSubstitution, thirdPerson, null); procuration = new ProcurationSyntax(country, typeOfSubstitution, certRef); checkConstruction(procuration, country, typeOfSubstitution, null, certRef); procuration = new ProcurationSyntax(null, typeOfSubstitution, certRef); checkConstruction(procuration, null, typeOfSubstitution, null, certRef); procuration = new ProcurationSyntax(country, null, certRef); checkConstruction(procuration, country, null, null, certRef); procuration = ProcurationSyntax.GetInstance(null); if (procuration != null) { Fail("null GetInstance() failed."); } try { ProcurationSyntax.GetInstance(new Object()); Fail("GetInstance() failed to detect bad object."); } catch (ArgumentException) { // expected } }
private void checkConstruction( ProcurationSyntax procuration, string country, DirectoryString typeOfSubstitution, GeneralName thirdPerson, IssuerSerial certRef) { checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); procuration = ProcurationSyntax.GetInstance(procuration); checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); Asn1InputStream aIn = new Asn1InputStream(procuration.ToAsn1Object().GetEncoded()); Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject(); procuration = ProcurationSyntax.GetInstance(seq); checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); }
public override void PerformTest() { DerObjectIdentifier namingAuthorityID = new DerObjectIdentifier("1.2.3"); string namingAuthorityURL = "url"; DirectoryString namingAuthorityText = new DirectoryString("text"); NamingAuthority auth = new NamingAuthority(namingAuthorityID, namingAuthorityURL, namingAuthorityText); checkConstruction(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); auth = new NamingAuthority(null, namingAuthorityURL, namingAuthorityText); checkConstruction(auth, null, namingAuthorityURL, namingAuthorityText); auth = new NamingAuthority(namingAuthorityID, null, namingAuthorityText); checkConstruction(auth, namingAuthorityID, null, namingAuthorityText); auth = new NamingAuthority(namingAuthorityID, namingAuthorityURL, null); checkConstruction(auth, namingAuthorityID, namingAuthorityURL, null); auth = NamingAuthority.GetInstance(null); if (auth != null) { Fail("null GetInstance() failed."); } try { NamingAuthority.GetInstance(new Object()); Fail("GetInstance() failed to detect bad object."); } catch (ArgumentException) { // expected } }
private void checkConstruction( ProfessionInfo profInfo, NamingAuthority auth, DirectoryString[] professionItems, DerObjectIdentifier[] professionOids, string registrationNumber, DerOctetString addProfInfo) { checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); profInfo = ProfessionInfo.GetInstance(profInfo); checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); Asn1InputStream aIn = new Asn1InputStream(profInfo.ToAsn1Object().GetEncoded()); Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject(); profInfo = ProfessionInfo.GetInstance(seq); checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); }
private void checkConstruction( PersonalData data, NameOrPseudonym nameOrPseudonym, BigInteger nameDistinguisher, DerGeneralizedTime dateOfBirth, DirectoryString placeOfBirth, string gender, DirectoryString postalAddress) { checkValues(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); data = PersonalData.GetInstance(data); checkValues(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); Asn1InputStream aIn = new Asn1InputStream(data.ToAsn1Object().GetEncoded()); Asn1Sequence seq = (Asn1Sequence) aIn.ReadObject(); data = PersonalData.GetInstance(seq); checkValues(data, nameOrPseudonym, nameDistinguisher, dateOfBirth, placeOfBirth, gender, postalAddress); }
private void checkValues( ProfessionInfo profInfo, NamingAuthority auth, DirectoryString[] professionItems, DerObjectIdentifier[] professionOids, string registrationNumber, DerOctetString addProfInfo) { checkOptionalField("auth", auth, profInfo.NamingAuthority); checkMandatoryField("professionItems", professionItems[0], profInfo.GetProfessionItems()[0]); if (professionOids != null) { checkOptionalField("professionOids", professionOids[0], profInfo.GetProfessionOids()[0]); } checkOptionalField("registrationNumber", registrationNumber, profInfo.RegistrationNumber); checkOptionalField("addProfessionInfo", addProfInfo, profInfo.AddProfessionInfo); }
/** * Constructor from a given details. * * @param restriction The description of the restriction. */ public Restriction( string restriction) { this.restriction = new DirectoryString(restriction); }
/** * Constructor from DirectoryString. * <p/> * The DirectoryString is of type RestrictionSyntax: * <p/> * <pre> * RestrictionSyntax ::= DirectoryString (SIZE(1..1024)) * </pre> * * @param restriction A IAsn1String. */ private Restriction( DirectoryString restriction) { this.restriction = restriction; }
/** * Constructor from Asn1Sequence. * <p/> * The sequence is of type ProcurationSyntax: * <p/> * <pre> * ProcurationSyntax ::= SEQUENCE { * country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL, * typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL, * signingFor [3] EXPLICIT SigningFor * } * <p/> * SigningFor ::= CHOICE * { * thirdPerson GeneralName, * certRef IssuerSerial * } * </pre> * * @param seq The ASN.1 sequence. */ private Procuration( Asn1Sequence seq) { if (seq.Count < 1 || seq.Count > 3) throw new ArgumentException("Bad sequence size: " + seq.Count); IEnumerator e = seq.GetEnumerator(); while (e.MoveNext()) { Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current); switch (o.TagNo) { case 1: country = DerPrintableString.GetInstance(o, true); break; case 2: typeOfSubstitution = DirectoryString.GetInstance(o, true); break; case 3: Asn1Object signingFor = o.GetObject(); if (signingFor is Asn1TaggedObject) { thirdPerson = GeneralName.GetInstance(signingFor); } else { certRef = IssuerSerial.GetInstance(signingFor); } break; default: throw new ArgumentException("Bad tag number: " + o.TagNo); } } }
private void checkValues( ProcurationSyntax procuration, string country, DirectoryString typeOfSubstitution, GeneralName thirdPerson, IssuerSerial certRef) { checkOptionalField("country", country, procuration.Country); checkOptionalField("typeOfSubstitution", typeOfSubstitution, procuration.TypeOfSubstitution); checkOptionalField("thirdPerson", thirdPerson, procuration.ThirdPerson); checkOptionalField("certRef", certRef, procuration.CertRef); }
private AdditionalInformationSyntax( DirectoryString information) { this.information = information; }
/** * Constructor from a given details. * * @param pseudonym The pseudonym. */ public NameOrPseudonym( string pseudonym) { this.pseudonym = new DirectoryString(pseudonym); }
/** * Constructor from DERString. * <p/> * The sequence is of type NameOrPseudonym: * <p/> * <pre> * NameOrPseudonym ::= CHOICE { * surAndGivenName SEQUENCE { * surName DirectoryString, * givenName SEQUENCE OF DirectoryString * }, * pseudonym DirectoryString * } * </pre> * @param pseudonym pseudonym value to use. */ public NameOrPseudonym( DirectoryString pseudonym) { this.pseudonym = pseudonym; }
/** * Constructor from Asn1Sequence. * <p/> * The sequence is of type NameOrPseudonym: * <p/> * <pre> * NameOrPseudonym ::= CHOICE { * surAndGivenName SEQUENCE { * surName DirectoryString, * givenName SEQUENCE OF DirectoryString * }, * pseudonym DirectoryString * } * </pre> * * @param seq The ASN.1 sequence. */ private NameOrPseudonym( Asn1Sequence seq) { if (seq.Count != 2) throw new ArgumentException("Bad sequence size: " + seq.Count); if (!(seq[0] is IAsn1String)) throw new ArgumentException("Bad object encountered: " + seq[0].GetType().Name); surname = DirectoryString.GetInstance(seq[0]); givenName = new ArrayList(); Asn1Sequence s = Asn1Sequence.GetInstance(seq[1]); foreach (object o in s) { if (!(o is IAsn1String)) throw new ArgumentException("Bad object encountered: " + o.GetType().Name); givenName.Add(DirectoryString.GetInstance(o)); } }
/** * Constructor from a given details. * * @param information The describtion of the information. */ public AdditionalInformationSyntax( string information) { this.information = new DirectoryString(information); }
/** * Constructor from Asn1Sequence. * <p/> * <p/> * <pre> * NamingAuthority ::= SEQUENCE * { * namingAuthorityID OBJECT IDENTIFIER OPTIONAL, * namingAuthorityUrl IA5String OPTIONAL, * namingAuthorityText DirectoryString(SIZE(1..128)) OPTIONAL * } * </pre> * * @param seq The ASN.1 sequence. */ private NamingAuthority( Asn1Sequence seq) { if (seq.Count > 3) throw new ArgumentException("Bad sequence size: " + seq.Count); IEnumerator e = seq.GetEnumerator(); if (e.MoveNext()) { Asn1Encodable o = (Asn1Encodable) e.Current; if (o is DerObjectIdentifier) { namingAuthorityID = (DerObjectIdentifier) o; } else if (o is DerIA5String) { namingAuthorityUrl = DerIA5String.GetInstance(o).GetString(); } else if (o is IAsn1String) { namingAuthorityText = DirectoryString.GetInstance(o); } else { throw new ArgumentException("Bad object encountered: " + o.GetType().Name); } } if (e.MoveNext()) { Asn1Encodable o = (Asn1Encodable) e.Current; if (o is DerIA5String) { namingAuthorityUrl = DerIA5String.GetInstance(o).GetString(); } else if (o is IAsn1String) { namingAuthorityText = DirectoryString.GetInstance(o); } else { throw new ArgumentException("Bad object encountered: " + o.GetType().Name); } } if (e.MoveNext()) { Asn1Encodable o = (Asn1Encodable) e.Current; if (o is IAsn1String) { namingAuthorityText = DirectoryString.GetInstance(o); } else { throw new ArgumentException("Bad object encountered: " + o.GetType().Name); } } }