OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto_impl.h" |
6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" |
7 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 8 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| 9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| 10 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
8 | 11 |
9 namespace content { | 12 namespace content { |
10 | 13 |
11 void WebCryptoImpl::digest( | 14 void WebCryptoImpl::digest( |
12 const WebKit::WebCryptoAlgorithm& algorithm, | 15 const WebKit::WebCryptoAlgorithm& algorithm, |
13 const unsigned char* data, | 16 const unsigned char* data, |
14 size_t data_size, | 17 size_t data_size, |
15 WebKit::WebCryptoResult result) { | 18 WebKit::WebCryptoResult result) { |
16 WebKit::WebArrayBuffer buffer; | 19 WebKit::WebArrayBuffer buffer; |
17 if (!digestInternal(algorithm, data, data_size, &buffer)) { | 20 if (!DigestInternal(algorithm, data, data_size, &buffer)) { |
18 result.completeWithError(); | 21 result.completeWithError(); |
19 } else { | 22 } else { |
20 result.completeWithBuffer(buffer); | 23 result.completeWithBuffer(buffer); |
| 24 } |
| 25 } |
| 26 |
| 27 void WebCryptoImpl::importKey( |
| 28 WebKit::WebCryptoKeyFormat format, |
| 29 const unsigned char* key_data, |
| 30 size_t key_data_size, |
| 31 const WebKit::WebCryptoAlgorithm& algorithm, |
| 32 bool extractable, |
| 33 WebKit::WebCryptoKeyUsageMask usage_mask, |
| 34 WebKit::WebCryptoResult result) { |
| 35 WebKit::WebCryptoKeyType type; |
| 36 scoped_ptr<WebKit::WebCryptoKeyHandle> handle; |
| 37 |
| 38 if (!ImportKeyInternal(format, |
| 39 key_data, |
| 40 key_data_size, |
| 41 algorithm, |
| 42 usage_mask, |
| 43 &handle, |
| 44 &type)) { |
| 45 result.completeWithError(); |
| 46 return; |
| 47 } |
| 48 |
| 49 WebKit::WebCryptoKey key( |
| 50 WebKit::WebCryptoKey::create( |
| 51 handle.release(), type, extractable, algorithm, usage_mask)); |
| 52 |
| 53 result.completeWithKey(key); |
| 54 } |
| 55 |
| 56 void WebCryptoImpl::sign( |
| 57 const WebKit::WebCryptoAlgorithm& algorithm, |
| 58 const WebKit::WebCryptoKey& key, |
| 59 const unsigned char* data, |
| 60 size_t data_size, |
| 61 WebKit::WebCryptoResult result) { |
| 62 WebKit::WebArrayBuffer buffer; |
| 63 if (!SignInternal(algorithm, key.handle(), data, data_size, &buffer)) { |
| 64 result.completeWithError(); |
| 65 } else { |
| 66 result.completeWithBuffer(buffer); |
21 } | 67 } |
22 } | 68 } |
23 | 69 |
24 } // namespace content | 70 } // namespace content |
OLD | NEW |