Skip to content

Commit da57816

Browse files
committed
Improve CmpCertificate.GetInstance
1 parent c2f2046 commit da57816

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

crypto/src/asn1/cmp/CmpCertificate.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@ public static CmpCertificate GetInstance(object obj)
1313
return null;
1414
if (obj is CmpCertificate cmpCertificate)
1515
return cmpCertificate;
16+
if (obj is X509CertificateStructure certificate)
17+
return new CmpCertificate(certificate);
1618
if (obj is Asn1TaggedObject taggedObject)
1719
return new CmpCertificate(taggedObject);
18-
return new CmpCertificate(X509CertificateStructure.GetInstance(obj));
20+
21+
Asn1Object asn1Object = null;
22+
if (obj is IAsn1Convertible asn1Convertible)
23+
{
24+
asn1Object = asn1Convertible.ToAsn1Object();
25+
}
26+
else if (obj is byte[] bytes)
27+
{
28+
asn1Object = Asn1Object.FromByteArray(bytes);
29+
}
30+
31+
if (asn1Object is Asn1TaggedObject asn1TaggedObject)
32+
return new CmpCertificate(asn1TaggedObject);
33+
34+
return new CmpCertificate(X509CertificateStructure.GetInstance(asn1Object ?? obj));
1935
}
2036

2137
public static CmpCertificate GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)

0 commit comments

Comments
 (0)