Chromium Code Reviews| 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..c86ccd3781206234efec9346ac2eb6ae48d26947 100644 |
| --- a/content/child/webcrypto/algorithm_dispatch.cc |
| +++ b/content/child/webcrypto/algorithm_dispatch.cc |
| @@ -8,6 +8,7 @@ |
| #include "content/child/webcrypto/algorithm_implementation.h" |
| #include "content/child/webcrypto/algorithm_registry.h" |
| #include "content/child/webcrypto/crypto_data.h" |
| +#include "content/child/webcrypto/generate_key_result.h" |
| #include "content/child/webcrypto/platform_crypto.h" |
| #include "content/child/webcrypto/status.h" |
| #include "content/child/webcrypto/webcrypto_util.h" |
| @@ -111,7 +112,30 @@ 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.IsError()) |
| + return status; |
| + |
| + const blink::WebCryptoKey* key = NULL; |
| + 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 == NULL) |
| + return Status::ErrorUnexpected(); |
| + |
| + // This should only fail if an algorithm is implemented incorrectly and |
| + // does not do its own check of the usages. |
| + if (key->usages() == 0) { |
| + DCHECK(false) << "Key usages for generateKey() must not be empty"; |
| + |
| + // Even though this is unexpected, I chose not to use |
|
eroman
2014/12/05 23:49:48
Remove this comment. "I" will become unclear over
nharper
2014/12/05 23:58:08
Done.
|
| + // Status::ErrorUnexpected() so that we can present a better error to the |
| + // user. |
| + // TODO(nharper): This should be instrumented with http://crbug.com/428806 |
| + return Status::ErrorCreateKeyEmptyUsages(); |
| + } |
| + return status; |
| } |
| Status ImportKey(blink::WebCryptoKeyFormat format, |