01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.crypto.asn1.x509;
17:
18: import java.math.BigInteger;
19: import java.util.Enumeration;
20:
21: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
22: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
23: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
24: import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
25: import org.apache.geronimo.crypto.asn1.DERInteger;
26: import org.apache.geronimo.crypto.asn1.DERObject;
27: import org.apache.geronimo.crypto.asn1.DERSequence;
28:
29: public class DSAParameter extends ASN1Encodable {
30: DERInteger p, q, g;
31:
32: public static DSAParameter getInstance(ASN1TaggedObject obj,
33: boolean explicit) {
34: return getInstance(ASN1Sequence.getInstance(obj, explicit));
35: }
36:
37: public static DSAParameter getInstance(Object obj) {
38: if (obj == null || obj instanceof DSAParameter) {
39: return (DSAParameter) obj;
40: }
41:
42: if (obj instanceof ASN1Sequence) {
43: return new DSAParameter((ASN1Sequence) obj);
44: }
45:
46: throw new IllegalArgumentException("Invalid DSAParameter: "
47: + obj.getClass().getName());
48: }
49:
50: public DSAParameter(BigInteger p, BigInteger q, BigInteger g) {
51: this .p = new DERInteger(p);
52: this .q = new DERInteger(q);
53: this .g = new DERInteger(g);
54: }
55:
56: public DSAParameter(ASN1Sequence seq) {
57: Enumeration e = seq.getObjects();
58:
59: p = (DERInteger) e.nextElement();
60: q = (DERInteger) e.nextElement();
61: g = (DERInteger) e.nextElement();
62: }
63:
64: public BigInteger getP() {
65: return p.getPositiveValue();
66: }
67:
68: public BigInteger getQ() {
69: return q.getPositiveValue();
70: }
71:
72: public BigInteger getG() {
73: return g.getPositiveValue();
74: }
75:
76: public DERObject toASN1Object() {
77: ASN1EncodableVector v = new ASN1EncodableVector();
78:
79: v.add(p);
80: v.add(q);
81: v.add(g);
82:
83: return new DERSequence(v);
84: }
85: }
|