1
by Brian Thomason
Initial import |
1 |
package org.bouncycastle.asn1.crmf; |
2 |
||
3 |
import org.bouncycastle.asn1.ASN1Encodable; |
|
4 |
import org.bouncycastle.asn1.ASN1EncodableVector; |
|
5 |
import org.bouncycastle.asn1.ASN1Sequence; |
|
6 |
import org.bouncycastle.asn1.ASN1TaggedObject; |
|
7 |
import org.bouncycastle.asn1.DERObject; |
|
8 |
import org.bouncycastle.asn1.DERSequence; |
|
9 |
import org.bouncycastle.asn1.DERTaggedObject; |
|
10 |
import org.bouncycastle.asn1.x509.Time; |
|
11 |
||
12 |
import java.util.Enumeration; |
|
13 |
||
14 |
public class OptionalValidity |
|
15 |
extends ASN1Encodable |
|
16 |
{
|
|
17 |
private Time notBefore; |
|
18 |
private Time notAfter; |
|
19 |
||
20 |
private OptionalValidity(ASN1Sequence seq) |
|
21 |
{
|
|
22 |
Enumeration en = seq.getObjects(); |
|
23 |
while (en.hasMoreElements()) |
|
24 |
{
|
|
25 |
ASN1TaggedObject tObj = (ASN1TaggedObject)en.nextElement(); |
|
26 |
||
27 |
if (tObj.getTagNo() == 0) |
|
28 |
{
|
|
29 |
notBefore = Time.getInstance(tObj, true); |
|
30 |
}
|
|
31 |
else
|
|
32 |
{
|
|
33 |
notAfter = Time.getInstance(tObj, true); |
|
34 |
}
|
|
35 |
}
|
|
36 |
}
|
|
37 |
||
38 |
public static OptionalValidity getInstance(Object o) |
|
39 |
{
|
|
40 |
if (o instanceof OptionalValidity) |
|
41 |
{
|
|
42 |
return (OptionalValidity)o; |
|
43 |
}
|
|
44 |
||
45 |
if (o instanceof ASN1Sequence) |
|
46 |
{
|
|
47 |
return new OptionalValidity((ASN1Sequence)o); |
|
48 |
}
|
|
49 |
||
50 |
throw new IllegalArgumentException("Invalid object: " + o.getClass().getName()); |
|
51 |
}
|
|
52 |
||
53 |
/**
|
|
54 |
* <pre>
|
|
55 |
* OptionalValidity ::= SEQUENCE {
|
|
56 |
* notBefore [0] Time OPTIONAL,
|
|
57 |
* notAfter [1] Time OPTIONAL } --at least one MUST be present
|
|
58 |
* </pre>
|
|
59 |
* @return a basic ASN.1 object representation.
|
|
60 |
*/
|
|
61 |
public DERObject toASN1Object() |
|
62 |
{
|
|
63 |
ASN1EncodableVector v = new ASN1EncodableVector(); |
|
64 |
||
65 |
if (notBefore != null) |
|
66 |
{
|
|
67 |
v.add(new DERTaggedObject(true, 0, notBefore)); |
|
68 |
}
|
|
69 |
||
70 |
if (notAfter != null) |
|
71 |
{
|
|
72 |
v.add(new DERTaggedObject(true, 1, notAfter)); |
|
73 |
}
|
|
74 |
||
75 |
return new DERSequence(v); |
|
76 |
}
|
|
77 |
}
|