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

Side by Side Diff: content/child/webcrypto/webcrypto_impl.cc

Issue 379383002: Refactor WebCrypto code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase onto master (no longer has BoringSSL) Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « content/child/webcrypto/webcrypto_impl.h ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/child/webcrypto/webcrypto_impl.h" 5 #include "content/child/webcrypto/webcrypto_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/task_runner.h" 13 #include "base/task_runner.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/threading/worker_pool.h" 16 #include "base/threading/worker_pool.h"
17 #include "content/child/webcrypto/algorithm_dispatch.h"
17 #include "content/child/webcrypto/crypto_data.h" 18 #include "content/child/webcrypto/crypto_data.h"
18 #include "content/child/webcrypto/shared_crypto.h"
19 #include "content/child/webcrypto/status.h" 19 #include "content/child/webcrypto/status.h"
20 #include "content/child/webcrypto/structured_clone.h"
20 #include "content/child/webcrypto/webcrypto_util.h" 21 #include "content/child/webcrypto/webcrypto_util.h"
21 #include "content/child/worker_thread_task_runner.h" 22 #include "content/child/worker_thread_task_runner.h"
22 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 23 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
23 #include "third_party/WebKit/public/platform/WebString.h" 24 #include "third_party/WebKit/public/platform/WebString.h"
24 25
25 namespace content { 26 namespace content {
26 27
27 using webcrypto::Status; 28 using webcrypto::Status;
28 29
29 namespace { 30 namespace {
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 CompleteWithError(state->status, &state->result); 519 CompleteWithError(state->status, &state->result);
519 } else { 520 } else {
520 state->result.completeWithBoolean(state->verify_result); 521 state->result.completeWithBoolean(state->verify_result);
521 } 522 }
522 } 523 }
523 524
524 void DoVerify(scoped_ptr<VerifySignatureState> passed_state) { 525 void DoVerify(scoped_ptr<VerifySignatureState> passed_state) {
525 VerifySignatureState* state = passed_state.get(); 526 VerifySignatureState* state = passed_state.get();
526 if (state->cancelled()) 527 if (state->cancelled())
527 return; 528 return;
528 state->status = 529 state->status = webcrypto::Verify(state->algorithm,
529 webcrypto::VerifySignature(state->algorithm, 530 state->key,
530 state->key, 531 webcrypto::CryptoData(state->signature),
531 webcrypto::CryptoData(state->signature), 532 webcrypto::CryptoData(state->data),
532 webcrypto::CryptoData(state->data), 533 &state->verify_result);
533 &state->verify_result);
534 534
535 state->origin_thread->PostTask( 535 state->origin_thread->PostTask(
536 FROM_HERE, base::Bind(DoVerifyReply, Passed(&passed_state))); 536 FROM_HERE, base::Bind(DoVerifyReply, Passed(&passed_state)));
537 } 537 }
538 538
539 void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) { 539 void DoWrapKeyReply(scoped_ptr<WrapKeyState> state) {
540 CompleteWithBufferOrError(state->status, state->buffer, &state->result); 540 CompleteWithBufferOrError(state->status, state->buffer, &state->result);
541 } 541 }
542 542
543 void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) { 543 void DoWrapKey(scoped_ptr<WrapKeyState> passed_state) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 } 577 }
578 578
579 } // namespace 579 } // namespace
580 580
581 WebCryptoImpl::WebCryptoImpl() { 581 WebCryptoImpl::WebCryptoImpl() {
582 } 582 }
583 583
584 WebCryptoImpl::~WebCryptoImpl() { 584 WebCryptoImpl::~WebCryptoImpl() {
585 } 585 }
586 586
587 void WebCryptoImpl::EnsureInit() {
588 webcrypto::Init();
589 }
590
591 void WebCryptoImpl::encrypt(const blink::WebCryptoAlgorithm& algorithm, 587 void WebCryptoImpl::encrypt(const blink::WebCryptoAlgorithm& algorithm,
592 const blink::WebCryptoKey& key, 588 const blink::WebCryptoKey& key,
593 const unsigned char* data, 589 const unsigned char* data,
594 unsigned int data_size, 590 unsigned int data_size,
595 blink::WebCryptoResult result) { 591 blink::WebCryptoResult result) {
596 DCHECK(!algorithm.isNull()); 592 DCHECK(!algorithm.isNull());
597 593
598 scoped_ptr<EncryptState> state( 594 scoped_ptr<EncryptState> state(
599 new EncryptState(algorithm, key, data, data_size, result)); 595 new EncryptState(algorithm, key, data, data_size, result));
600 if (!CryptoThreadPool::PostTask(FROM_HERE, 596 if (!CryptoThreadPool::PostTask(FROM_HERE,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 &key); 762 &key);
767 } 763 }
768 764
769 bool WebCryptoImpl::serializeKeyForClone( 765 bool WebCryptoImpl::serializeKeyForClone(
770 const blink::WebCryptoKey& key, 766 const blink::WebCryptoKey& key,
771 blink::WebVector<unsigned char>& key_data) { 767 blink::WebVector<unsigned char>& key_data) {
772 return webcrypto::SerializeKeyForClone(key, &key_data); 768 return webcrypto::SerializeKeyForClone(key, &key_data);
773 } 769 }
774 770
775 } // namespace content 771 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/webcrypto_impl.h ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698