Title: [279058] trunk/Source/WTF
Revision
279058
Author
wei...@apple.com
Date
2021-06-20 13:33:15 -0700 (Sun, 20 Jun 2021)

Log Message

Adopt Span in SHA1.h
https://bugs.webkit.org/show_bug.cgi?id=227184

Reviewed by Chris Dumez.

Replaces overload of addBytes taking a Vector with ones taking
a Span and add overloads for Span<const std::byte> which all the
others are now implemented in terms of. This is useful since
any Span can be turned into one of type Span<const std::byte>
just by calling asBytes(existingSpan).

This leaves most of the existing overloads in place (though
simplifies them by implementing them as Span contructions),
though we should consider removing some in a separate pass.

* wtf/SHA1.cpp:
* wtf/SHA1.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (279057 => 279058)


--- trunk/Source/WTF/ChangeLog	2021-06-20 19:46:09 UTC (rev 279057)
+++ trunk/Source/WTF/ChangeLog	2021-06-20 20:33:15 UTC (rev 279058)
@@ -1,3 +1,23 @@
+2021-06-20  Sam Weinig  <wei...@apple.com>
+
+        Adopt Span in SHA1.h
+        https://bugs.webkit.org/show_bug.cgi?id=227184
+
+        Reviewed by Chris Dumez.
+
+        Replaces overload of addBytes taking a Vector with ones taking
+        a Span and add overloads for Span<const std::byte> which all the
+        others are now implemented in terms of. This is useful since
+        any Span can be turned into one of type Span<const std::byte>
+        just by calling asBytes(existingSpan).
+
+        This leaves most of the existing overloads in place (though
+        simplifies them by implementing them as Span contructions),
+        though we should consider removing some in a separate pass.
+
+        * wtf/SHA1.cpp:
+        * wtf/SHA1.h:
+
 2021-06-19  Sam Weinig  <wei...@apple.com>
 
         Adopt Span in Base64.h

Modified: trunk/Source/WTF/wtf/SHA1.cpp (279057 => 279058)


--- trunk/Source/WTF/wtf/SHA1.cpp	2021-06-20 19:46:09 UTC (rev 279057)
+++ trunk/Source/WTF/wtf/SHA1.cpp	2021-06-20 20:33:15 UTC (rev 279058)
@@ -46,10 +46,10 @@
     ALLOW_DEPRECATED_DECLARATIONS_END
 }
 
-void SHA1::addBytes(const uint8_t* input, size_t length)
+void SHA1::addBytes(Span<const std::byte> input)
 {
     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-    CC_SHA1_Update(&m_context, input, length);
+    CC_SHA1_Update(&m_context, input.data(), input.size());
     ALLOW_DEPRECATED_DECLARATIONS_END
 }
 
@@ -101,11 +101,11 @@
     reset();
 }
 
-void SHA1::addBytes(const uint8_t* input, size_t length)
+void SHA1::addBytes(Span<const std::byte> input)
 {
-    while (length--) {
+    for (auto byte : input) {
         ASSERT(m_cursor < 64);
-        m_buffer[m_cursor++] = *input++;
+        m_buffer[m_cursor++] = std::to_integer<uint8_t>(byte);
         ++m_totalBytes;
         if (m_cursor == 64)
             processBlock();

Modified: trunk/Source/WTF/wtf/SHA1.h (279057 => 279058)


--- trunk/Source/WTF/wtf/SHA1.h	2021-06-20 19:46:09 UTC (rev 279057)
+++ trunk/Source/WTF/wtf/SHA1.h	2021-06-20 20:33:15 UTC (rev 279058)
@@ -31,7 +31,7 @@
 #pragma once
 
 #include <array>
-#include <wtf/Vector.h>
+#include <wtf/Span.h>
 #include <wtf/text/CString.h>
 
 #if PLATFORM(COCOA)
@@ -45,16 +45,23 @@
 public:
     WTF_EXPORT_PRIVATE SHA1();
 
-    void addBytes(const Vector<uint8_t>& input)
+    WTF_EXPORT_PRIVATE void addBytes(Span<const std::byte>);
+
+    void addBytes(Span<const uint8_t> input)
     {
-        addBytes(input.data(), input.size());
+        addBytes(asBytes(input));
     }
+
     void addBytes(const CString& input)
     {
-        addBytes(input.dataAsUInt8Ptr(), input.length());
+        addBytes(input.bytes());
     }
-    WTF_EXPORT_PRIVATE void addBytes(const uint8_t* input, size_t length);
 
+    void addBytes(const uint8_t* input, size_t length)
+    {
+        addBytes(Span { input, length });
+    }
+
     // Size of the SHA1 hash
     WTF_EXPORT_PRIVATE static constexpr size_t hashSize = 20;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to