Title: [160456] trunk/Source
Revision
160456
Author
[email protected]
Date
2013-12-11 14:31:07 -0800 (Wed, 11 Dec 2013)

Log Message

Store SHA1 hash in std::array
https://bugs.webkit.org/show_bug.cgi?id=125446

Patch by Laszlo Vidacs <[email protected]> on 2013-12-11
Reviewed by Darin Adler.

Change Vector to std::array and use typedef.

Source/_javascript_Core:

* bytecode/CodeBlockHash.cpp:
(JSC::CodeBlockHash::CodeBlockHash):

Source/WebCore:

* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::getExpectedWebSocketAccept):
* inspector/DOMPatchSupport.cpp:
(WebCore::DOMPatchSupport::createDigest):
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::HostTLSCertificateSet::computeCertificateHash):

Source/WTF:

* wtf/SHA1.cpp:
(WTF::SHA1::computeHash):
(WTF::SHA1::hexDigest):
(WTF::SHA1::computeHexDigest):
* wtf/SHA1.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (160455 => 160456)


--- trunk/Source/_javascript_Core/ChangeLog	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-12-11 22:31:07 UTC (rev 160456)
@@ -1,3 +1,15 @@
+2013-12-11  Laszlo Vidacs  <[email protected]>
+
+        Store SHA1 hash in std::array
+        https://bugs.webkit.org/show_bug.cgi?id=125446
+
+        Reviewed by Darin Adler.
+
+        Change Vector to std::array and use typedef.
+
+        * bytecode/CodeBlockHash.cpp:
+        (JSC::CodeBlockHash::CodeBlockHash):
+
 2013-12-11  Mark Rowe  <[email protected]>
 
         <https://webkit.org/b/125141> Modernize the _javascript_Core API headers

Modified: trunk/Source/_javascript_Core/bytecode/CodeBlockHash.cpp (160455 => 160456)


--- trunk/Source/_javascript_Core/bytecode/CodeBlockHash.cpp	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/_javascript_Core/bytecode/CodeBlockHash.cpp	2013-12-11 22:31:07 UTC (rev 160456)
@@ -42,7 +42,7 @@
 {
     SHA1 sha1;
     sha1.addBytes(sourceCode.toUTF8());
-    Vector<uint8_t, SHA1::hashSize> digest;
+    SHA1::Digest digest;
     sha1.computeHash(digest);
     m_hash += digest[0] | (digest[1] << 8) | (digest[2] << 16) | (digest[3] << 24);
     m_hash ^= static_cast<unsigned>(kind);

Modified: trunk/Source/WTF/ChangeLog (160455 => 160456)


--- trunk/Source/WTF/ChangeLog	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WTF/ChangeLog	2013-12-11 22:31:07 UTC (rev 160456)
@@ -1,3 +1,18 @@
+2013-12-11  Laszlo Vidacs  <[email protected]>
+
+        Store SHA1 hash in std::array
+        https://bugs.webkit.org/show_bug.cgi?id=125446
+
+        Reviewed by Darin Adler.
+
+        Change Vector to std::array and use typedef.
+
+        * wtf/SHA1.cpp:
+        (WTF::SHA1::computeHash):
+        (WTF::SHA1::hexDigest):
+        (WTF::SHA1::computeHexDigest):
+        * wtf/SHA1.h:
+
 2013-12-11  Oliver Hunt  <[email protected]>
 
         Give Unique StringImpls a meaningful data pointer

Modified: trunk/Source/WTF/wtf/SHA1.cpp (160455 => 160456)


--- trunk/Source/WTF/wtf/SHA1.cpp	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WTF/wtf/SHA1.cpp	2013-12-11 22:31:07 UTC (rev 160456)
@@ -88,12 +88,10 @@
     }
 }
 
