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