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, |