-void SHA1::computeHash(Vector<uint8_t, 20>& digest)
+void SHA1::computeHash(Digest& digest)
 {
     finalize();
 
-    digest.clear();
-    digest.resize(20);
     for (size_t i = 0; i < 5; ++i) {
         // Treat hashValue as a big-endian value.
         uint32_t hashValue = m_hash[i];
@@ -106,12 +104,12 @@
     reset();
 }
 
-CString SHA1::hexDigest(const Vector<uint8_t, 20>& digest)
+CString SHA1::hexDigest(const Digest& digest)
 {
     char* start = 0;
     CString result = CString::newUninitialized(40, start);
     char* buffer = start;
-    for (size_t i = 0; i < 20; ++i) {
+    for (size_t i = 0; i < hashSize; ++i) {
         snprintf(buffer, 3, "%02X", digest.at(i));
         buffer += 2;
     }
@@ -120,7 +118,7 @@
 
 CString SHA1::computeHexDigest()
 {
-    Vector<uint8_t, 20> digest;
+    Digest digest;
     computeHash(digest);
     return hexDigest(digest);
 }

Modified: trunk/Source/WTF/wtf/SHA1.h (160455 => 160456)


--- trunk/Source/WTF/wtf/SHA1.h	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WTF/wtf/SHA1.h	2013-12-11 22:31:07 UTC (rev 160456)
@@ -31,6 +31,7 @@
 #ifndef WTF_SHA1_h
 #define WTF_SHA1_h
 
+#include <array>
 #include <wtf/Vector.h>
 #include <wtf/text/CString.h>
 
@@ -56,18 +57,21 @@
     }
     WTF_EXPORT_PRIVATE void addBytes(const uint8_t* input, size_t length);
 
+    // Size of the SHA1 hash
+    WTF_EXPORT_PRIVATE static const size_t hashSize = 20;
+
+    // type for computing SHA1 hash
+    typedef std::array<uint8_t, hashSize> Digest;
+
     // computeHash has a side effect of resetting the state of the object.
-    WTF_EXPORT_PRIVATE void computeHash(Vector<uint8_t, 20>&);
+    WTF_EXPORT_PRIVATE void computeHash(Digest&);
     
-    // Get a hex hash from the digest. Pass a limit less than 40 if you want a shorter digest.
-    WTF_EXPORT_PRIVATE static CString hexDigest(const Vector<uint8_t, 20>&);
+    // Get a hex hash from the digest.
+    WTF_EXPORT_PRIVATE static CString hexDigest(const Digest&);
     
-    // Compute the hex digest directly. Pass a limit less than 40 if you want a shorter digest.
+    // Compute the hex digest directly.
     WTF_EXPORT_PRIVATE CString computeHexDigest();
 
-    // Size of the SHA1 hash
-    WTF_EXPORT_PRIVATE static const size_t hashSize = 20;
-
 private:
     void finalize();
     void processBlock();

Modified: trunk/Source/WebCore/ChangeLog (160455 => 160456)


--- trunk/Source/WebCore/ChangeLog	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WebCore/ChangeLog	2013-12-11 22:31:07 UTC (rev 160456)
@@ -1,3 +1,19 @@
+2013-12-11  Laszlo Vidacs  <[email protected]>
+
+        Store SHA1 hash in std::array
+        https://bugs.webkit.org/show_bug.cgi?id=125446
+
+        Reviewed by Darin Adler.
+
+        Change Vector to std::array and use typedef.
+
+        * Modules/websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::getExpectedWebSocketAccept):
+        * inspector/DOMPatchSupport.cpp:
+        (WebCore::DOMPatchSupport::createDigest):
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::HostTLSCertificateSet::computeCertificateHash):
+
 2013-12-11  Alexey Proskuryakov  <[email protected]>
 
         WebCrypto keys should support structured clone

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp (160455 => 160456)


--- trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2013-12-11 22:31:07 UTC (rev 160456)
@@ -113,7 +113,7 @@
     CString keyData = secWebSocketKey.ascii();
     sha1.addBytes(reinterpret_cast<const uint8_t*>(keyData.data()), keyData.length());
     sha1.addBytes(reinterpret_cast<const uint8_t*>(webSocketKeyGUID), strlen(webSocketKeyGUID));
-    Vector<uint8_t, SHA1::hashSize> hash;
+    SHA1::Digest hash;
     sha1.computeHash(hash);
     return base64Encode(hash.data(), SHA1::hashSize);
 }

Modified: trunk/Source/WebCore/inspector/DOMPatchSupport.cpp (160455 => 160456)


--- trunk/Source/WebCore/inspector/DOMPatchSupport.cpp	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WebCore/inspector/DOMPatchSupport.cpp	2013-12-11 22:31:07 UTC (rev 160456)
@@ -440,14 +440,14 @@
                 addStringToSHA1(attrsSHA1, attribute.name().toString());
                 addStringToSHA1(attrsSHA1, attribute.value());
             }
-            Vector<uint8_t, 20> attrsHash;
+            SHA1::Digest attrsHash;
             attrsSHA1.computeHash(attrsHash);
             digest->m_attrsSHA1 = base64Encode(attrsHash.data(), 10);
             addStringToSHA1(sha1, digest->m_attrsSHA1);
         }
     }
 
-    Vector<uint8_t, 20> hash;
+    SHA1::Digest hash;
     sha1.computeHash(hash);
     digest->m_sha1 = base64Encode(hash.data(), 10);
     if (unusedNodesMap)

Modified: trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp (160455 => 160456)


--- trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2013-12-11 22:13:55 UTC (rev 160455)
+++ trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2013-12-11 22:31:07 UTC (rev 160456)
@@ -219,7 +219,7 @@
         SHA1 sha1;
         sha1.addBytes(certificateData->data, certificateData->len);
 
-        Vector<uint8_t, SHA1::hashSize> digest;
+        SHA1::Digest digest;
         sha1.computeHash(digest);
 
         return base64Encode(reinterpret_cast<const char*>(digest.data()), SHA1::hashSize);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to