summary refs log tree commit diff
path: root/crypto/src/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/crypto')
-rw-r--r--crypto/src/crypto/operators/DefaultMacCalculator.cs21
-rw-r--r--crypto/src/crypto/operators/DefaultMacResult.cs27
-rw-r--r--crypto/src/crypto/operators/DefaultSignatureCalculator.cs18
-rw-r--r--crypto/src/crypto/operators/DefaultSignatureResult.cs11
-rw-r--r--crypto/src/crypto/operators/DefaultVerifierCalculator.cs15
-rw-r--r--crypto/src/crypto/operators/DefaultVerifierResult.cs19
6 files changed, 70 insertions, 41 deletions
diff --git a/crypto/src/crypto/operators/DefaultMacCalculator.cs b/crypto/src/crypto/operators/DefaultMacCalculator.cs
new file mode 100644
index 000000000..2137bcde5
--- /dev/null
+++ b/crypto/src/crypto/operators/DefaultMacCalculator.cs
@@ -0,0 +1,21 @@
+using System.IO;
+
+using Org.BouncyCastle.Crypto.IO;
+
+namespace Org.BouncyCastle.Crypto.Operators
+{
+    public sealed class DefaultMacCalculator
+        : IStreamCalculator<IBlockResult>
+    {
+        private readonly MacSink m_macSink;
+
+        public DefaultMacCalculator(IMac mac)
+        {
+            m_macSink = new MacSink(mac);
+        }
+
+        public Stream Stream => m_macSink;
+
+        public IBlockResult GetResult() => new DefaultMacResult(m_macSink.Mac);
+    }
+}
diff --git a/crypto/src/crypto/operators/DefaultMacResult.cs b/crypto/src/crypto/operators/DefaultMacResult.cs
new file mode 100644
index 000000000..9a45d6792
--- /dev/null
+++ b/crypto/src/crypto/operators/DefaultMacResult.cs
@@ -0,0 +1,27 @@
+using System;
+
+using Org.BouncyCastle.Security;
+
+namespace Org.BouncyCastle.Crypto.Operators
+{
+    public sealed class DefaultMacResult
+        : IBlockResult
+    {
+        private readonly IMac m_mac;
+
+        public DefaultMacResult(IMac mac)
+        {
+            m_mac = mac;
+        }
+
+        public byte[] Collect() => MacUtilities.DoFinal(m_mac);
+
+        public int Collect(byte[] buf, int off) => m_mac.DoFinal(buf, off);
+
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        public int Collect(Span<byte> output) => m_mac.DoFinal(output);
+#endif
+
+        public int GetMaxResultLength() => m_mac.GetMacSize();
+    }
+}
diff --git a/crypto/src/crypto/operators/DefaultSignatureCalculator.cs b/crypto/src/crypto/operators/DefaultSignatureCalculator.cs
index 851662622..0b9f151d3 100644
--- a/crypto/src/crypto/operators/DefaultSignatureCalculator.cs
+++ b/crypto/src/crypto/operators/DefaultSignatureCalculator.cs
@@ -1,28 +1,22 @@
-using System;
-using System.IO;
+using System.IO;
 
 using Org.BouncyCastle.Crypto.IO;
 
 namespace Org.BouncyCastle.Crypto.Operators
 {
+    // TODO[api] sealed
     public class DefaultSignatureCalculator
         : IStreamCalculator<IBlockResult>
     {
-        private readonly SignerSink mSignerSink;
+        private readonly SignerSink m_signerSink;
 
         public DefaultSignatureCalculator(ISigner signer)
         {
-            this.mSignerSink = new SignerSink(signer);
+            m_signerSink = new SignerSink(signer);
         }
 
-        public Stream Stream
-        {
-            get { return mSignerSink; }
-        }
+        public Stream Stream => m_signerSink;
 
-        public IBlockResult GetResult()
-        {
-            return new DefaultSignatureResult(mSignerSink.Signer);
-        }
+        public IBlockResult GetResult() => new DefaultSignatureResult(m_signerSink.Signer);
     }
 }
