KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > DSAParameter


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1.x509;
19
20 import java.math.BigInteger JavaDoc;
21 import java.util.Enumeration JavaDoc;
22
23 import org.apache.geronimo.util.asn1.ASN1Encodable;
24 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
25 import org.apache.geronimo.util.asn1.ASN1Sequence;
26 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
27 import org.apache.geronimo.util.asn1.DERInteger;
28 import org.apache.geronimo.util.asn1.DERObject;
29 import org.apache.geronimo.util.asn1.DERSequence;
30
31 public class DSAParameter
32     extends ASN1Encodable
33 {
34     DERInteger p, q, g;
35
36     public static DSAParameter getInstance(
37         ASN1TaggedObject obj,
38         boolean explicit)
39     {
40         return getInstance(ASN1Sequence.getInstance(obj, explicit));
41     }
42
43     public static DSAParameter getInstance(
44         Object JavaDoc obj)
45     {
46         if(obj == null || obj instanceof DSAParameter)
47         {
48             return (DSAParameter)obj;
49         }
50
51         if(obj instanceof ASN1Sequence)
52         {
53             return new DSAParameter((ASN1Sequence)obj);
54         }
55
56         throw new IllegalArgumentException JavaDoc("Invalid DSAParameter: " + obj.getClass().getName());
57     }
58
59     public DSAParameter(
60         BigInteger JavaDoc p,
61         BigInteger JavaDoc q,
62         BigInteger JavaDoc g)
63     {
64         this.p = new DERInteger(p);
65         this.q = new DERInteger(q);
66         this.g = new DERInteger(g);
67     }
68
69     public DSAParameter(
70         ASN1Sequence seq)
71     {
72         Enumeration JavaDoc e = seq.getObjects();
73
74         p = (DERInteger)e.nextElement();
75         q = (DERInteger)e.nextElement();
76         g = (DERInteger)e.nextElement();
77     }
78
79     public BigInteger JavaDoc getP()
80     {
81         return p.getPositiveValue();
82     }
83
84     public BigInteger JavaDoc getQ()
85     {
86         return q.getPositiveValue();
87     }
88
89     public BigInteger JavaDoc getG()
90     {
91         return g.getPositiveValue();
92     }
93
94     public DERObject toASN1Object()
95     {
96         ASN1EncodableVector v = new ASN1EncodableVector();
97
98         v.add(p);
99         v.add(q);
100         v.add(g);
101
102         return new DERSequence(v);
103     }
104 }
105
Popular Tags