3
3
import org .bouncycastle .asn1 .ASN1Choice ;
4
4
import org .bouncycastle .asn1 .ASN1Object ;
5
5
import org .bouncycastle .asn1 .ASN1Primitive ;
6
- import org .bouncycastle .asn1 .ASN1Sequence ;
7
6
import org .bouncycastle .asn1 .ASN1TaggedObject ;
7
+ import org .bouncycastle .asn1 .ASN1Util ;
8
8
import org .bouncycastle .asn1 .DERTaggedObject ;
9
9
10
10
/**
@@ -37,9 +37,14 @@ public static KeyAgreeRecipientIdentifier getInstance(
37
37
ASN1TaggedObject obj ,
38
38
boolean explicit )
39
39
{
40
- return getInstance (ASN1Sequence .getInstance (obj , explicit ));
40
+ if (!explicit )
41
+ {
42
+ throw new IllegalArgumentException ("choice item must be explicitly tagged" );
43
+ }
44
+
45
+ return getInstance (obj .getExplicitBaseObject ());
41
46
}
42
-
47
+
43
48
/**
44
49
* Return an KeyAgreeRecipientIdentifier object from the given object.
45
50
* <p>
@@ -62,19 +67,20 @@ public static KeyAgreeRecipientIdentifier getInstance(
62
67
{
63
68
return (KeyAgreeRecipientIdentifier )obj ;
64
69
}
65
-
66
- if (obj instanceof ASN1Sequence )
67
- {
68
- return new KeyAgreeRecipientIdentifier (IssuerAndSerialNumber .getInstance (obj ));
69
- }
70
-
71
- if (obj instanceof ASN1TaggedObject && ((ASN1TaggedObject )obj ).getTagNo () == 0 )
70
+
71
+ if (obj instanceof ASN1TaggedObject )
72
72
{
73
- return new KeyAgreeRecipientIdentifier (RecipientKeyIdentifier .getInstance (
74
- (ASN1TaggedObject )obj , false ));
73
+ ASN1TaggedObject taggedObject = (ASN1TaggedObject )obj ;
74
+ if (taggedObject .hasContextTag (0 ))
75
+ {
76
+ return new KeyAgreeRecipientIdentifier (RecipientKeyIdentifier .getInstance (taggedObject , false ));
77
+ }
78
+
79
+ throw new IllegalArgumentException ("Invalid KeyAgreeRecipientIdentifier tag: "
80
+ + ASN1Util .getTagText (taggedObject ));
75
81
}
76
-
77
- throw new IllegalArgumentException ( "Invalid KeyAgreeRecipientIdentifier: " + obj . getClass (). getName ( ));
82
+
83
+ return new KeyAgreeRecipientIdentifier ( IssuerAndSerialNumber . getInstance ( obj ));
78
84
}
79
85
80
86
public KeyAgreeRecipientIdentifier (
0 commit comments