diff --git a/crypto/src/crypto/operators/DefaultSignatureResult.cs b/crypto/src/crypto/operators/DefaultSignatureResult.cs
index cbbc04d20..3ac66c2b4 100644
--- a/crypto/src/crypto/operators/DefaultSignatureResult.cs
+++ b/crypto/src/crypto/operators/DefaultSignatureResult.cs
@@ -5,17 +5,14 @@ namespace Org.BouncyCastle.Crypto.Operators
     public sealed class DefaultSignatureResult
         : IBlockResult
     {
-        private readonly ISigner mSigner;
+        private readonly ISigner m_signer;
 
         public DefaultSignatureResult(ISigner signer)
         {
-            this.mSigner = signer;
+            m_signer = signer;
         }
 
-        public byte[] Collect()
-        {
-            return mSigner.GenerateSignature();
-        }
+        public byte[] Collect() => m_signer.GenerateSignature();
 
         public int Collect(byte[] buf, int off)
         {
@@ -33,6 +30,6 @@ namespace Org.BouncyCastle.Crypto.Operators
         }
 #endif
 
-        public int GetMaxResultLength() => mSigner.GetMaxSignatureSize();
+        public int GetMaxResultLength() => m_signer.GetMaxSignatureSize();
     }
 }
diff --git a/crypto/src/crypto/operators/DefaultVerifierCalculator.cs b/crypto/src/crypto/operators/DefaultVerifierCalculator.cs
index cbf4e77d6..719a3f9a4 100644
--- a/crypto/src/crypto/operators/DefaultVerifierCalculator.cs
+++ b/crypto/src/crypto/operators/DefaultVerifierCalculator.cs
@@ -5,24 +5,19 @@ using Org.BouncyCastle.Crypto.IO;
 
 namespace Org.BouncyCastle.Crypto.Operators
 {
+    // TODO[api] sealed
     public class DefaultVerifierCalculator
         : IStreamCalculator<IVerifier>
     {
-        private readonly SignerSink mSignerSink;
+        private readonly SignerSink m_signerSink;
 
         public DefaultVerifierCalculator(ISigner signer)
         {
-            this.mSignerSink = new SignerSink(signer);
+            m_signerSink = new SignerSink(signer);
         }
 
-        public Stream Stream
-        {
-            get { return mSignerSink; }
-        }
+        public Stream Stream => m_signerSink;
 
-        public IVerifier GetResult()
-        {
-            return new DefaultVerifierResult(mSignerSink.Signer);
-        }
+        public IVerifier GetResult() => new DefaultVerifierResult(m_signerSink.Signer);
     }
 }
diff --git a/crypto/src/crypto/operators/DefaultVerifierResult.cs b/crypto/src/crypto/operators/DefaultVerifierResult.cs
index fb259c8f8..994020a46 100644
--- a/crypto/src/crypto/operators/DefaultVerifierResult.cs
+++ b/crypto/src/crypto/operators/DefaultVerifierResult.cs
@@ -4,26 +4,21 @@ using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Crypto.Operators
 {
+    // TODO[api] sealed
     public class DefaultVerifierResult
         : IVerifier
     {
-        private readonly ISigner mSigner;
+        private readonly ISigner m_signer;
 
         public DefaultVerifierResult(ISigner signer)
         {
-            this.mSigner = signer;
+            m_signer = signer;
         }
 
-        public bool IsVerified(byte[] signature)
-        {
-            return mSigner.VerifySignature(signature);
-        }
+        public bool IsVerified(byte[] signature) => m_signer.VerifySignature(signature);
 
-        public bool IsVerified(byte[] sig, int sigOff, int sigLen)
-        {
-            byte[] signature = Arrays.CopyOfRange(sig, sigOff, sigOff + sigLen);
-
-            return IsVerified(signature);
-        }
+        // TODO[api] Use ISigner.VerifySignature(ReadOnlySpan<byte>) when available
+        public bool IsVerified(byte[] sig, int sigOff, int sigLen) =>
+            IsVerified(Arrays.CopyOfRange(sig, sigOff, sigOff + sigLen));
     }
 }