public static NameOrPseudonym getInstance(Object obj) { if (obj == null || obj instanceof NameOrPseudonym) { return (NameOrPseudonym)obj; } if (obj instanceof ASN1String) { return new NameOrPseudonym(DirectoryString.getInstance(obj)); } if (obj instanceof ASN1Sequence) { return new NameOrPseudonym((ASN1Sequence)obj); } throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); }
/** * 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.size() != 2) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } if (!(seq.getObjectAt(0) instanceof ASN1String)) { throw new IllegalArgumentException("Bad object encountered: " + seq.getObjectAt(0).getClass()); } surname = DirectoryString.getInstance(seq.getObjectAt(0)); givenName = ASN1Sequence.getInstance(seq.getObjectAt(1)); }
/** * Constructor from ASN1Sequence. * <p> * The sequence is of type NameOrPseudonym: * <pre> * NameOrPseudonym ::= CHOICE { * surAndGivenName SEQUENCE { * surName DirectoryString, * givenName SEQUENCE OF DirectoryString * }, * pseudonym DirectoryString * } * </pre> * </p> * @param seq The ASN.1 sequence. */ private NameOrPseudonym(ASN1Sequence seq) { if (seq.size() != 2) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } if (!(seq.getObjectAt(0) instanceof ASN1String)) { throw new IllegalArgumentException("Bad object encountered: " + seq.getObjectAt(0).getClass()); } surname = DirectoryString.getInstance(seq.getObjectAt(0)); givenName = ASN1Sequence.getInstance(seq.getObjectAt(1)); }
/** * Constructor from given details. * <p> * <code>professionItems</code> is mandatory, all other parameters are * optional. * * @param namingAuthority The naming authority. * @param professionItems Directory strings of the profession. * @param professionOIDs DERObjectIdentfier objects for the * profession. * @param registrationNumber Registration number. * @param addProfessionInfo Additional infos in encoded form. */ public ProfessionInfo(NamingAuthority namingAuthority, DirectoryString[] professionItems, ASN1ObjectIdentifier[] professionOIDs, String registrationNumber, ASN1OctetString addProfessionInfo) { this.namingAuthority = namingAuthority; ASN1EncodableVector v = new ASN1EncodableVector(); for (int i = 0; i != professionItems.length; i++) { v.add(professionItems[i]); } this.professionItems = new DERSequence(v); if (professionOIDs != null) { v = new ASN1EncodableVector(); for (int i = 0; i != professionOIDs.length; i++) { v.add(professionOIDs[i]); } this.professionOIDs = new DERSequence(v); } this.registrationNumber = registrationNumber; this.addProfessionInfo = addProfessionInfo; }
private void checkConstruction( NamingAuthority auth, ASN1ObjectIdentifier namingAuthorityID, String namingAuthorityURL, DirectoryString namingAuthorityText) throws IOException { checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); auth = NamingAuthority.getInstance(auth); checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); ASN1InputStream aIn = new ASN1InputStream(auth.toASN1Primitive().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); auth = NamingAuthority.getInstance(seq); checkValues(auth, namingAuthorityID, namingAuthorityURL, namingAuthorityText); }
private void checkConstruction( ProcurationSyntax procuration, String country, DirectoryString typeOfSubstitution, GeneralName thirdPerson, IssuerSerial certRef) throws IOException { checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); procuration = ProcurationSyntax.getInstance(procuration); checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); ASN1InputStream aIn = new ASN1InputStream(procuration.toASN1Primitive().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); procuration = ProcurationSyntax.getInstance(seq); checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef); }
private void checkConstruction( ProfessionInfo profInfo, NamingAuthority auth, DirectoryString[] professionItems, ASN1ObjectIdentifier[] professionOids, String registrationNumber, DEROctetString addProfInfo) throws IOException { checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); profInfo = ProfessionInfo.getInstance(profInfo); checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); ASN1InputStream aIn = new ASN1InputStream(profInfo.toASN1Primitive().getEncoded()); ASN1Sequence seq = (ASN1Sequence)aIn.readObject(); profInfo = ProfessionInfo.getInstance(seq); checkValues(profInfo, auth, professionItems, professionOids, registrationNumber, addProfInfo); }
private void checkValues( ProfessionInfo profInfo, NamingAuthority auth, DirectoryString[] professionItems, ASN1ObjectIdentifier[] professionOids, String registrationNumber, DEROctetString addProfInfo) { checkOptionalField("auth", auth, profInfo.getNamingAuthority()); checkMandatoryField("professionItems", professionItems[0], profInfo.getProfessionItems()[0]); if (professionOids != null) { checkOptionalField("professionOids", professionOids[0], profInfo.getProfessionOIDs()[0]); } checkOptionalField("registrationNumber", registrationNumber, profInfo.getRegistrationNumber()); checkOptionalField("addProfessionInfo", addProfInfo, profInfo.getAddProfessionInfo()); }
public void performTest() throws Exception { AdditionalInformationSyntax syntax = new AdditionalInformationSyntax("hello world"); checkConstruction(syntax, new DirectoryString("hello world")); try { AdditionalInformationSyntax.getInstance(new Object()); fail("getInstance() failed to detect bad object."); } catch (IllegalArgumentException e) { // expected } }
public void performTest() throws Exception { 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 (IllegalArgumentException e) { // expected } }
@Override public void parse(ASN1Primitive derObject) { ASN1Sequence derSequence = ASN1Object.getDERSequence(derObject); ASN1Primitive firstObject = derSequence.getObjectAt(0).toASN1Primitive(); this.policyName = new DirectoryString(firstObject.toString()); ASN1Primitive secondObject = derSequence.getObjectAt(1).toASN1Primitive(); String fieldOfApplication = secondObject.toString(); this.fieldOfApplication = new DirectoryString(fieldOfApplication); this.signingPeriod = new SigningPeriod(); this.signingPeriod.parse(derSequence.getObjectAt(2).toASN1Primitive()); int indice = 3; ASN1Primitive revocationObject = derSequence.getObjectAt(indice).toASN1Primitive(); if (!(secondObject instanceof DERTaggedObject)) { indice = 4; } if (indice == 3) { this.revocationDate = new Time(); this.revocationDate.parse(revocationObject); } }
/** * Constructor from given details. * <p/> * <code>professionItems</code> is mandatory, all other parameters are * optional. * * @param namingAuthority The naming authority. * @param professionItems Directory strings of the profession. * @param professionOIDs DERObjectIdentfier objects for the * profession. * @param registrationNumber Registration number. * @param addProfessionInfo Additional infos in encoded form. */ public ProfessionInfo(NamingAuthority namingAuthority, DirectoryString[] professionItems, ASN1ObjectIdentifier[] professionOIDs, String registrationNumber, ASN1OctetString addProfessionInfo) { this.namingAuthority = namingAuthority; ASN1EncodableVector v = new ASN1EncodableVector(); for (int i = 0; i != professionItems.length; i++) { v.add(professionItems[i]); } this.professionItems = new DERSequence(v); if (professionOIDs != null) { v = new ASN1EncodableVector(); for (int i = 0; i != professionOIDs.length; i++) { v.add(professionOIDs[i]); } this.professionOIDs = new DERSequence(v); } this.registrationNumber = registrationNumber; this.addProfessionInfo = addProfessionInfo; }
private void checkConstruction( NamingAuthority auth, DERObjectIdentifier namingAuthorityID, String namingAuthorityURL, DirectoryString namingAuthorityText) throws IOException { 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); }
private void checkConstruction( PersonalData data, NameOrPseudonym nameOrPseudonym, BigInteger nameDistinguisher, DERGeneralizedTime dateOfBirth, DirectoryString placeOfBirth, String gender, DirectoryString postalAddress) throws IOException { 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( PersonalData data, NameOrPseudonym nameOrPseudonym, BigInteger nameDistinguisher, DERGeneralizedTime dateOfBirth, DirectoryString placeOfBirth, String gender, DirectoryString postalAddress) { checkMandatoryField("nameOrPseudonym", nameOrPseudonym, data.getNameOrPseudonym()); checkOptionalField("nameDistinguisher", nameDistinguisher, data.getNameDistinguisher()); checkOptionalField("dateOfBirth", dateOfBirth, data.getDateOfBirth()); checkOptionalField("placeOfBirth", placeOfBirth, data.getPlaceOfBirth()); checkOptionalField("gender", gender, data.getGender()); checkOptionalField("postalAddress", postalAddress, data.getPostalAddress()); }
private void checkConstruction( ProcurationSyntax procuration, String country, DirectoryString typeOfSubstitution, GeneralName thirdPerson, IssuerSerial certRef) throws IOException { 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); }
private void checkValues( NameOrPseudonym id, String pseudonym, DirectoryString surname, ASN1Sequence givenName) { if (surname != null) { checkMandatoryField("surname", surname, id.getSurname()); checkMandatoryField("givenName", givenName, new DERSequence(id.getGivenName()[0])); } else { checkOptionalField("pseudonym", new DirectoryString(pseudonym), id.getPseudonym()); } }
private void checkConstruction( ProfessionInfo profInfo, NamingAuthority auth, DirectoryString[] professionItems, DERObjectIdentifier[] professionOids, String registrationNumber, DEROctetString addProfInfo) throws IOException { 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 checkValues( ProfessionInfo profInfo, NamingAuthority auth, DirectoryString[] professionItems, DERObjectIdentifier[] professionOids, String registrationNumber, DEROctetString addProfInfo) { checkOptionalField("auth", auth, profInfo.getNamingAuthority()); checkMandatoryField("professionItems", professionItems[0], profInfo.getProfessionItems()[0]); if (professionOids != null) { checkOptionalField("professionOids", professionOids[0], profInfo.getProfessionOIDs()[0]); } checkOptionalField("registrationNumber", registrationNumber, profInfo.getRegistrationNumber()); checkOptionalField("addProfessionInfo", addProfInfo, profInfo.getAddProfessionInfo()); }