summary refs log tree commit diff
path: root/crypto/src/asn1/tsp/MessageImprint.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-07-18 18:29:42 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-07-18 18:29:42 +0700
commit8119dba914a3aa08cd1ce7b24b757e95269d3aaf (patch)
tree26a50fe08c3d9aff219776675a0dd015f38f38e2 /crypto/src/asn1/tsp/MessageImprint.cs
parentCustom encoding classes for tagged objects (diff)
downloadBouncyCastle.NET-ed25519-8119dba914a3aa08cd1ce7b24b757e95269d3aaf.tar.xz
Asn1.Tsp updates from bc-java
Diffstat (limited to 'crypto/src/asn1/tsp/MessageImprint.cs')
-rw-r--r--crypto/src/asn1/tsp/MessageImprint.cs44
1 files changed, 20 insertions, 24 deletions
diff --git a/crypto/src/asn1/tsp/MessageImprint.cs b/crypto/src/asn1/tsp/MessageImprint.cs
index cb728629c..0be856048 100644
--- a/crypto/src/asn1/tsp/MessageImprint.cs
+++ b/crypto/src/asn1/tsp/MessageImprint.cs
@@ -8,46 +8,42 @@ namespace Org.BouncyCastle.Asn1.Tsp
 	public class MessageImprint
 		: Asn1Encodable
 	{
-		private readonly AlgorithmIdentifier	hashAlgorithm;
-		private readonly byte[]					hashedMessage;
-
         public static MessageImprint GetInstance(object obj)
         {
-            if (obj is MessageImprint)
-                return (MessageImprint)obj;
             if (obj == null)
                 return null;
+            if (obj is MessageImprint messageImprint)
+                return messageImprint;
             return new MessageImprint(Asn1Sequence.GetInstance(obj));
         }
 
-        private MessageImprint(
-			Asn1Sequence seq)
+		public static MessageImprint GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
 		{
-			if (seq.Count != 2)
-				throw new ArgumentException("Wrong number of elements in sequence", "seq");
+            return new MessageImprint(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
+        }
 
-			this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
-			this.hashedMessage = Asn1OctetString.GetInstance(seq[1]).GetOctets();
-		}
+        private readonly AlgorithmIdentifier m_hashAlgorithm;
+        private readonly byte[] m_hashedMessage;
 
-		public MessageImprint(
-			AlgorithmIdentifier	hashAlgorithm,
-			byte[]				hashedMessage)
+        private MessageImprint(Asn1Sequence seq)
 		{
-			this.hashAlgorithm = hashAlgorithm;
-			this.hashedMessage = hashedMessage;
-		}
+			if (seq.Count != 2)
+				throw new ArgumentException("Wrong number of elements in sequence", nameof(seq));
 
-		public AlgorithmIdentifier HashAlgorithm
-		{
-			get { return hashAlgorithm; }
+			m_hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]);
+			m_hashedMessage = Asn1OctetString.GetInstance(seq[1]).GetOctets();
 		}
 
-		public byte[] GetHashedMessage()
+		public MessageImprint(AlgorithmIdentifier hashAlgorithm, byte[] hashedMessage)
 		{
-			return hashedMessage;
+			m_hashAlgorithm = hashAlgorithm;
+			m_hashedMessage = hashedMessage;
 		}
 
+		public AlgorithmIdentifier HashAlgorithm => m_hashAlgorithm;
+
+		public byte[] GetHashedMessage() => m_hashedMessage;
+
 		/**
 		 * <pre>
 		 *    MessageImprint ::= SEQUENCE  {
@@ -57,7 +53,7 @@ namespace Org.BouncyCastle.Asn1.Tsp
 		 */
 		public override Asn1Object ToAsn1Object()
 		{
-			return new DerSequence(hashAlgorithm, new DerOctetString(hashedMessage));
+			return new DerSequence(m_hashAlgorithm, new DerOctetString(m_hashedMessage));
 		}
 	}
 }