summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-14 16:04:20 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-14 16:04:20 +0700
commit9e96c3d0bd333cfdca84c44f47a966068556a67d (patch)
tree8de118a74048068abf50e7c68c2aa41582b513ff
parentImprove DerObjectIdentifier cache (diff)
downloadBouncyCastle.NET-ed25519-9e96c3d0bd333cfdca84c44f47a966068556a67d.tar.xz
Refactor Check
-rw-r--r--crypto/src/crypto/Check.cs31
1 files changed, 20 insertions, 11 deletions
diff --git a/crypto/src/crypto/Check.cs b/crypto/src/crypto/Check.cs
index 36263dc24..035304db4 100644
--- a/crypto/src/crypto/Check.cs
+++ b/crypto/src/crypto/Check.cs
@@ -2,38 +2,47 @@
 
 namespace Org.BouncyCastle.Crypto
 {
-    internal class Check
+    internal static class Check
     {
-        internal static void DataLength(bool condition, string msg)
+        internal static void DataLength(bool condition, string message)
         {
             if (condition)
-                throw new DataLengthException(msg);
+                ThrowDataLengthException(message);
         }
 
-        internal static void DataLength(byte[] buf, int off, int len, string msg)
+        internal static void DataLength(byte[] buf, int off, int len, string message)
         {
             if (off > (buf.Length - len))
-                throw new DataLengthException(msg);
+                ThrowDataLengthException(message);
         }
 
-        internal static void OutputLength(byte[] buf, int off, int len, string msg)
+        internal static void OutputLength(bool condition, string message)
+        {
+            if (condition)
+                ThrowOutputLengthException(message);
+        }
+
+        internal static void OutputLength(byte[] buf, int off, int len, string message)
         {
             if (off > (buf.Length - len))
-                throw new OutputLengthException(msg);
+                ThrowOutputLengthException(message);
         }
 
 #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
-        internal static void DataLength(ReadOnlySpan<byte> input, int len, string msg)
+        internal static void DataLength<T>(ReadOnlySpan<T> input, int len, string message)
         {
             if (input.Length < len)
-                throw new DataLengthException(msg);
+                ThrowDataLengthException(message);
         }
 
-        internal static void OutputLength(Span<byte> output, int len, string msg)
+        internal static void OutputLength<T>(Span<T> output, int len, string message)
         {
             if (output.Length < len)
-                throw new OutputLengthException(msg);
+                ThrowOutputLengthException(message);
         }
 #endif
+
+        internal static void ThrowDataLengthException(string message) => throw new DataLengthException(message);
+        internal static void ThrowOutputLengthException(string message) => throw new OutputLengthException(message);
     }
 }