View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.geronimo.util.asn1.x509;
20  
21  import java.math.BigInteger;
22  import java.util.Enumeration;
23  
24  import org.apache.geronimo.util.asn1.ASN1Encodable;
25  import org.apache.geronimo.util.asn1.ASN1EncodableVector;
26  import org.apache.geronimo.util.asn1.ASN1Sequence;
27  import org.apache.geronimo.util.asn1.ASN1TaggedObject;
28  import org.apache.geronimo.util.asn1.DERInteger;
29  import org.apache.geronimo.util.asn1.DERObject;
30  import org.apache.geronimo.util.asn1.DERSequence;
31  
32  public class DSAParameter
33      extends ASN1Encodable
34  {
35      DERInteger      p, q, g;
36  
37      public static DSAParameter getInstance(
38          ASN1TaggedObject obj,
39          boolean          explicit)
40      {
41          return getInstance(ASN1Sequence.getInstance(obj, explicit));
42      }
43  
44      public static DSAParameter getInstance(
45          Object obj)
46      {
47          if(obj == null || obj instanceof DSAParameter)
48          {
49              return (DSAParameter)obj;
50          }
51  
52          if(obj instanceof ASN1Sequence)
53          {
54              return new DSAParameter((ASN1Sequence)obj);
55          }
56  
57          throw new IllegalArgumentException("Invalid DSAParameter: " + obj.getClass().getName());
58      }
59  
60      public DSAParameter(
61          BigInteger  p,
62          BigInteger  q,
63          BigInteger  g)
64      {
65          this.p = new DERInteger(p);
66          this.q = new DERInteger(q);
67          this.g = new DERInteger(g);
68      }
69  
70      public DSAParameter(
71          ASN1Sequence  seq)
72      {
73          Enumeration     e = seq.getObjects();
74  
75          p = (DERInteger)e.nextElement();
76          q = (DERInteger)e.nextElement();
77          g = (DERInteger)e.nextElement();
78      }
79  
80      public BigInteger getP()
81      {
82          return p.getPositiveValue();
83      }
84  
85      public BigInteger getQ()
86      {
87          return q.getPositiveValue();
88      }
89  
90      public BigInteger getG()
91      {
92          return g.getPositiveValue();
93      }
94  
95      public DERObject toASN1Object()
96      {
97          ASN1EncodableVector  v = new ASN1EncodableVector();
98  
99          v.add(p);
100         v.add(q);
101         v.add(g);
102 
103         return new DERSequence(v);
104     }
105 }