/**
* addSubjectAlternativeName(int type, byte[] name) method testing.
*/
public void testAddSubjectAlternativeName2() {
try {
GeneralName san0 =
new GeneralName(new OtherName("1.2.3.4.5",
ASN1Integer.getInstance().encode(
BigInteger.valueOf(55L).toByteArray())
));
GeneralName san1 = new GeneralName(1, "rfc@822.Name");
GeneralName san2 = new GeneralName(2, "dNSName");
GeneralName san3 = new GeneralName(new ORAddress());
GeneralName san4 = new GeneralName(new Name("O=Organization"));
GeneralName san5 =
new GeneralName(new EDIPartyName("assigner", "party"));
GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
GeneralName san7 = new GeneralName(new byte[] {1, 1, 1, 1});
GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");
GeneralNames sans_1 = new GeneralNames();
sans_1.addName(san0);
sans_1.addName(san1);
sans_1.addName(san2);
sans_1.addName(san3);
sans_1.addName(san4);
sans_1.addName(san5);
sans_1.addName(san6);
sans_1.addName(san7);
sans_1.addName(san8);
GeneralNames sans_2 = new GeneralNames();
sans_2.addName(san0);
sans_2.addName(san1);
sans_2.addName(san2);
TestCert cert_1 = new TestCert(sans_1);
TestCert cert_2 = new TestCert(sans_2);
X509CertSelector selector = new X509CertSelector();
selector.setMatchAllSubjectAltNames(true);
selector.addSubjectAlternativeName(0, san0.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_2));
selector.addSubjectAlternativeName(1, san1.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_2));
selector.addSubjectAlternativeName(2, san2.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_2));
selector.addSubjectAlternativeName(3, san3.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertFalse("The certificate should not match the selection criteria.",
selector.match(cert_2));
selector.addSubjectAlternativeName(4, san4.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertFalse("The certificate should not match "
+ "the selection criteria.", selector.match(cert_2));
selector.addSubjectAlternativeName(5, san5.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertFalse("The certificate should not match "
+ "the selection criteria.", selector.match(cert_2));
selector.addSubjectAlternativeName(6, san6.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertFalse("The certificate should not match "
+ "the selection criteria.", selector.match(cert_2));
selector.addSubjectAlternativeName(7, san7.getEncodedName());
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertFalse("The certificate should not match "
+ "the selection criteria.", selector.match(cert_2));
byte[] oid = san8.getEncodedName();
selector.addSubjectAlternativeName(8, oid);
assertTrue("The certificate should match the selection criteria.",
selector.match(cert_1));
assertFalse("The certificate should not match "
+ "the selection criteria.", selector.match(cert_2));