summaryrefslogtreecommitdiffstats
path: root/content/child/webcrypto/webcrypto_impl.cc
diff options
context:
space:
mode:
authoreroman <eroman@chromium.org>2014-11-26 11:59:53 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-26 20:00:17 +0000
commit1499b4948559e1c3d04beb9980dec9da36f9d4af (patch)
tree4dbc8ff2ba60f3052af6e5232013edfc4801642b /content/child/webcrypto/webcrypto_impl.cc
parent7ef5b365909cb4ad156d515f8b091c7059aba798 (diff)
downloadchromium_src-1499b4948559e1c3d04beb9980dec9da36f9d4af.zip
chromium_src-1499b4948559e1c3d04beb9980dec9da36f9d4af.tar.gz
chromium_src-1499b4948559e1c3d04beb9980dec9da36f9d4af.tar.bz2
Add the method DeriveBits to AlgorithmImplementation.
And wire it up to WebCryptoImplementation. BUG=399093 Review URL: https://codereview.chromium.org/744993002 Cr-Commit-Position: refs/heads/master@{#305863}
Diffstat (limited to 'content/child/webcrypto/webcrypto_impl.cc')
-rw-r--r--content/child/webcrypto/webcrypto_impl.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/content/child/webcrypto/webcrypto_impl.cc b/content/child/webcrypto/webcrypto_impl.cc
index 5b033a5..8efd9de 100644
--- a/content/child/webcrypto/webcrypto_impl.cc
+++ b/content/child/webcrypto/webcrypto_impl.cc
@@ -333,6 +333,23 @@ struct UnwrapKeyState : public BaseState {
blink::WebCryptoKey unwrapped_key;
};
+struct DeriveBitsState : public BaseState {
+ DeriveBitsState(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ const blink::WebCryptoResult& result)
+ : BaseState(result),
+ algorithm(algorithm),
+ base_key(base_key),
+ length_bits(length_bits) {}
+
+ const blink::WebCryptoAlgorithm algorithm;
+ const blink::WebCryptoKey base_key;
+ const unsigned int length_bits;
+
+ std::vector<uint8_t> derived_bytes;
+};
+
// --------------------------------------------------------------------
// Wrapper functions
// --------------------------------------------------------------------
@@ -519,6 +536,22 @@ void DoUnwrapKey(scoped_ptr<UnwrapKeyState> passed_state) {
FROM_HERE, base::Bind(DoUnwrapKeyReply, Passed(&passed_state)));
}
+void DoDeriveBitsReply(scoped_ptr<DeriveBitsState> state) {
+ CompleteWithBufferOrError(state->status, state->derived_bytes,
+ &state->result);
+}
+
+void DoDeriveBits(scoped_ptr<DeriveBitsState> passed_state) {
+ DeriveBitsState* state = passed_state.get();
+ if (state->cancelled())
+ return;
+ state->status =
+ webcrypto::DeriveBits(state->algorithm, state->base_key,
+ state->length_bits, &state->derived_bytes);
+ state->origin_thread->PostTask(
+ FROM_HERE, base::Bind(DoDeriveBitsReply, Passed(&passed_state)));
+}
+
} // namespace
WebCryptoImpl::WebCryptoImpl() {
@@ -670,6 +703,18 @@ void WebCryptoImpl::unwrapKey(
}
}
+void WebCryptoImpl::deriveBits(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ blink::WebCryptoResult result) {
+ scoped_ptr<DeriveBitsState> state(
+ new DeriveBitsState(algorithm, base_key, length_bits, result));
+ if (!CryptoThreadPool::PostTask(FROM_HERE,
+ base::Bind(DoDeriveBits, Passed(&state)))) {
+ CompleteWithThreadPoolError(&result);
+ }
+}
+
blink::WebCryptoDigestor* WebCryptoImpl::createDigestor(
blink::WebCryptoAlgorithmId algorithm_id) {
return webcrypto::CreateDigestor(algorithm_id).release();