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

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

Issue 778543004: Add sanity check to generateKey to make sure usages aren't empty (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
Index: content/child/webcrypto/algorithm_dispatch.cc
diff --git a/content/child/webcrypto/algorithm_dispatch.cc b/content/child/webcrypto/algorithm_dispatch.cc
index 1c9b409ace58e4cf87aa1dfa7014a4e46bb6aec4..e622e925319b2c0985338c90829095aa68132acd 100644
--- a/content/child/webcrypto/algorithm_dispatch.cc
+++ b/content/child/webcrypto/algorithm_dispatch.cc
@@ -111,7 +111,23 @@ Status GenerateKey(const blink::WebCryptoAlgorithm& algorithm,
if (status.IsError())
return status;
- return impl->GenerateKey(algorithm, extractable, usages, result);
+ status = impl->GenerateKey(algorithm, extractable, usages, result);
+ if (status.IsSuccess()) {
eroman 2014/12/05 19:41:55 style: Can you write this in the opposite directio
nharper 2014/12/05 23:15:47 Done.
+ const blink::WebCryptoKey* key = nullptr;
eroman 2014/12/05 19:41:55 Does this compile on all platforms? Not sure that
nharper 2014/12/05 23:15:47 Codesearch shows nullptr used in thousands of plac
+ if (result->type() == GenerateKeyResult::TYPE_SECRET_KEY) {
+ key = &result->secret_key();
+ }
+ if (result->type() == GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR) {
+ key = &result->private_key();
+ }
+ if (key != nullptr) {
+ // This should only fail if an algorithm is implemented incorrectly and
+ // does not do its own check of the usages.
+ DCHECK(key->usages() != 0)
eroman 2014/12/05 20:52:45 also: DCHECK_NE(0, key->usages());
nharper 2014/12/05 23:15:47 Since I need to do other things when the DCHECK co
+ << "Key usages for generateKey() must not be empty";
eroman 2014/12/05 19:41:55 Great. Can you also return an ErrorUnexpected here
nharper 2014/12/05 23:15:47 Done.
+ }
+ }
+ return status;
}
Status ImportKey(blink::WebCryptoKeyFormat format,
« content/child/webcrypto/algorithm_dispatch.h ('K') | « content/child/webcrypto/algorithm_dispatch.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698