KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > pkcs > DHParameter


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.pkcs;
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.DERInteger;
27 import org.apache.geronimo.util.asn1.DERObject;
28 import org.apache.geronimo.util.asn1.DERSequence;
29
30 public class DHParameter
31     extends ASN1Encodable
32 {
33     DERInteger p, g, l;
34
35     public DHParameter(
36         BigInteger JavaDoc p,
37         BigInteger JavaDoc g,
38         int l)
39     {
40         this.p = new DERInteger(p);
41         this.g = new DERInteger(g);
42
43         if (l != 0)
44         {
45             this.l = new DERInteger(l);
46         }
47         else
48         {
49             this.l = null;
50         }
51     }
52
53     public DHParameter(
54         ASN1Sequence seq)
55     {
56         Enumeration JavaDoc e = seq.getObjects();
57
58         p = (DERInteger)e.nextElement();
59         g = (DERInteger)e.nextElement();
60
61         if (e.hasMoreElements())
62         {
63             l = (DERInteger)e.nextElement();
64         }
65         else
66         {
67             l = null;
68         }
69     }
70
71     public BigInteger JavaDoc getP()
72     {
73         return p.getPositiveValue();
74     }
75
76     public BigInteger JavaDoc getG()
77     {
78         return g.getPositiveValue();
79     }
80
81     public BigInteger JavaDoc getL()
82     {
83         if (l == null)
84         {
85             return null;
86         }
87
88         return l.getPositiveValue();
89     }
90
91     public DERObject toASN1Object()
92     {
93         ASN1EncodableVector v = new ASN1EncodableVector();
94
95         v.add(p);
96         v.add(g);
97
98         if (this.getL() != null)
99         {
100             v.add(l);
101         }
102
103         return new DERSequence(v);
104     }
105 }
106
Popular Tags