1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.math.BigInteger ; 21 import java.util.Enumeration ; 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 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 ("Invalid DSAParameter: " + obj.getClass().getName()); 57 } 58 59 public DSAParameter( 60 BigInteger p, 61 BigInteger q, 62 BigInteger 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 e = seq.getObjects(); 73 74 p = (DERInteger)e.nextElement(); 75 q = (DERInteger)e.nextElement(); 76 g = (DERInteger)e.nextElement(); 77 } 78 79 public BigInteger getP() 80 { 81 return p.getPositiveValue(); 82 } 83 84 public BigInteger getQ() 85 { 86 return q.getPositiveValue(); 87 } 88 89 public BigInteger 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 |