01: package org.bouncycastle.asn1.pkcs;
02:
03: import java.math.BigInteger;
04: import java.util.Enumeration;
05:
06: import org.bouncycastle.asn1.ASN1Encodable;
07: import org.bouncycastle.asn1.ASN1EncodableVector;
08: import org.bouncycastle.asn1.ASN1Sequence;
09: import org.bouncycastle.asn1.DERInteger;
10: import org.bouncycastle.asn1.DERObject;
11: import org.bouncycastle.asn1.DERSequence;
12:
13: public class DHParameter extends ASN1Encodable {
14: DERInteger p, g, l;
15:
16: public DHParameter(BigInteger p, BigInteger g, int l) {
17: this .p = new DERInteger(p);
18: this .g = new DERInteger(g);
19:
20: if (l != 0) {
21: this .l = new DERInteger(l);
22: } else {
23: this .l = null;
24: }
25: }
26:
27: public DHParameter(ASN1Sequence seq) {
28: Enumeration e = seq.getObjects();
29:
30: p = (DERInteger) e.nextElement();
31: g = (DERInteger) e.nextElement();
32:
33: if (e.hasMoreElements()) {
34: l = (DERInteger) e.nextElement();
35: } else {
36: l = null;
37: }
38: }
39:
40: public BigInteger getP() {
41: return p.getPositiveValue();
42: }
43:
44: public BigInteger getG() {
45: return g.getPositiveValue();
46: }
47:
48: public BigInteger getL() {
49: if (l == null) {
50: return null;
51: }
52:
53: return l.getPositiveValue();
54: }
55:
56: public DERObject toASN1Object() {
57: ASN1EncodableVector v = new ASN1EncodableVector();
58:
59: v.add(p);
60: v.add(g);
61:
62: if (this .getL() != null) {
63: v.add(l);
64: }
65:
66: return new DERSequence(v);
67: }
68: }
|