01: package org.bouncycastle.asn1.pkcs;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1Set;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.DERTaggedObject;
11:
12: public class SafeBag extends ASN1Encodable {
13: DERObjectIdentifier bagId;
14: DERObject bagValue;
15: ASN1Set bagAttributes;
16:
17: public SafeBag(DERObjectIdentifier oid, DERObject obj) {
18: this .bagId = oid;
19: this .bagValue = obj;
20: this .bagAttributes = null;
21: }
22:
23: public SafeBag(DERObjectIdentifier oid, DERObject obj,
24: ASN1Set bagAttributes) {
25: this .bagId = oid;
26: this .bagValue = obj;
27: this .bagAttributes = bagAttributes;
28: }
29:
30: public SafeBag(ASN1Sequence seq) {
31: this .bagId = (DERObjectIdentifier) seq.getObjectAt(0);
32: this .bagValue = ((DERTaggedObject) seq.getObjectAt(1))
33: .getObject();
34: if (seq.size() == 3) {
35: this .bagAttributes = (ASN1Set) seq.getObjectAt(2);
36: }
37: }
38:
39: public DERObjectIdentifier getBagId() {
40: return bagId;
41: }
42:
43: public DERObject getBagValue() {
44: return bagValue;
45: }
46:
47: public ASN1Set getBagAttributes() {
48: return bagAttributes;
49: }
50:
51: public DERObject toASN1Object() {
52: ASN1EncodableVector v = new ASN1EncodableVector();
53:
54: v.add(bagId);
55: v.add(new DERTaggedObject(0, bagValue));
56:
57: if (bagAttributes != null) {
58: v.add(bagAttributes);
59: }
60:
61: return new DERSequence(v);
62: }
63: }
|