01: package org.bouncycastle.asn1.misc;
02:
03: import org.bouncycastle.asn1.*;
04:
05: public class IDEACBCPar extends ASN1Encodable {
06: ASN1OctetString iv;
07:
08: public static IDEACBCPar getInstance(Object o) {
09: if (o instanceof IDEACBCPar) {
10: return (IDEACBCPar) o;
11: } else if (o instanceof ASN1Sequence) {
12: return new IDEACBCPar((ASN1Sequence) o);
13: }
14:
15: throw new IllegalArgumentException(
16: "unknown object in IDEACBCPar factory");
17: }
18:
19: public IDEACBCPar(byte[] iv) {
20: this .iv = new DEROctetString(iv);
21: }
22:
23: public IDEACBCPar(ASN1Sequence seq) {
24: if (seq.size() == 1) {
25: iv = (ASN1OctetString) seq.getObjectAt(0);
26: } else {
27: iv = null;
28: }
29: }
30:
31: public byte[] getIV() {
32: if (iv != null) {
33: return iv.getOctets();
34: } else {
35: return null;
36: }
37: }
38:
39: /**
40: * Produce an object suitable for an ASN1OutputStream.
41: * <pre>
42: * IDEA-CBCPar ::= SEQUENCE {
43: * iv OCTET STRING OPTIONAL -- exactly 8 octets
44: * }
45: * </pre>
46: */
47: public DERObject toASN1Object() {
48: ASN1EncodableVector v = new ASN1EncodableVector();
49:
50: if (iv != null) {
51: v.add(iv);
52: }
53:
54: return new DERSequence(v);
55: }
56: }
|