From a97ee27030cf80bad858b14b28a930968461ea80 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Thu, 14 Mar 2024 11:17:24 -0700 Subject: [PATCH] Use vectorized SequenceEqual method --- src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs index 5ecd41d2..b01456e2 100644 --- a/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs +++ b/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs @@ -209,10 +209,10 @@ if (encryptionDictionary.Revision >= 3) { - return encryptionDictionary.UserBytes.Take(16).SequenceEqual(output.Take(16)); + return encryptionDictionary.UserBytes.AsSpan(0, 16).SequenceEqual(output.AsSpan(0, 16)); } - return encryptionDictionary.UserBytes.SequenceEqual(output); + return encryptionDictionary.UserBytes.AsSpan().SequenceEqual(output); } private static bool IsUserPasswordRevision5And6(byte[] passwordBytes, EncryptionDictionary encryptionDictionary) @@ -270,7 +270,7 @@ // 4. Create an RC4 encryption key using the first n bytes of the output from the final MD5 hash, // where n is always 5 for revision 2 but for revision 3 or greater depends on the value of the encryption dictionary's Length entry. - var key = hash.Take(length).ToArray(); + var key = hash.AsSpan(0, length).ToArray(); if (encryptionDictionary.Revision == 2) { @@ -615,7 +615,7 @@ { for (var i = 0; i < 50; i++) { - input = newMd5.ComputeHash(input.Take(n).ToArray()); + input = newMd5.ComputeHash(input.AsSpan(0, n).ToArray()); } }