1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import org.apache.geronimo.util.asn1.ASN1Encodable; 21 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 22 import org.apache.geronimo.util.asn1.ASN1Sequence; 23 import org.apache.geronimo.util.asn1.ASN1TaggedObject; 24 import org.apache.geronimo.util.asn1.DEREncodable; 25 import org.apache.geronimo.util.asn1.DERObject; 26 import org.apache.geronimo.util.asn1.DERObjectIdentifier; 27 import org.apache.geronimo.util.asn1.DERSequence; 28 29 public class AlgorithmIdentifier 30 extends ASN1Encodable 31 { 32 private DERObjectIdentifier objectId; 33 private DEREncodable parameters; 34 private boolean parametersDefined = false; 35 36 public static AlgorithmIdentifier getInstance( 37 ASN1TaggedObject obj, 38 boolean explicit) 39 { 40 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 41 } 42 43 public static AlgorithmIdentifier getInstance( 44 Object obj) 45 { 46 if (obj instanceof AlgorithmIdentifier) 47 { 48 return (AlgorithmIdentifier)obj; 49 } 50 51 if (obj instanceof DERObjectIdentifier) 52 { 53 return new AlgorithmIdentifier((DERObjectIdentifier)obj); 54 } 55 56 if (obj instanceof String ) 57 { 58 return new AlgorithmIdentifier((String )obj); 59 } 60 61 if (obj instanceof ASN1Sequence) 62 { 63 return new AlgorithmIdentifier((ASN1Sequence)obj); 64 } 65 66 throw new IllegalArgumentException ("unknown object in factory"); 67 } 68 69 public AlgorithmIdentifier( 70 DERObjectIdentifier objectId) 71 { 72 this.objectId = objectId; 73 } 74 75 public AlgorithmIdentifier( 76 String objectId) 77 { 78 this.objectId = new DERObjectIdentifier(objectId); 79 } 80 81 public AlgorithmIdentifier( 82 DERObjectIdentifier objectId, 83 DEREncodable parameters) 84 { 85 parametersDefined = true; 86 this.objectId = objectId; 87 this.parameters = parameters; 88 } 89 90 public AlgorithmIdentifier( 91 ASN1Sequence seq) 92 { 93 objectId = (DERObjectIdentifier)seq.getObjectAt(0); 94 95 if (seq.size() == 2) 96 { 97 parametersDefined = true; 98 parameters = seq.getObjectAt(1); 99 } 100 else 101 { 102 parameters = null; 103 } 104 } 105 106 public DERObjectIdentifier getObjectId() 107 { 108 return objectId; 109 } 110 111 public DEREncodable getParameters() 112 { 113 return parameters; 114 } 115 116 124 public DERObject toASN1Object() 125 { 126 ASN1EncodableVector v = new ASN1EncodableVector(); 127 128 v.add(objectId); 129 130 if (parametersDefined) 131 { 132 v.add(parameters); 133 } 134 135 return new DERSequence(v); 136 } 137 } 138 | Popular Tags |