initial checkin
[org.ibex.nanogoat.git] / src / org / bouncycastle / asn1 / x509 / DSAParameter.java
1 package org.bouncycastle.asn1.x509;
2
3 import java.math.BigInteger;
4 import java.util.*;
5
6 import org.bouncycastle.asn1.*;
7
8 public class DSAParameter
9     implements DEREncodable
10 {
11     DERInteger      p, q, g;
12
13     public static DSAParameter getInstance(
14         ASN1TaggedObject obj,
15         boolean          explicit)
16     {
17         return getInstance(ASN1Sequence.getInstance(obj, explicit));
18     }
19
20     public static DSAParameter getInstance(
21         Object obj)
22     {
23         if(obj == null || obj instanceof DSAParameter) 
24         {
25             return (DSAParameter)obj;
26         }
27         
28         if(obj instanceof ASN1Sequence) 
29         {
30             return new DSAParameter((ASN1Sequence)obj);
31         }
32         
33         throw new IllegalArgumentException("Invalid DSAParameter: " + obj.getClass().getName());
34     }
35
36     public DSAParameter(
37         BigInteger  p,
38         BigInteger  q,
39         BigInteger  g)
40     {
41         this.p = new DERInteger(p);
42         this.q = new DERInteger(q);
43         this.g = new DERInteger(g);
44     }
45
46     public DSAParameter(
47         ASN1Sequence  seq)
48     {
49         Enumeration     e = seq.getObjects();
50
51         p = (DERInteger)e.nextElement();
52         q = (DERInteger)e.nextElement();
53         g = (DERInteger)e.nextElement();
54     }
55
56     public BigInteger getP()
57     {
58         return p.getPositiveValue();
59     }
60
61     public BigInteger getQ()
62     {
63         return q.getPositiveValue();
64     }
65
66     public BigInteger getG()
67     {
68         return g.getPositiveValue();
69     }
70
71     public DERObject getDERObject()
72     {
73         DEREncodableVector  v = new DEREncodableVector();
74
75         v.add(p);
76         v.add(q);
77         v.add(g);
78
79         return new DERSequence(v);
80     }
81 }