From 6b82d749f14943082790cfecda9674521e098b07 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 17 Oct 2022 17:48:11 +0700 Subject: Compare byte arrays using SequenceCompareTo --- crypto/src/asn1/Asn1Set.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crypto/src/asn1/Asn1Set.cs b/crypto/src/asn1/Asn1Set.cs index b2a654d68..faec50eb0 100644 --- a/crypto/src/asn1/Asn1Set.cs +++ b/crypto/src/asn1/Asn1Set.cs @@ -306,6 +306,10 @@ namespace Org.BouncyCastle.Asn1 if (a0 != b0) return a0 < b0 ? -1 : 1; +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + int compareLength = System.Math.Min(a.Length, b.Length) - 1; + return a.AsSpan(1, compareLength).SequenceCompareTo(b.AsSpan(1, compareLength)); +#else int len = System.Math.Min(a.Length, b.Length); for (int i = 1; i < len; ++i) { @@ -315,6 +319,7 @@ namespace Org.BouncyCastle.Asn1 } Debug.Assert(a.Length == b.Length); return 0; +#endif } } } -- cgit 1.4.1