From 77c65fab3bc625f98e8332a2c1e497c46fe39b4c Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 21 Jun 2022 17:41:31 -0400 Subject: [PATCH] Use SequenceEqual in SslCredKey.Equals --- .../System/Net/Security/SslSessionsCache.cs | 44 ++++--------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs index 59009e72b4cfa1..026115dfac1b00 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs @@ -72,47 +72,21 @@ public override int GetHashCode() return hashCode; } - public override bool Equals([NotNullWhen(true)] object? obj) => (obj is SslCredKey && Equals((SslCredKey)obj)); + public override bool Equals([NotNullWhen(true)] object? obj) => + obj is SslCredKey other && Equals(other); public bool Equals(SslCredKey other) { byte[] thumbPrint = _thumbPrint; byte[] otherThumbPrint = other._thumbPrint; - if (thumbPrint.Length != otherThumbPrint.Length) - { - return false; - } - - if (_encryptionPolicy != other._encryptionPolicy) - { - return false; - } - - if (_allowedProtocols != other._allowedProtocols) - { - return false; - } - - if (_isServerMode != other._isServerMode) - { - return false; - } - - if (_sendTrustList != other._sendTrustList) - { - return false; - } - - for (int i = 0; i < thumbPrint.Length; ++i) - { - if (thumbPrint[i] != otherThumbPrint[i]) - { - return false; - } - } - - return true; + return + thumbPrint.Length == otherThumbPrint.Length && + _encryptionPolicy == other._encryptionPolicy && + _allowedProtocols == other._allowedProtocols && + _isServerMode == other._isServerMode && + _sendTrustList == other._sendTrustList && + thumbPrint.AsSpan().SequenceEqual(otherThumbPrint); } }