Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: Source/platform/Crypto.cpp

Issue 235893003: Remove use of WebCrypto digestSynchronous in Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Changed ASSERT_WITH_SECURITY_IMPLICATIONS to RELEASE_ASSERT Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/platform/Crypto.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "platform/Crypto.h" 6 #include "platform/Crypto.h"
7 7
8 #include "public/platform/Platform.h" 8 #include "public/platform/Platform.h"
9 #include "public/platform/WebArrayBuffer.h" 9 #include "public/platform/WebArrayBuffer.h"
10 #include "public/platform/WebCrypto.h" 10 #include "public/platform/WebCrypto.h"
(...skipping 13 matching lines...) Expand all
24 case HashAlgorithmSha384: 24 case HashAlgorithmSha384:
25 return blink::WebCryptoAlgorithmIdSha384; 25 return blink::WebCryptoAlgorithmIdSha384;
26 case HashAlgorithmSha512: 26 case HashAlgorithmSha512:
27 return blink::WebCryptoAlgorithmIdSha512; 27 return blink::WebCryptoAlgorithmIdSha512;
28 }; 28 };
29 29
30 ASSERT_NOT_REACHED(); 30 ASSERT_NOT_REACHED();
31 return blink::WebCryptoAlgorithmIdSha256; 31 return blink::WebCryptoAlgorithmIdSha256;
32 } 32 }
33 33
34 void computeDigest(HashAlgorithm algorithm, const char* digestable, size_t lengt h, DigestValue& digestResult) 34 bool computeDigest(HashAlgorithm algorithm, const char* digestable, size_t lengt h, DigestValue& digestResult)
35 { 35 {
36 blink::WebCryptoAlgorithmId algorithmId = toWebCryptoAlgorithmId(algorithm); 36 blink::WebCryptoAlgorithmId algorithmId = toWebCryptoAlgorithmId(algorithm);
37 blink::WebCrypto* crypto = blink::Platform::current()->crypto(); 37 blink::WebCrypto* crypto = blink::Platform::current()->crypto();
38 blink::WebArrayBuffer result; 38 unsigned char* result;
39 unsigned resultSize;
39 40
40 ASSERT(crypto); 41 ASSERT(crypto);
41 42
42 crypto->digestSynchronous(algorithmId, reinterpret_cast<const unsigned char* >(digestable), length, result); 43 OwnPtr<blink::WebCryptoDigestor> digestor = adoptPtr(crypto->createDigestor( algorithmId));
44 if (!digestor.get() || !digestor->consume(reinterpret_cast<const unsigned ch ar*>(digestable), length) || !digestor->finish(result, resultSize))
45 return false;
43 46
44 ASSERT(!result.isNull()); 47 digestResult.append(static_cast<uint8_t*>(result), resultSize);
45 48 return true;
46 digestResult.append(static_cast<uint8_t*>(result.data()), result.byteLength( ));
47 } 49 }
48 50
49 PassOwnPtr<blink::WebCryptoDigestor> createDigestor(HashAlgorithm algorithm) 51 PassOwnPtr<blink::WebCryptoDigestor> createDigestor(HashAlgorithm algorithm)
50 { 52 {
51 return adoptPtr(blink::Platform::current()->crypto()->createDigestor(toWebCr yptoAlgorithmId(algorithm))); 53 return adoptPtr(blink::Platform::current()->crypto()->createDigestor(toWebCr yptoAlgorithmId(algorithm)));
52 } 54 }
53 55
54 void finishDigestor(blink::WebCryptoDigestor* digestor, DigestValue& digestResul t) 56 void finishDigestor(blink::WebCryptoDigestor* digestor, DigestValue& digestResul t)
55 { 57 {
56 unsigned char* result = 0; 58 unsigned char* result = 0;
57 unsigned resultSize = 0; 59 unsigned resultSize = 0;
58 60
59 if (!digestor->finish(result, resultSize)) 61 if (!digestor->finish(result, resultSize))
60 return; 62 return;
61 63
62 ASSERT(result); 64 ASSERT(result);
63 65
64 digestResult.append(static_cast<uint8_t*>(result), resultSize); 66 digestResult.append(static_cast<uint8_t*>(result), resultSize);
65 } 67 }
66 68
67 } // namespace WebCore 69 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/Crypto.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698