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

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

Issue 50173002: [webcrypto] Refactor to allow for unspecified "algorithm" to importKey(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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/renderer/webcrypto/webcrypto_impl.h ('k') | content/renderer/webcrypto/webcrypto_impl_nss.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/webcrypto/webcrypto_impl.cc
diff --git a/content/renderer/webcrypto/webcrypto_impl.cc b/content/renderer/webcrypto/webcrypto_impl.cc
index f2510100eb755c3f7d4b7929c6227a4bb7571a67..8fc0b62abb2d4ddeb679b9cb8adf287d08132ddd 100644
--- a/content/renderer/webcrypto/webcrypto_impl.cc
+++ b/content/renderer/webcrypto/webcrypto_impl.cc
@@ -40,6 +40,7 @@ void WebCryptoImpl::encrypt(
const unsigned char* data,
unsigned data_size,
WebKit::WebCryptoResult result) {
+ DCHECK(!algorithm.isNull());
WebKit::WebArrayBuffer buffer;
if (!EncryptInternal(algorithm, key, data, data_size, &buffer)) {
result.completeWithError();
@@ -54,6 +55,7 @@ void WebCryptoImpl::decrypt(
const unsigned char* data,
unsigned data_size,
WebKit::WebCryptoResult result) {
+ DCHECK(!algorithm.isNull());
WebKit::WebArrayBuffer buffer;
if (!DecryptInternal(algorithm, key, data, data_size, &buffer)) {
result.completeWithError();
@@ -67,6 +69,7 @@ void WebCryptoImpl::digest(
const unsigned char* data,
unsigned data_size,
WebKit::WebCryptoResult result) {
+ DCHECK(!algorithm.isNull());
WebKit::WebArrayBuffer buffer;
if (!DigestInternal(algorithm, data, data_size, &buffer)) {
result.completeWithError();
@@ -75,50 +78,55 @@ void WebCryptoImpl::digest(
}
}
+WebKit::WebCryptoKey NullKey() {
+ // TODO(eroman): Expose this in Blink instead.
+ return WebKit::WebCryptoKey::create(NULL, WebKit::WebCryptoKeyTypeSecret,
+ false,
+ WebKit::WebCryptoAlgorithm::createNull(),
+ 0);
+}
+
void WebCryptoImpl::generateKey(
const WebKit::WebCryptoAlgorithm& algorithm,
- bool exportable,
- WebKit::WebCryptoKeyUsageMask usage,
+ bool extractable,
+ WebKit::WebCryptoKeyUsageMask usage_mask,
WebKit::WebCryptoResult result) {
- scoped_ptr<WebKit::WebCryptoKeyHandle> handle;
- WebKit::WebCryptoKeyType type;
- if (!GenerateKeyInternal(algorithm, &handle, &type)) {
- result.completeWithError();
- } else {
- WebKit::WebCryptoKey key(
- WebKit::WebCryptoKey::create(handle.release(), type, exportable,
- algorithm, usage));
+ DCHECK(!algorithm.isNull());
+ WebKit::WebCryptoKey key = NullKey();
+ if (GenerateKeyInternal(algorithm, extractable, usage_mask, &key)) {
+ DCHECK(key.handle());
+ DCHECK_EQ(algorithm.id(), key.algorithm().id());
+ DCHECK_EQ(extractable, key.extractable());
+ DCHECK_EQ(usage_mask, key.usages());
result.completeWithKey(key);
+ return;
}
+ result.completeWithError();
Ryan Sleevi 2013/10/30 20:55:53 Should you follow the normal error form here? if
eroman 2013/10/30 21:26:21 Done.
}
void WebCryptoImpl::importKey(
WebKit::WebCryptoKeyFormat format,
const unsigned char* key_data,
unsigned key_data_size,
- const WebKit::WebCryptoAlgorithm& algorithm,
+ const WebKit::WebCryptoAlgorithm& algorithm_or_null,
bool extractable,
WebKit::WebCryptoKeyUsageMask usage_mask,
WebKit::WebCryptoResult result) {
- WebKit::WebCryptoKeyType type;
- scoped_ptr<WebKit::WebCryptoKeyHandle> handle;
-
- if (!ImportKeyInternal(format,
- key_data,
- key_data_size,
- algorithm,
- usage_mask,
- &handle,
- &type)) {
- result.completeWithError();
+ WebKit::WebCryptoKey key = NullKey();
+ if (ImportKeyInternal(format,
+ key_data,
+ key_data_size,
+ algorithm_or_null,
+ extractable,
+ usage_mask,
+ &key)) {
+ DCHECK(key.handle());
+ DCHECK(!key.algorithm().isNull());
+ DCHECK_EQ(extractable, key.extractable());
+ result.completeWithKey(key);
return;
}
-
- WebKit::WebCryptoKey key(
- WebKit::WebCryptoKey::create(
- handle.release(), type, extractable, algorithm, usage_mask));
-
- result.completeWithKey(key);
+ result.completeWithError();
Ryan Sleevi 2013/10/30 20:55:53 ditto. Why change from the original form?
eroman 2013/10/30 21:26:21 Done.
}
void WebCryptoImpl::sign(
@@ -127,6 +135,7 @@ void WebCryptoImpl::sign(
const unsigned char* data,
unsigned data_size,
WebKit::WebCryptoResult result) {
+ DCHECK(!algorithm.isNull());
WebKit::WebArrayBuffer buffer;
if (!SignInternal(algorithm, key, data, data_size, &buffer)) {
result.completeWithError();
@@ -143,6 +152,7 @@ void WebCryptoImpl::verifySignature(
const unsigned char* data,
unsigned data_size,
WebKit::WebCryptoResult result) {
+ DCHECK(!algorithm.isNull());
bool signature_match = false;
if (!VerifySignatureInternal(algorithm,
key,
« no previous file with comments | « content/renderer/webcrypto/webcrypto_impl.h ('k') | content/renderer/webcrypto/webcrypto_impl_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698