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