01: package org.bouncycastle.asn1.cms;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.ASN1TaggedObject;
07: import org.bouncycastle.asn1.BERSequence;
08: import org.bouncycastle.asn1.DERInteger;
09: import org.bouncycastle.asn1.DERObject;
10: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
11:
12: /**
13: * RFC 3274 - CMS Compressed Data.
14: * <pre>
15: * CompressedData ::= SEQUENCE {
16: * version CMSVersion,
17: * compressionAlgorithm CompressionAlgorithmIdentifier,
18: * encapContentInfo EncapsulatedContentInfo
19: * }
20: * </pre>
21: */
22: public class CompressedData extends ASN1Encodable {
23: private DERInteger version;
24: private AlgorithmIdentifier compressionAlgorithm;
25: private ContentInfo encapContentInfo;
26:
27: public CompressedData(AlgorithmIdentifier compressionAlgorithm,
28: ContentInfo encapContentInfo) {
29: this .version = new DERInteger(0);
30: this .compressionAlgorithm = compressionAlgorithm;
31: this .encapContentInfo = encapContentInfo;
32: }
33:
34: public CompressedData(ASN1Sequence seq) {
35: this .version = (DERInteger) seq.getObjectAt(0);
36: this .compressionAlgorithm = AlgorithmIdentifier.getInstance(seq
37: .getObjectAt(1));
38: this .encapContentInfo = ContentInfo.getInstance(seq
39: .getObjectAt(2));
40:
41: }
42:
43: /**
44: * return a CompressedData object from a tagged object.
45: *
46: * @param _ato the tagged object holding the object we want.
47: * @param _explicit true if the object is meant to be explicitly
48: * tagged false otherwise.
49: * @exception IllegalArgumentException if the object held by the
50: * tagged object cannot be converted.
51: */
52: public static CompressedData getInstance(ASN1TaggedObject _ato,
53: boolean _explicit) {
54: return getInstance(ASN1Sequence.getInstance(_ato, _explicit));
55: }
56:
57: /**
58: * return a CompressedData object from the given object.
59: *
60: * @param _obj the object we want converted.
61: * @exception IllegalArgumentException if the object cannot be converted.
62: */
63: public static CompressedData getInstance(Object _obj) {
64: if (_obj == null || _obj instanceof CompressedData) {
65: return (CompressedData) _obj;
66: }
67:
68: if (_obj instanceof ASN1Sequence) {
69: return new CompressedData((ASN1Sequence) _obj);
70: }
71:
72: throw new IllegalArgumentException("Invalid CompressedData: "
73: + _obj.getClass().getName());
74: }
75:
76: public DERInteger getVersion() {
77: return version;
78: }
79:
80: public AlgorithmIdentifier getCompressionAlgorithmIdentifier() {
81: return compressionAlgorithm;
82: }
83:
84: public ContentInfo getEncapContentInfo() {
85: return encapContentInfo;
86: }
87:
88: public DERObject toASN1Object() {
89: ASN1EncodableVector v = new ASN1EncodableVector();
90:
91: v.add(version);
92: v.add(compressionAlgorithm);
93: v.add(encapContentInfo);
94:
95: return new BERSequence(v);
96: }
97: }
|