1 files changed, 19 insertions, 0 deletions
diff --git a/crypto/src/asn1/Asn1Utilities.cs b/crypto/src/asn1/Asn1Utilities.cs
index 5605d4c54..6ccdfc43a 100644
--- a/crypto/src/asn1/Asn1Utilities.cs
+++ b/crypto/src/asn1/Asn1Utilities.cs
@@ -1,6 +1,8 @@
using System;
using System.IO;
+using Org.BouncyCastle.Utilities;
+
namespace Org.BouncyCastle.Asn1
{
public abstract class Asn1Utilities
@@ -29,6 +31,23 @@ namespace Org.BouncyCastle.Asn1
}
+ internal static TChoice GetInstanceFromChoice<TChoice>(Asn1TaggedObject taggedObject, bool declaredExplicit,
+ Func<object, TChoice> constructor)
+ where TChoice : Asn1Encodable, IAsn1Choice
+ {
+ if (!declaredExplicit)
+ {
+ var message = string.Format(
+ "Implicit tagging cannot be used with untagged choice type {0} (X.680 30.6, 30.8).",
+ Platform.GetTypeName(typeof(TChoice)));
+
+ throw new ArgumentException(message, nameof(declaredExplicit));
+ }
+
+ return constructor(taggedObject.GetExplicitBaseObject());
+ }
+
+
internal static string GetTagText(Asn1Tag tag)
{
return GetTagText(tag.TagClass, tag.TagNo);
|