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

Side by Side Diff: content/renderer/webcrypto_impl.cc

Issue 23569007: WebCrypto: Implement importKey() and sign() for HMAC in NSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove duplication of usage, fix naming, add length sanity check. Rebase. Created 7 years, 3 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
OLDNEW
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 unsigned data_size, 17 unsigned 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);
21 } 24 }
22 } 25 }
23 26
27 void WebCryptoImpl::importKey(
28 WebKit::WebCryptoKeyFormat format,
29 const unsigned char* key_data,
30 unsigned 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 unsigned data_size,
61 WebKit::WebCryptoResult result) {
62 WebKit::WebArrayBuffer buffer;
63 if (!SignInternal(algorithm, key, data, data_size, &buffer)) {
64 result.completeWithError();
65 } else {
66 result.completeWithBuffer(buffer);
67 }
68 }
69
24 } // namespace content 70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698