01: package org.bouncycastle.asn1.pkcs;
02:
03: import java.math.BigInteger;
04:
05: import org.bouncycastle.asn1.ASN1Encodable;
06: import org.bouncycastle.asn1.ASN1EncodableVector;
07: import org.bouncycastle.asn1.ASN1OctetString;
08: import org.bouncycastle.asn1.ASN1Sequence;
09: import org.bouncycastle.asn1.DERInteger;
10: import org.bouncycastle.asn1.DERObject;
11: import org.bouncycastle.asn1.DEROctetString;
12: import org.bouncycastle.asn1.DERSequence;
13:
14: public class RC2CBCParameter extends ASN1Encodable {
15: DERInteger version;
16: ASN1OctetString iv;
17:
18: public static RC2CBCParameter getInstance(Object o) {
19: if (o instanceof ASN1Sequence) {
20: return new RC2CBCParameter((ASN1Sequence) o);
21: }
22:
23: throw new IllegalArgumentException(
24: "unknown object in RC2CBCParameter factory");
25: }
26:
27: public RC2CBCParameter(byte[] iv) {
28: this .version = null;
29: this .iv = new DEROctetString(iv);
30: }
31:
32: public RC2CBCParameter(int parameterVersion, byte[] iv) {
33: this .version = new DERInteger(parameterVersion);
34: this .iv = new DEROctetString(iv);
35: }
36:
37: public RC2CBCParameter(ASN1Sequence seq) {
38: if (seq.size() == 1) {
39: version = null;
40: iv = (ASN1OctetString) seq.getObjectAt(0);
41: } else {
42: version = (DERInteger) seq.getObjectAt(0);
43: iv = (ASN1OctetString) seq.getObjectAt(1);
44: }
45: }
46:
47: public BigInteger getRC2ParameterVersion() {
48: if (version == null) {
49: return null;
50: }
51:
52: return version.getValue();
53: }
54:
55: public byte[] getIV() {
56: return iv.getOctets();
57: }
58:
59: public DERObject toASN1Object() {
60: ASN1EncodableVector v = new ASN1EncodableVector();
61:
62: if (version != null) {
63: v.add(version);
64: }
65:
66: v.add(iv);
67:
68: return new DERSequence(v);
69: }
70: }
|