001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.crypto.asn1.x509;
019
020 import java.math.BigInteger;
021 import java.util.Enumeration;
022
023 import org.apache.geronimo.crypto.asn1.ASN1Encodable;
024 import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
025 import org.apache.geronimo.crypto.asn1.ASN1Sequence;
026 import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
027 import org.apache.geronimo.crypto.asn1.DERInteger;
028 import org.apache.geronimo.crypto.asn1.DERObject;
029 import org.apache.geronimo.crypto.asn1.DERSequence;
030
031 public class DSAParameter
032 extends ASN1Encodable
033 {
034 DERInteger p, q, g;
035
036 public static DSAParameter getInstance(
037 ASN1TaggedObject obj,
038 boolean explicit)
039 {
040 return getInstance(ASN1Sequence.getInstance(obj, explicit));
041 }
042
043 public static DSAParameter getInstance(
044 Object obj)
045 {
046 if(obj == null || obj instanceof DSAParameter)
047 {
048 return (DSAParameter)obj;
049 }
050
051 if(obj instanceof ASN1Sequence)
052 {
053 return new DSAParameter((ASN1Sequence)obj);
054 }
055
056 throw new IllegalArgumentException("Invalid DSAParameter: " + obj.getClass().getName());
057 }
058
059 public DSAParameter(
060 BigInteger p,
061 BigInteger q,
062 BigInteger g)
063 {
064 this.p = new DERInteger(p);
065 this.q = new DERInteger(q);
066 this.g = new DERInteger(g);
067 }
068
069 public DSAParameter(
070 ASN1Sequence seq)
071 {
072 Enumeration e = seq.getObjects();
073
074 p = (DERInteger)e.nextElement();
075 q = (DERInteger)e.nextElement();
076 g = (DERInteger)e.nextElement();
077 }
078
079 public BigInteger getP()
080 {
081 return p.getPositiveValue();
082 }
083
084 public BigInteger getQ()
085 {
086 return q.getPositiveValue();
087 }
088
089 public BigInteger getG()
090 {
091 return g.getPositiveValue();
092 }
093
094 public DERObject toASN1Object()
095 {
096 ASN1EncodableVector v = new ASN1EncodableVector();
097
098 v.add(p);
099 v.add(q);
100 v.add(g);
101
102 return new DERSequence(v);
103 }
104 }