summaryrefslogtreecommitdiffstats
path: root/content/child/webcrypto/webcrypto_impl.cc
diff options
context:
space:
mode:
authoreroman <eroman@chromium.org>2014-12-12 09:22:37 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-12 17:22:55 +0000
commit20bf4c3c8f6c408cd2214d76e57265d424dae13e (patch)
treeccc82acb57ee295cfbe95363217a45c0aa26e6ca /content/child/webcrypto/webcrypto_impl.cc
parentbd52a8a1d59abc3e9fab7856655a8d6dee8fa90b (diff)
downloadchromium_src-20bf4c3c8f6c408cd2214d76e57265d424dae13e.zip
chromium_src-20bf4c3c8f6c408cd2214d76e57265d424dae13e.tar.gz
chromium_src-20bf4c3c8f6c408cd2214d76e57265d424dae13e.tar.bz2
WebCrypto: Implement crypto.subtle.deriveKey (chromium-side).
BUG=437577 Review URL: https://codereview.chromium.org/749183004 Cr-Commit-Position: refs/heads/master@{#308110}
Diffstat (limited to 'content/child/webcrypto/webcrypto_impl.cc')
-rw-r--r--content/child/webcrypto/webcrypto_impl.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/content/child/webcrypto/webcrypto_impl.cc b/content/child/webcrypto/webcrypto_impl.cc
index 8efd9de..9a3924b 100644
--- a/content/child/webcrypto/webcrypto_impl.cc
+++ b/content/child/webcrypto/webcrypto_impl.cc
@@ -350,6 +350,32 @@ struct DeriveBitsState : public BaseState {
std::vector<uint8_t> derived_bytes;
};
+struct DeriveKeyState : public BaseState {
+ DeriveKeyState(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ const blink::WebCryptoAlgorithm& import_algorithm,
+ const blink::WebCryptoAlgorithm& key_length_algorithm,
+ bool extractable,
+ blink::WebCryptoKeyUsageMask usages,
+ const blink::WebCryptoResult& result)
+ : BaseState(result),
+ algorithm(algorithm),
+ base_key(base_key),
+ import_algorithm(import_algorithm),
+ key_length_algorithm(key_length_algorithm),
+ extractable(extractable),
+ usages(usages) {}
+
+ const blink::WebCryptoAlgorithm algorithm;
+ const blink::WebCryptoKey base_key;
+ const blink::WebCryptoAlgorithm import_algorithm;
+ const blink::WebCryptoAlgorithm key_length_algorithm;
+ bool extractable;
+ blink::WebCryptoKeyUsageMask usages;
+
+ blink::WebCryptoKey derived_key;
+};
+
// --------------------------------------------------------------------
// Wrapper functions
// --------------------------------------------------------------------
@@ -552,6 +578,22 @@ void DoDeriveBits(scoped_ptr<DeriveBitsState> passed_state) {
FROM_HERE, base::Bind(DoDeriveBitsReply, Passed(&passed_state)));
}
+void DoDeriveKeyReply(scoped_ptr<DeriveKeyState> state) {
+ CompleteWithKeyOrError(state->status, state->derived_key, &state->result);
+}
+
+void DoDeriveKey(scoped_ptr<DeriveKeyState> passed_state) {
+ DeriveKeyState* state = passed_state.get();
+ if (state->cancelled())
+ return;
+ state->status = webcrypto::DeriveKey(
+ state->algorithm, state->base_key, state->import_algorithm,
+ state->key_length_algorithm, state->extractable, state->usages,
+ &state->derived_key);
+ state->origin_thread->PostTask(
+ FROM_HERE, base::Bind(DoDeriveKeyReply, Passed(&passed_state)));
+}
+
} // namespace
WebCryptoImpl::WebCryptoImpl() {
@@ -715,6 +757,23 @@ void WebCryptoImpl::deriveBits(const blink::WebCryptoAlgorithm& algorithm,
}
}
+void WebCryptoImpl::deriveKey(
+ const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ const blink::WebCryptoAlgorithm& import_algorithm,
+ const blink::WebCryptoAlgorithm& key_length_algorithm,
+ bool extractable,
+ blink::WebCryptoKeyUsageMask usages,
+ blink::WebCryptoResult result) {
+ scoped_ptr<DeriveKeyState> state(
+ new DeriveKeyState(algorithm, base_key, import_algorithm,
+ key_length_algorithm, extractable, usages, result));
+ if (!CryptoThreadPool::PostTask(FROM_HERE,
+ base::Bind(DoDeriveKey, Passed(&state)))) {
+ CompleteWithThreadPoolError(&result);
+ }
+}
+
blink::WebCryptoDigestor* WebCryptoImpl::createDigestor(
blink::WebCryptoAlgorithmId algorithm_id) {
return webcrypto::CreateDigestor(algorithm_id).release();