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 #ifdef WEBCRYPTO_DIGEST_LENGTH_IS_UINT | 17 #ifdef WEBCRYPTO_DIGEST_LENGTH_IS_UINT |
15 unsigned data_size, | 18 unsigned data_size, |
16 #else | 19 #else |
17 size_t data_size, | 20 size_t data_size, |
18 #endif | 21 #endif |
19 WebKit::WebCryptoResult result) { | 22 WebKit::WebCryptoResult result) { |
20 WebKit::WebArrayBuffer buffer; | 23 WebKit::WebArrayBuffer buffer; |
21 if (!DigestInternal(algorithm, data, data_size, &buffer)) { | 24 if (!DigestInternal(algorithm, data, data_size, &buffer)) { |
22 result.completeWithError(); | 25 result.completeWithError(); |
23 } else { | 26 } else { |
24 result.completeWithBuffer(buffer); | 27 result.completeWithBuffer(buffer); |
25 } | 28 } |
26 } | 29 } |
27 | 30 |
| 31 void WebCryptoImpl::importKey( |
| 32 WebKit::WebCryptoKeyFormat format, |
| 33 const unsigned char* key_data, |
| 34 unsigned key_data_size, |
| 35 const WebKit::WebCryptoAlgorithm& algorithm, |
| 36 bool extractable, |
| 37 WebKit::WebCryptoKeyUsageMask usage_mask, |
| 38 WebKit::WebCryptoResult result) { |
| 39 WebKit::WebCryptoKeyType type; |
| 40 scoped_ptr<WebKit::WebCryptoKeyHandle> handle; |
| 41 |
| 42 if (!ImportKeyInternal(format, |
| 43 key_data, |
| 44 key_data_size, |
| 45 algorithm, |
| 46 usage_mask, |
| 47 &handle, |
| 48 &type)) { |
| 49 result.completeWithError(); |
| 50 return; |
| 51 } |
| 52 |
| 53 WebKit::WebCryptoKey key( |
| 54 WebKit::WebCryptoKey::create( |
| 55 handle.release(), type, extractable, algorithm, usage_mask)); |
| 56 |
| 57 result.completeWithKey(key); |
| 58 } |
| 59 |
| 60 void WebCryptoImpl::sign( |
| 61 const WebKit::WebCryptoAlgorithm& algorithm, |
| 62 const WebKit::WebCryptoKey& key, |
| 63 const unsigned char* data, |
| 64 unsigned data_size, |
| 65 WebKit::WebCryptoResult result) { |
| 66 WebKit::WebArrayBuffer buffer; |
| 67 if (!SignInternal(algorithm, key.handle(), data, data_size, &buffer)) { |
| 68 result.completeWithError(); |
| 69 } else { |
| 70 result.completeWithBuffer(buffer); |
| 71 } |
| 72 } |
| 73 |
28 } // namespace content | 74 } // namespace content |
OLD | NEW |