01: package org.bouncycastle.asn1.smime;
02:
03: import org.bouncycastle.asn1.ASN1Encodable;
04: import org.bouncycastle.asn1.ASN1EncodableVector;
05: import org.bouncycastle.asn1.ASN1Sequence;
06: import org.bouncycastle.asn1.DEREncodable;
07: import org.bouncycastle.asn1.DERObject;
08: import org.bouncycastle.asn1.DERObjectIdentifier;
09: import org.bouncycastle.asn1.DERSequence;
10: import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
11: import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
12:
13: public class SMIMECapability extends ASN1Encodable {
14: /**
15: * general preferences
16: */
17: public static final DERObjectIdentifier preferSignedData = PKCSObjectIdentifiers.preferSignedData;
18: public static final DERObjectIdentifier canNotDecryptAny = PKCSObjectIdentifiers.canNotDecryptAny;
19: public static final DERObjectIdentifier sMIMECapabilitiesVersions = PKCSObjectIdentifiers.sMIMECapabilitiesVersions;
20:
21: /**
22: * encryption algorithms preferences
23: */
24: public static final DERObjectIdentifier dES_CBC = new DERObjectIdentifier(
25: "1.3.14.3.2.7");
26: public static final DERObjectIdentifier dES_EDE3_CBC = PKCSObjectIdentifiers.des_EDE3_CBC;
27: public static final DERObjectIdentifier rC2_CBC = PKCSObjectIdentifiers.RC2_CBC;
28: public static final DERObjectIdentifier aES128_CBC = NISTObjectIdentifiers.id_aes128_CBC;
29: public static final DERObjectIdentifier aES192_CBC = NISTObjectIdentifiers.id_aes192_CBC;
30: public static final DERObjectIdentifier aES256_CBC = NISTObjectIdentifiers.id_aes256_CBC;
31:
32: private DERObjectIdentifier capabilityID;
33: private DEREncodable parameters;
34:
35: public SMIMECapability(ASN1Sequence seq) {
36: capabilityID = (DERObjectIdentifier) seq.getObjectAt(0);
37:
38: if (seq.size() > 1) {
39: parameters = (DERObject) seq.getObjectAt(1);
40: }
41: }
42:
43: public SMIMECapability(DERObjectIdentifier capabilityID,
44: DEREncodable parameters) {
45: this .capabilityID = capabilityID;
46: this .parameters = parameters;
47: }
48:
49: public static SMIMECapability getInstance(Object obj) {
50: if (obj == null || obj instanceof SMIMECapability) {
51: return (SMIMECapability) obj;
52: }
53:
54: if (obj instanceof ASN1Sequence) {
55: return new SMIMECapability((ASN1Sequence) obj);
56: }
57:
58: throw new IllegalArgumentException("Invalid SMIMECapability");
59: }
60:
61: public DERObjectIdentifier getCapabilityID() {
62: return capabilityID;
63: }
64:
65: public DEREncodable getParameters() {
66: return parameters;
67: }
68:
69: /**
70: * Produce an object suitable for an ASN1OutputStream.
71: * <pre>
72: * SMIMECapability ::= SEQUENCE {
73: * capabilityID OBJECT IDENTIFIER,
74: * parameters ANY DEFINED BY capabilityID OPTIONAL
75: * }
76: * </pre>
77: */
78: public DERObject toASN1Object() {
79: ASN1EncodableVector v = new ASN1EncodableVector();
80:
81: v.add(capabilityID);
82:
83: if (parameters != null) {
84: v.add(parameters);
85: }
86:
87: return new DERSequence(v);
88: }
89: }
|