summary refs log tree commit diff
path: root/crypto/src/asn1/cms/Attributes.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cms/Attributes.cs')
-rw-r--r--crypto/src/asn1/cms/Attributes.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/asn1/cms/Attributes.cs b/crypto/src/asn1/cms/Attributes.cs
index 41018453d..cdcada6dc 100644
--- a/crypto/src/asn1/cms/Attributes.cs
+++ b/crypto/src/asn1/cms/Attributes.cs
@@ -1,3 +1,5 @@
+using System;
+
 namespace Org.BouncyCastle.Asn1.Cms
 {
     public class Attributes
@@ -17,6 +19,21 @@ namespace Org.BouncyCastle.Asn1.Cms
             return new Attributes(Asn1Set.GetInstance(taggedObject, declaredExplicit));
         }
 
+        public static Attributes GetOptional(Asn1Encodable element)
+        {
+            if (element == null)
+                throw new ArgumentNullException(nameof(element));
+
+            if (element is Attributes attributes)
+                return attributes;
+
+            Asn1Set asn1Set = Asn1Set.GetOptional(element);
+            if (asn1Set != null)
+                return new Attributes(asn1Set);
+
+            return null;
+        }
+
         private readonly Asn1Set m_attributes;
 
         private Attributes(Asn1Set attributes)