1
package org.bouncycastle.asn1.test;
3
import org.bouncycastle.asn1.ASN1InputStream;
4
import org.bouncycastle.asn1.DERGeneralizedTime;
5
import org.bouncycastle.asn1.DERTaggedObject;
6
import org.bouncycastle.asn1.isismtt.x509.DeclarationOfMajority;
8
import java.io.IOException;
10
public class DeclarationOfMajorityUnitTest
13
public String getName()
15
return "DeclarationOfMajority";
18
public void performTest()
21
DERGeneralizedTime dateOfBirth = new DERGeneralizedTime("20070315173729Z");
22
DeclarationOfMajority decl = new DeclarationOfMajority(dateOfBirth);
24
checkConstruction(decl, DeclarationOfMajority.dateOfBirth, dateOfBirth, -1);
26
decl = new DeclarationOfMajority(6);
28
checkConstruction(decl, DeclarationOfMajority.notYoungerThan, null, 6);
30
decl = DeclarationOfMajority.getInstance(null);
34
fail("null getInstance() failed.");
39
DeclarationOfMajority.getInstance(new Object());
41
fail("getInstance() failed to detect bad object.");
43
catch (IllegalArgumentException e)
49
private void checkConstruction(
50
DeclarationOfMajority decl,
52
DERGeneralizedTime dateOfBirth,
56
checkValues(decl, type, dateOfBirth, notYoungerThan);
58
decl = DeclarationOfMajority.getInstance(decl);
60
checkValues(decl, type, dateOfBirth, notYoungerThan);
62
ASN1InputStream aIn = new ASN1InputStream(decl.toASN1Object().getEncoded());
64
DERTaggedObject info = (DERTaggedObject)aIn.readObject();
66
decl = DeclarationOfMajority.getInstance(info);
68
checkValues(decl, type, dateOfBirth, notYoungerThan);
71
private void checkValues(
72
DeclarationOfMajority decl,
74
DERGeneralizedTime dateOfBirth,
77
checkMandatoryField("type", type, decl.getType());
78
checkOptionalField("dateOfBirth", dateOfBirth, decl.getDateOfBirth());
79
if (notYoungerThan != -1 && notYoungerThan != decl.notYoungerThan())
81
fail("notYoungerThan mismatch");
85
public static void main(
88
runTest(new DeclarationOfMajorityUnitTest());