From 9e96c3d0bd333cfdca84c44f47a966068556a67d Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Tue, 14 Feb 2023 16:04:20 +0700 Subject: Refactor Check --- crypto/src/crypto/Check.cs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'crypto') 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 input, int len, string msg) + internal static void DataLength(ReadOnlySpan input, int len, string message) { if (input.Length < len) - throw new DataLengthException(msg); + ThrowDataLengthException(message); } - internal static void OutputLength(Span output, int len, string msg) + internal static void OutputLength(Span 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); } } -- cgit 1.4.1