| OLD | NEW |
| 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" | |
| 18 #include "content/child/webcrypto/crypto_data.h" | 17 #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" | |
| 21 #include "content/child/webcrypto/webcrypto_util.h" | 20 #include "content/child/webcrypto/webcrypto_util.h" |
| 22 #include "content/child/worker_thread_task_runner.h" | 21 #include "content/child/worker_thread_task_runner.h" |
| 23 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 22 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
| 24 #include "third_party/WebKit/public/platform/WebString.h" | 23 #include "third_party/WebKit/public/platform/WebString.h" |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 | 26 |
| 28 using webcrypto::Status; | 27 using webcrypto::Status; |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 CompleteWithError(state->status, &state->result); | 518 CompleteWithError(state->status, &state->result); |
| 520 } else { | 519 } else { |
| 521 state->result.completeWithBoolean(state->verify_result); | 520 state->result.completeWithBoolean(state->verify_result); |
| 522 } | 521 } |
| 523 } | 522 } |
| 524 | 523 |
| 525 void DoVerify(scoped_ptr<VerifySignatureState> passed_state) { | 524 void DoVerify(scoped_ptr<VerifySignatureState> passed_state) { |
| 526 VerifySignatureState* state = passed_state.get(); | 525 VerifySignatureState* state = passed_state.get(); |
| 527 if (state->cancelled()) | 526 if (state->cancelled()) |
| 528 return; | 527 return; |
| 529 state->status = webcrypto::Verify(state->algorithm, | 528 state->status = |
| 530 state->key, | 529 webcrypto::VerifySignature(state->algorithm, |
| 531 webcrypto::CryptoData(state->signature), | 530 state->key, |
| 532 webcrypto::CryptoData(state->data), | 531 webcrypto::CryptoData(state->signature), |
| 533 &state->verify_result); | 532 webcrypto::CryptoData(state->data), |
| 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 Loading... |
| 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 |
| 587 void WebCryptoImpl::encrypt(const blink::WebCryptoAlgorithm& algorithm, | 591 void WebCryptoImpl::encrypt(const blink::WebCryptoAlgorithm& algorithm, |
| 588 const blink::WebCryptoKey& key, | 592 const blink::WebCryptoKey& key, |
| 589 const unsigned char* data, | 593 const unsigned char* data, |
| 590 unsigned int data_size, | 594 unsigned int data_size, |
| 591 blink::WebCryptoResult result) { | 595 blink::WebCryptoResult result) { |
| 592 DCHECK(!algorithm.isNull()); | 596 DCHECK(!algorithm.isNull()); |
| 593 | 597 |
| 594 scoped_ptr<EncryptState> state( | 598 scoped_ptr<EncryptState> state( |
| 595 new EncryptState(algorithm, key, data, data_size, result)); | 599 new EncryptState(algorithm, key, data, data_size, result)); |
| 596 if (!CryptoThreadPool::PostTask(FROM_HERE, | 600 if (!CryptoThreadPool::PostTask(FROM_HERE, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 &key); | 766 &key); |
| 763 } | 767 } |
| 764 | 768 |
| 765 bool WebCryptoImpl::serializeKeyForClone( | 769 bool WebCryptoImpl::serializeKeyForClone( |
| 766 const blink::WebCryptoKey& key, | 770 const blink::WebCryptoKey& key, |
| 767 blink::WebVector<unsigned char>& key_data) { | 771 blink::WebVector<unsigned char>& key_data) { |
| 768 return webcrypto::SerializeKeyForClone(key, &key_data); | 772 return webcrypto::SerializeKeyForClone(key, &key_data); |
| 769 } | 773 } |
| 770 | 774 |
| 771 } // namespace content | 775 } // namespace content |
| OLD | NEW |