summary refs log tree commit diff
path: root/crypto/src/asn1/cms/Evidence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/asn1/cms/Evidence.cs')
-rw-r--r--crypto/src/asn1/cms/Evidence.cs88
1 files changed, 45 insertions, 43 deletions
diff --git a/crypto/src/asn1/cms/Evidence.cs b/crypto/src/asn1/cms/Evidence.cs
index 54d498cb9..19dab50c2 100644
--- a/crypto/src/asn1/cms/Evidence.cs
+++ b/crypto/src/asn1/cms/Evidence.cs
@@ -1,5 +1,6 @@
 using System;
 
+using Org.BouncyCastle.Asn1.Tsp;
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.Cms
@@ -7,67 +8,68 @@ namespace Org.BouncyCastle.Asn1.Cms
 	public class Evidence
 		: Asn1Encodable, IAsn1Choice
 	{
-		private TimeStampTokenEvidence tstEvidence;
-        private Asn1Sequence otherEvidence;
+        public static Evidence GetInstance(object obj)
+        {
+            if (obj == null)
+                return null;
+            if (obj is Evidence evidence)
+                return evidence;
+            if (obj is Asn1TaggedObject taggedObject)
+                return new Evidence(Asn1Utilities.CheckTagClass(taggedObject, Asn1Tags.ContextSpecific));
+
+            throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), nameof(obj));
+        }
 
-		public Evidence(TimeStampTokenEvidence tstEvidence)
+        public static Evidence GetInstance(Asn1TaggedObject obj, bool isExplicit)
+        {
+            return Asn1Utilities.GetInstanceFromChoice(obj, isExplicit, GetInstance);
+        }
+
+        private readonly TimeStampTokenEvidence m_tstEvidence;
+        private readonly EvidenceRecord m_ersEvidence;
+        private readonly Asn1Sequence m_otherEvidence;
+
+        public Evidence(TimeStampTokenEvidence tstEvidence)
 		{
-			this.tstEvidence = tstEvidence;
+			m_tstEvidence = tstEvidence;
 		}
 
-		private Evidence(Asn1TaggedObject tagged)
+        public Evidence(EvidenceRecord ersEvidence)
+        {
+            m_ersEvidence = ersEvidence;
+        }
+
+        private Evidence(Asn1TaggedObject tagged)
 		{
             if (tagged.TagNo == 0)
             {
-                this.tstEvidence = TimeStampTokenEvidence.GetInstance(tagged, false);
+                m_tstEvidence = TimeStampTokenEvidence.GetInstance(tagged, false);
+            }
+            else if (tagged.TagNo == 1)
+            {
+                m_ersEvidence = EvidenceRecord.GetInstance(tagged, false);
             }
-            //else if (tagged.TagNo == 1)
-            //{
-            //    this.ersEvidence = EvidenceRecord.GetInstance(tagged, false);
-            //}
             else if (tagged.TagNo == 2)
             {
-                this.otherEvidence = Asn1Sequence.GetInstance(tagged, false);
+                m_otherEvidence = Asn1Sequence.GetInstance(tagged, false);
             }
             else
             {
-                throw new ArgumentException("unknown tag in Evidence", "tagged");
+                throw new ArgumentException("unknown tag in Evidence", nameof(tagged));
             }
         }
 
-		public static Evidence GetInstance(object obj)
-		{
-			if (obj is Evidence evidence)
-				return evidence;
-
-			if (obj is Asn1TaggedObject taggedObject)
-				return new Evidence(Asn1Utilities.CheckTagClass(taggedObject, Asn1Tags.ContextSpecific));
+        public virtual TimeStampTokenEvidence TstEvidence => m_tstEvidence;
 
-			throw new ArgumentException("Unknown object in GetInstance: " + Platform.GetTypeName(obj), "obj");
-		}
+        public virtual EvidenceRecord ErsEvidence => m_ersEvidence;
 
-        public static Evidence GetInstance(Asn1TaggedObject obj, bool isExplicit)
+        public override Asn1Object ToAsn1Object()
         {
-            return Asn1Utilities.GetInstanceFromChoice(obj, isExplicit, GetInstance);
+            if (m_tstEvidence != null)
+                return new DerTaggedObject(false, 0, m_tstEvidence);
+            if (m_ersEvidence != null)
+                return new DerTaggedObject(false, 1, m_ersEvidence);
+            return new DerTaggedObject(false, 2, m_otherEvidence);
         }
-
-		public virtual TimeStampTokenEvidence TstEvidence
-		{
-			get { return tstEvidence; }
-		}
-
-        //public EvidenceRecord ErsEvidence
-        //{
-        //    get { return ersEvidence; }
-        //}
-
-		public override Asn1Object ToAsn1Object()
-		{
-			if (tstEvidence != null)
-				return new DerTaggedObject(false, 0, tstEvidence);
-            //if (ersEvidence != null)
-            //    return new DerTaggedObject(false, 1, ersEvidence);
-            return new DerTaggedObject(false, 2, otherEvidence);
-		}
-	}
+    }
 }