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

Unified Diff: content/child/webcrypto/webcrypto_impl.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/webcrypto/test/test_helpers.cc ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/webcrypto_impl.cc
diff --git a/content/child/webcrypto/webcrypto_impl.cc b/content/child/webcrypto/webcrypto_impl.cc
index e367ae641b011de7ad3a5c2197f8d5bb392b38ba..418c0f81f2bd9f8abdb0c46ef3a94f2358a67441 100644
--- a/content/child/webcrypto/webcrypto_impl.cc
+++ b/content/child/webcrypto/webcrypto_impl.cc
@@ -17,6 +17,7 @@
#include "base/threading/worker_pool.h"
#include "content/child/webcrypto/algorithm_dispatch.h"
#include "content/child/webcrypto/crypto_data.h"
+#include "content/child/webcrypto/generate_key_result.h"
#include "content/child/webcrypto/status.h"
#include "content/child/webcrypto/structured_clone.h"
#include "content/child/webcrypto/webcrypto_util.h"
@@ -215,20 +216,13 @@ struct GenerateKeyState : public BaseState {
: BaseState(result),
algorithm(algorithm),
extractable(extractable),
- usage_mask(usage_mask),
- public_key(blink::WebCryptoKey::createNull()),
- private_key(blink::WebCryptoKey::createNull()),
- is_asymmetric(false) {}
+ usage_mask(usage_mask) {}
const blink::WebCryptoAlgorithm algorithm;
const bool extractable;
const blink::WebCryptoKeyUsageMask usage_mask;
- // If |is_asymmetric| is false, then |public_key| is understood to mean the
- // symmetric key, and |private_key| is unused.
- blink::WebCryptoKey public_key;
- blink::WebCryptoKey private_key;
- bool is_asymmetric;
+ webcrypto::GenerateKeyResult generate_key_result;
};
struct ImportKeyState : public BaseState {
@@ -401,10 +395,7 @@ void DoGenerateKeyReply(scoped_ptr<GenerateKeyState> state) {
if (state->status.IsError()) {
CompleteWithError(state->status, &state->result);
} else {
- if (state->is_asymmetric)
- state->result.completeWithKeyPair(state->public_key, state->private_key);
- else
- state->result.completeWithKey(state->public_key);
+ state->generate_key_result.Complete(&state->result);
}
}
@@ -412,37 +403,10 @@ void DoGenerateKey(scoped_ptr<GenerateKeyState> passed_state) {
GenerateKeyState* state = passed_state.get();
if (state->cancelled())
return;
- state->is_asymmetric =
- webcrypto::IsAlgorithmAsymmetric(state->algorithm.id());
- if (state->is_asymmetric) {
- state->status = webcrypto::GenerateKeyPair(state->algorithm,
- state->extractable,
- state->usage_mask,
- &state->public_key,
- &state->private_key);
-
- if (state->status.IsSuccess()) {
- DCHECK(state->public_key.handle());
- DCHECK(state->private_key.handle());
- DCHECK_EQ(state->algorithm.id(), state->public_key.algorithm().id());
- DCHECK_EQ(state->algorithm.id(), state->private_key.algorithm().id());
- DCHECK_EQ(true, state->public_key.extractable());
- DCHECK_EQ(state->extractable, state->private_key.extractable());
- }
- } else {
- blink::WebCryptoKey* key = &state->public_key;
-
- state->status = webcrypto::GenerateSecretKey(
- state->algorithm, state->extractable, state->usage_mask, key);
-
- if (state->status.IsSuccess()) {
- DCHECK(key->handle());
- DCHECK_EQ(state->algorithm.id(), key->algorithm().id());
- DCHECK_EQ(state->extractable, key->extractable());
- DCHECK_EQ(state->usage_mask, key->usages());
- }
- }
-
+ state->status = webcrypto::GenerateKey(state->algorithm,
+ state->extractable,
+ state->usage_mask,
+ &state->generate_key_result);
state->origin_thread->PostTask(
FROM_HERE, base::Bind(DoGenerateKeyReply, Passed(&passed_state)));
}
« no previous file with comments | « content/child/webcrypto/test/test_helpers.cc ('k') | content/child/webcrypto/webcrypto_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698