01: package org.bouncycastle.asn1.x509;
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.ASN1TaggedObject;
10: import org.bouncycastle.asn1.DERInteger;
11: import org.bouncycastle.asn1.DERObject;
12: import org.bouncycastle.asn1.DERSequence;
13:
14: public class DSAParameter extends ASN1Encodable {
15: DERInteger p, q, g;
16:
17: public static DSAParameter getInstance(ASN1TaggedObject obj,
18: boolean explicit) {
19: return getInstance(ASN1Sequence.getInstance(obj, explicit));
20: }
21:
22: public static DSAParameter getInstance(Object obj) {
23: if (obj == null || obj instanceof DSAParameter) {
24: return (DSAParameter) obj;
25: }
26:
27: if (obj instanceof ASN1Sequence) {
28: return new DSAParameter((ASN1Sequence) obj);
29: }
30:
31: throw new IllegalArgumentException("Invalid DSAParameter: "
32: + obj.getClass().getName());
33: }
34:
35: public DSAParameter(BigInteger p, BigInteger q, BigInteger g) {
36: this .p = new DERInteger(p);
37: this .q = new DERInteger(q);
38: this .g = new DERInteger(g);
39: }
40:
41: public DSAParameter(ASN1Sequence seq) {
42: if (seq.size() != 3) {
43: throw new IllegalArgumentException("Bad sequence size: "
44: + seq.size());
45: }
46:
47: Enumeration e = seq.getObjects();
48:
49: p = DERInteger.getInstance(e.nextElement());
50: q = DERInteger.getInstance(e.nextElement());
51: g = DERInteger.getInstance(e.nextElement());
52: }
53:
54: public BigInteger getP() {
55: return p.getPositiveValue();
56: }
57:
58: public BigInteger getQ() {
59: return q.getPositiveValue();
60: }
61:
62: public BigInteger getG() {
63: return g.getPositiveValue();
64: }
65:
66: public DERObject toASN1Object() {
67: ASN1EncodableVector v = new ASN1EncodableVector();
68:
69: v.add(p);
70: v.add(q);
71: v.add(g);
72:
73: return new DERSequence(v);
74: }
75: }
|