01: package org.bouncycastle.asn1.x9;
02:
03: import java.util.Enumeration;
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.DERObject;
10: import org.bouncycastle.asn1.DERSequence;
11: import org.bouncycastle.asn1.DERTaggedObject;
12:
13: /**
14: * ANS.1 def for Diffie-Hellman key exchange OtherInfo structure. See
15: * RFC 2631, or X9.42, for further details.
16: */
17: public class OtherInfo extends ASN1Encodable {
18: private KeySpecificInfo keyInfo;
19: private ASN1OctetString partyAInfo;
20: private ASN1OctetString suppPubInfo;
21:
22: public OtherInfo(KeySpecificInfo keyInfo,
23: ASN1OctetString partyAInfo, ASN1OctetString suppPubInfo) {
24: this .keyInfo = keyInfo;
25: this .partyAInfo = partyAInfo;
26: this .suppPubInfo = suppPubInfo;
27: }
28:
29: public OtherInfo(ASN1Sequence seq) {
30: Enumeration e = seq.getObjects();
31:
32: keyInfo = new KeySpecificInfo((ASN1Sequence) e.nextElement());
33:
34: while (e.hasMoreElements()) {
35: DERTaggedObject o = (DERTaggedObject) e.nextElement();
36:
37: if (o.getTagNo() == 0) {
38: partyAInfo = (ASN1OctetString) o.getObject();
39: } else if (o.getTagNo() == 2) {
40: suppPubInfo = (ASN1OctetString) o.getObject();
41: }
42: }
43: }
44:
45: public KeySpecificInfo getKeyInfo() {
46: return keyInfo;
47: }
48:
49: public ASN1OctetString getPartyAInfo() {
50: return partyAInfo;
51: }
52:
53: public ASN1OctetString getSuppPubInfo() {
54: return suppPubInfo;
55: }
56:
57: /**
58: * Produce an object suitable for an ASN1OutputStream.
59: * <pre>
60: * OtherInfo ::= SEQUENCE {
61: * keyInfo KeySpecificInfo,
62: * partyAInfo [0] OCTET STRING OPTIONAL,
63: * suppPubInfo [2] OCTET STRING
64: * }
65: * </pre>
66: */
67: public DERObject toASN1Object() {
68: ASN1EncodableVector v = new ASN1EncodableVector();
69:
70: v.add(keyInfo);
71:
72: if (partyAInfo != null) {
73: v.add(new DERTaggedObject(0, partyAInfo));
74: }
75:
76: v.add(new DERTaggedObject(2, suppPubInfo));
77:
78: return new DERSequence(v);
79: }
80: }
|