Chromium Code Reviews| 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 "third_party/WebKit/public/platform/WebArrayBuffer.h" | 7 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| 8 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | |
| 9 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | |
| 8 | 10 |
| 9 namespace content { | 11 namespace content { |
| 10 | 12 |
| 11 void WebCryptoImpl::digest( | 13 void WebCryptoImpl::digest( |
| 12 const WebKit::WebCryptoAlgorithm& algorithm, | 14 const WebKit::WebCryptoAlgorithm& algorithm, |
| 13 const unsigned char* data, | 15 const unsigned char* data, |
| 14 size_t data_size, | 16 size_t data_size, |
| 15 WebKit::WebCryptoResult result) { | 17 WebKit::WebCryptoResult result) { |
| 16 WebKit::WebArrayBuffer buffer; | 18 WebKit::WebArrayBuffer buffer; |
| 17 if (!digestInternal(algorithm, data, data_size, &buffer)) { | 19 if (!digestInternal(algorithm, data, data_size, &buffer)) { |
| 18 result.completeWithError(); | 20 result.completeWithError(); |
| 19 } else { | 21 } else { |
| 20 result.completeWithBuffer(buffer); | 22 result.completeWithBuffer(buffer); |
| 21 } | 23 } |
| 22 } | 24 } |
| 23 | 25 |
| 26 void WebCryptoImpl::importKey( | |
| 27 WebKit::WebCryptoKeyFormat format, | |
| 28 const unsigned char* key_data, | |
| 29 size_t key_data_size, | |
| 30 const WebKit::WebCryptoAlgorithm& algorithm, | |
| 31 bool extractable, | |
| 32 WebKit::WebCryptoKeyUsageMask usage_mask, | |
| 33 WebKit::WebCryptoResult result) { | |
| 34 WebKit::WebCryptoKeyType type; | |
| 35 switch (algorithm.id()) { | |
| 36 case WebKit::WebCryptoAlgorithmIdHmac: | |
| 37 type = WebKit::WebCryptoKeyTypeSecret; | |
|
eroman
2013/09/05 01:57:51
For the future, we are better off having the "type
Bryan Eyler
2013/09/06 01:27:51
Done.
| |
| 38 break; | |
| 39 default: | |
| 40 result.completeWithError(); | |
| 41 return; | |
| 42 } | |
| 43 | |
| 44 WebKit::WebCryptoKeyHandle* handle; | |
| 45 if (!importKeyInternal(format, | |
| 46 key_data, | |
| 47 key_data_size, | |
| 48 algorithm, | |
| 49 extractable, | |
| 50 usage_mask, | |
| 51 &handle)) { | |
| 52 result.completeWithError(); | |
|
eroman
2013/09/05 01:57:51
You need a return statement after this
Bryan Eyler
2013/09/06 01:27:51
Done.
| |
| 53 } | |
| 54 | |
| 55 WebKit::WebCryptoKey key( | |
| 56 WebKit::WebCryptoKey::create( | |
| 57 handle, type, extractable, algorithm, usage_mask)); | |
| 58 | |
| 59 result.completeWithKey(key); | |
| 60 } | |
| 61 | |
| 62 void WebCryptoImpl::sign( | |
| 63 const WebKit::WebCryptoAlgorithm& algorithm, | |
| 64 const WebKit::WebCryptoKey& key, | |
| 65 const unsigned char* data, | |
| 66 size_t data_size, | |
| 67 WebKit::WebCryptoResult result) { | |
| 68 WebKit::WebArrayBuffer buffer; | |
| 69 if (!signInternal(algorithm, key.handle(), data, data_size, &buffer)) { | |
| 70 result.completeWithError(); | |
| 71 } else { | |
| 72 result.completeWithBuffer(buffer); | |
| 73 } | |
| 74 } | |
| 75 | |
| 24 } // namespace content | 76 } // namespace content |
| OLD | NEW |