Use IndexOf in RsaPaddingProcessor.FillNonZeroBytes (#81327)
authorStephen Toub <stoub@microsoft.com>
Sun, 29 Jan 2023 16:03:01 +0000 (11:03 -0500)
committerGitHub <noreply@github.com>
Sun, 29 Jan 2023 16:03:01 +0000 (11:03 -0500)
src/libraries/Common/src/System/Security/Cryptography/RsaPaddingProcessor.cs

index 95a93fd..fe4d22d 100644 (file)
@@ -510,14 +510,10 @@ namespace System.Security.Cryptography
                 RandomNumberGenerator.Fill(data);
 
                 // Find the first zero in the remaining portion.
-                int indexOfFirst0Byte = data.Length;
-                for (int i = 0; i < data.Length; i++)
+                int indexOfFirst0Byte = data.IndexOf((byte)0);
+                if (indexOfFirst0Byte < 0)
                 {
-                    if (data[i] == 0)
-                    {
-                        indexOfFirst0Byte = i;
-                        break;
-                    }
+                    break;
                 }
 
                 // If there were any zeros, shift down all non-zeros.