1 17 18 package org.apache.geronimo.util.asn1.pkcs; 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.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 p, 37 BigInteger 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 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 getP() 72 { 73 return p.getPositiveValue(); 74 } 75 76 public BigInteger getG() 77 { 78 return g.getPositiveValue(); 79 } 80 81 public BigInteger 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 |