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

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: Address sleevi comments and make NullKey() work in debug mode 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..9275783bab77ce6fcec25fb69656a4203c834a7d 100644
--- a/content/renderer/webcrypto/webcrypto_impl.cc
+++ b/content/renderer/webcrypto/webcrypto_impl.cc
@@ -34,12 +34,23 @@ void WebCryptoImpl::ShrinkBuffer(
*buffer = new_buffer;
}
+// static
+// TODO(eroman): Expose functionality in Blink instead.
+WebKit::WebCryptoKey WebCryptoImpl::NullKey() {
+ // Needs a non-null algorithm to succeed.
+ return WebKit::WebCryptoKey::create(
+ NULL, WebKit::WebCryptoKeyTypeSecret, false,
+ WebKit::WebCryptoAlgorithm::adoptParamsAndCreate(
+ WebKit::WebCryptoAlgorithmIdAesGcm, NULL), 0);
+}
+
void WebCryptoImpl::encrypt(
const WebKit::WebCryptoAlgorithm& algorithm,
const WebKit::WebCryptoKey& key,
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 +65,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 +79,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();
@@ -77,17 +90,18 @@ void WebCryptoImpl::digest(
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)) {
+ DCHECK(!algorithm.isNull());
+ WebKit::WebCryptoKey key = NullKey();
+ if (!GenerateKeyInternal(algorithm, extractable, usage_mask, &key)) {
result.completeWithError();
} else {
- WebKit::WebCryptoKey key(
- WebKit::WebCryptoKey::create(handle.release(), type, exportable,
- algorithm, usage));
+ DCHECK(key.handle());
+ DCHECK_EQ(algorithm.id(), key.algorithm().id());
+ DCHECK_EQ(extractable, key.extractable());
+ DCHECK_EQ(usage_mask, key.usages());
result.completeWithKey(key);
}
}
@@ -96,28 +110,24 @@ 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;
-
+ WebKit::WebCryptoKey key = NullKey();
if (!ImportKeyInternal(format,
key_data,
key_data_size,
- algorithm,
+ algorithm_or_null,
+ extractable,
usage_mask,
- &handle,
- &type)) {
+ &key)) {
result.completeWithError();
return;
}
-
- WebKit::WebCryptoKey key(
- WebKit::WebCryptoKey::create(
- handle.release(), type, extractable, algorithm, usage_mask));
-
+ DCHECK(key.handle());
+ DCHECK(!key.algorithm().isNull());
+ DCHECK_EQ(extractable, key.extractable());
result.completeWithKey(key);
}
@@ -127,6 +137,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 +154,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