OLD | NEW |
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 "platform/Crypto.h" | 5 #include "platform/Crypto.h" |
6 | 6 |
7 #include "public/platform/Platform.h" | 7 #include "public/platform/Platform.h" |
8 #include "public/platform/WebCrypto.h" | 8 #include "public/platform/WebCrypto.h" |
9 #include "public/platform/WebCryptoAlgorithm.h" | 9 #include "public/platform/WebCryptoAlgorithm.h" |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 static WebCryptoAlgorithmId ToWebCryptoAlgorithmId(HashAlgorithm algorithm) { | 14 static WebCryptoAlgorithmId ToWebCryptoAlgorithmId(HashAlgorithm algorithm) { |
15 switch (algorithm) { | 15 switch (algorithm) { |
16 case kHashAlgorithmSha1: | 16 case kHashAlgorithmSha1: |
17 return kWebCryptoAlgorithmIdSha1; | 17 return kWebCryptoAlgorithmIdSha1; |
18 case kHashAlgorithmSha256: | 18 case kHashAlgorithmSha256: |
19 return kWebCryptoAlgorithmIdSha256; | 19 return kWebCryptoAlgorithmIdSha256; |
20 case kHashAlgorithmSha384: | 20 case kHashAlgorithmSha384: |
21 return kWebCryptoAlgorithmIdSha384; | 21 return kWebCryptoAlgorithmIdSha384; |
22 case kHashAlgorithmSha512: | 22 case kHashAlgorithmSha512: |
23 return kWebCryptoAlgorithmIdSha512; | 23 return kWebCryptoAlgorithmIdSha512; |
24 }; | 24 }; |
25 | 25 |
26 ASSERT_NOT_REACHED(); | 26 NOTREACHED(); |
27 return kWebCryptoAlgorithmIdSha256; | 27 return kWebCryptoAlgorithmIdSha256; |
28 } | 28 } |
29 | 29 |
30 bool ComputeDigest(HashAlgorithm algorithm, | 30 bool ComputeDigest(HashAlgorithm algorithm, |
31 const char* digestable, | 31 const char* digestable, |
32 size_t length, | 32 size_t length, |
33 DigestValue& digest_result) { | 33 DigestValue& digest_result) { |
34 WebCryptoAlgorithmId algorithm_id = ToWebCryptoAlgorithmId(algorithm); | 34 WebCryptoAlgorithmId algorithm_id = ToWebCryptoAlgorithmId(algorithm); |
35 WebCrypto* crypto = Platform::Current()->Crypto(); | 35 WebCrypto* crypto = Platform::Current()->Crypto(); |
36 unsigned char* result; | 36 unsigned char* result; |
(...skipping 24 matching lines...) Expand all Loading... |
61 | 61 |
62 if (!digestor->Finish(result, result_size)) | 62 if (!digestor->Finish(result, result_size)) |
63 return; | 63 return; |
64 | 64 |
65 ASSERT(result); | 65 ASSERT(result); |
66 | 66 |
67 digest_result.Append(static_cast<uint8_t*>(result), result_size); | 67 digest_result.Append(static_cast<uint8_t*>(result), result_size); |
68 } | 68 } |
69 | 69 |
70 } // namespace blink | 70 } // namespace blink |
OLD | NEW |