01: package org.bouncycastle.asn1.cmp;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DERObject;
07: import org.bouncycastle.asn1.DERSequence;
08:
09: public class ProtectedPart extends ASN1Encodable {
10: private PKIHeader header;
11: private PKIBody body;
12:
13: private ProtectedPart(ASN1Sequence seq) {
14: header = PKIHeader.getInstance(seq.getObjectAt(0));
15: body = PKIBody.getInstance(seq.getObjectAt(1));
16: }
17:
18: public static ProtectedPart getInstance(Object o) {
19: if (o instanceof ProtectedPart) {
20: return (ProtectedPart) o;
21: }
22:
23: if (o instanceof ASN1Sequence) {
24: return new ProtectedPart((ASN1Sequence) o);
25: }
26:
27: throw new IllegalArgumentException("Invalid object: "
28: + o.getClass().getName());
29: }
30:
31: public PKIHeader getHeader() {
32: return header;
33: }
34:
35: public PKIBody getBody() {
36: return body;
37: }
38:
39: /**
40: * <pre>
41: * ProtectedPart ::= SEQUENCE {
42: * header PKIHeader,
43: * body PKIBody
44: * }
45: * </pre>
46: * @return a basic ASN.1 object representation.
47: */
48: public DERObject toASN1Object() {
49: ASN1EncodableVector v = new ASN1EncodableVector();
50:
51: v.add(header);
52: v.add(body);
53:
54: return new DERSequence(v);
55: }
56: }
|