Chromium Code Reviews| Index: Source/core/inspector/DOMPatchSupport.cpp |
| diff --git a/Source/core/inspector/DOMPatchSupport.cpp b/Source/core/inspector/DOMPatchSupport.cpp |
| index 33dee3a1eb12e0a5f201fe037b33f2a275b45cea..f897da20e7f21e355ba6260f8b07ee03ba91d084 100644 |
| --- a/Source/core/inspector/DOMPatchSupport.cpp |
| +++ b/Source/core/inspector/DOMPatchSupport.cpp |
| @@ -46,10 +46,11 @@ |
| #include "core/inspector/DOMEditor.h" |
| #include "core/inspector/InspectorHistory.h" |
| #include "core/xml/parser/XMLDocumentParser.h" |
| +#include "platform/CryptoUtilities.h" |
| +#include "public/platform/Platform.h" |
| #include "wtf/Deque.h" |
| #include "wtf/HashTraits.h" |
| #include "wtf/RefPtr.h" |
| -#include "wtf/SHA1.h" |
| #include "wtf/text/Base64.h" |
| #include "wtf/text/CString.h" |
| @@ -394,28 +395,23 @@ bool DOMPatchSupport::innerPatchChildren(ContainerNode* parentNode, const Vector |
| return true; |
| } |
| -static void addStringToSHA1(SHA1& sha1, const String& string) |
| -{ |
| - CString cString = string.utf8(); |
| - sha1.addBytes(reinterpret_cast<const uint8_t*>(cString.data()), cString.length()); |
| -} |
| - |
| PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, UnusedNodesMap* unusedNodesMap) |
| { |
| Digest* digest = new Digest(node); |
| - SHA1 sha1; |
| + CryptoUtil::DigestValue digestResult; |
| + StringBuilder digestable; |
| Node::NodeType nodeType = node->nodeType(); |
| - sha1.addBytes(reinterpret_cast<const uint8_t*>(&nodeType), sizeof(nodeType)); |
| - addStringToSHA1(sha1, node->nodeName()); |
| - addStringToSHA1(sha1, node->nodeValue()); |
| + digestable.append(reinterpret_cast<const char*>(&nodeType), sizeof(nodeType)); |
| + digestable.append(node->nodeName()); |
|
eseidel
2014/03/12 06:50:29
You could have just used Vector<uint8_t> here, Str
abarth-chromium
2014/03/12 18:59:02
Yeah, you've got an UTF-8 conversion at the end, w
jww
2014/04/01 23:29:09
I think this is irrelevant now because I've modifi
|
| + digestable.append(node->nodeValue()); |
| if (node->nodeType() == Node::ELEMENT_NODE) { |
| Node* child = node->firstChild(); |
| while (child) { |
| OwnPtr<Digest> childInfo = createDigest(child, unusedNodesMap); |
| - addStringToSHA1(sha1, childInfo->m_sha1); |
| + digestable.append(childInfo->m_sha1); |
| child = child->nextSibling(); |
| digest->m_children.append(childInfo.release()); |
| } |
| @@ -423,22 +419,23 @@ PassOwnPtr<DOMPatchSupport::Digest> DOMPatchSupport::createDigest(Node* node, Un |
| if (element->hasAttributesWithoutUpdate()) { |
| size_t numAttrs = element->attributeCount(); |
| - SHA1 attrsSHA1; |
| + StringBuilder attrsDigestable; |
| for (size_t i = 0; i < numAttrs; ++i) { |
| const Attribute& attribute = element->attributeItem(i); |
| - addStringToSHA1(attrsSHA1, attribute.name().toString()); |
| - addStringToSHA1(attrsSHA1, attribute.value()); |
| + attrsDigestable.append(attribute.name().toString()); |
| + attrsDigestable.append(attribute.value()); |
| } |
| - Vector<uint8_t, 20> attrsHash; |
| - attrsSHA1.computeHash(attrsHash); |
| - digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(attrsHash.data()), 10); |
| - addStringToSHA1(sha1, digest->m_attrsSHA1); |
| + CString attrsDigestableCString = attrsDigestable.toString().utf8(); |
| + CryptoUtil::computeDigest(CryptoUtil::HashAlgorithmSha1, attrsDigestableCString.data(), attrsDigestableCString.length(), digestResult); |
| + digest->m_attrsSHA1 = base64Encode(reinterpret_cast<const char*>(digestResult.data()), 10); |
|
eseidel
2014/03/12 06:50:29
I take it we only want the first 10 bytes of the d
jww
2014/04/01 23:29:09
I don't ask questions; I just make compatible with
|
| + digestable.append(digest->m_attrsSHA1); |
| + digestResult.clear(); |
| } |
| } |
| - Vector<uint8_t, 20> hash; |
| - sha1.computeHash(hash); |
| - digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(hash.data()), 10); |
| + CString digestableCString = digestable.toString().utf8(); |
| + CryptoUtil::computeDigest(CryptoUtil::HashAlgorithmSha1, digestableCString.data(), digestableCString.length(), digestResult); |
| + digest->m_sha1 = base64Encode(reinterpret_cast<const char*>(digestResult.data()), 10); |
| if (unusedNodesMap) |
| unusedNodesMap->add(digest->m_sha1, digest); |
| return adoptPtr(digest); |