diff options
-rw-r--r-- | crypto/src/util/BigIntegers.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/Bytes.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/Integers.cs | 13 | ||||
-rw-r--r-- | crypto/src/util/Longs.cs | 13 | ||||
-rw-r--r-- | crypto/src/util/Platform.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/Strings.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/io/Streams.cs | 6 |
7 files changed, 29 insertions, 11 deletions
diff --git a/crypto/src/util/BigIntegers.cs b/crypto/src/util/BigIntegers.cs index 93dc8e8eb..e63af7c7c 100644 --- a/crypto/src/util/BigIntegers.cs +++ b/crypto/src/util/BigIntegers.cs @@ -9,7 +9,7 @@ namespace Org.BouncyCastle.Utilities /** * BigInteger utilities. */ - public abstract class BigIntegers + public static class BigIntegers { public static readonly BigInteger Zero = BigInteger.Zero; public static readonly BigInteger One = BigInteger.One; diff --git a/crypto/src/util/Bytes.cs b/crypto/src/util/Bytes.cs index ecde85dde..466eba576 100644 --- a/crypto/src/util/Bytes.cs +++ b/crypto/src/util/Bytes.cs @@ -2,7 +2,7 @@ namespace Org.BouncyCastle.Utilities { - public abstract class Bytes + public static class Bytes { public const int NumBits = 8; public const int NumBytes = 1; diff --git a/crypto/src/util/Integers.cs b/crypto/src/util/Integers.cs index 75ba566e3..ab1868b74 100644 --- a/crypto/src/util/Integers.cs +++ b/crypto/src/util/Integers.cs @@ -1,4 +1,7 @@ using System; +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER +using System.Buffers.Binary; +#endif #if NETCOREAPP3_0_OR_GREATER using System.Numerics; using System.Runtime.Intrinsics.X86; @@ -8,7 +11,7 @@ using Org.BouncyCastle.Math.Raw; namespace Org.BouncyCastle.Utilities { - public abstract class Integers + public static class Integers { public const int NumBits = 32; public const int NumBytes = 4; @@ -96,14 +99,22 @@ namespace Org.BouncyCastle.Utilities public static int ReverseBytes(int i) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + return BinaryPrimitives.ReverseEndianness(i); +#else return (int)ReverseBytes((uint)i); +#endif } [CLSCompliant(false)] public static uint ReverseBytes(uint i) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + return BinaryPrimitives.ReverseEndianness(i); +#else return RotateLeft(i & 0xFF00FF00U, 8) | RotateLeft(i & 0x00FF00FFU, 24); +#endif } public static int RotateLeft(int i, int distance) diff --git a/crypto/src/util/Longs.cs b/crypto/src/util/Longs.cs index 9e34dab99..02ffb7676 100644 --- a/crypto/src/util/Longs.cs +++ b/crypto/src/util/Longs.cs @@ -1,4 +1,7 @@ using System; +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER +using System.Buffers.Binary; +#endif #if NETCOREAPP3_0_OR_GREATER using System.Numerics; using System.Runtime.Intrinsics.X86; @@ -8,7 +11,7 @@ using Org.BouncyCastle.Math.Raw; namespace Org.BouncyCastle.Utilities { - public abstract class Longs + public static class Longs { public const int NumBits = 64; public const int NumBytes = 8; @@ -95,16 +98,24 @@ namespace Org.BouncyCastle.Utilities public static long ReverseBytes(long i) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + return BinaryPrimitives.ReverseEndianness(i); +#else return (long)ReverseBytes((ulong)i); +#endif } [CLSCompliant(false)] public static ulong ReverseBytes(ulong i) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + return BinaryPrimitives.ReverseEndianness(i); +#else return RotateLeft(i & 0xFF000000FF000000UL, 8) | RotateLeft(i & 0x00FF000000FF0000UL, 24) | RotateLeft(i & 0x0000FF000000FF00UL, 40) | RotateLeft(i & 0x000000FF000000FFUL, 56); +#endif } public static long RotateLeft(long i, int distance) diff --git a/crypto/src/util/Platform.cs b/crypto/src/util/Platform.cs index 75b728bd9..118c29918 100644 --- a/crypto/src/util/Platform.cs +++ b/crypto/src/util/Platform.cs @@ -3,7 +3,7 @@ using System.Globalization; namespace Org.BouncyCastle.Utilities { - internal abstract class Platform + internal static class Platform { private static readonly CompareInfo InvariantCompareInfo = CultureInfo.InvariantCulture.CompareInfo; diff --git a/crypto/src/util/Strings.cs b/crypto/src/util/Strings.cs index baee573be..12eafd21e 100644 --- a/crypto/src/util/Strings.cs +++ b/crypto/src/util/Strings.cs @@ -4,7 +4,7 @@ using System.Text; namespace Org.BouncyCastle.Utilities { /// <summary> General string utilities.</summary> - public abstract class Strings + public static class Strings { internal static bool IsOneOf(string s, params string[] candidates) { diff --git a/crypto/src/util/io/Streams.cs b/crypto/src/util/io/Streams.cs index c23332909..ac4bd3ae6 100644 --- a/crypto/src/util/io/Streams.cs +++ b/crypto/src/util/io/Streams.cs @@ -3,14 +3,10 @@ using System.IO; namespace Org.BouncyCastle.Utilities.IO { - public sealed class Streams + public static class Streams { private const int BufferSize = 4096; - private Streams() - { - } - public static void Drain(Stream inStr) { inStr.CopyTo(Stream.Null, BufferSize); |