Chromium Code Reviews| 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..7c56252fad0647937d59910cc3230f06b64127d5 100644 |
| --- a/content/renderer/webcrypto/webcrypto_impl.cc |
| +++ b/content/renderer/webcrypto/webcrypto_impl.cc |
| @@ -12,6 +12,19 @@ |
| namespace content { |
| +namespace { |
| + |
| +bool IsAlgorithmAsymmetric(const WebKit::WebCryptoAlgorithm& algorithm) { |
| + const WebKit::WebCryptoAlgorithmId algorithm_id = algorithm.id(); |
| + // TODO: include all other asymmetric algorithms once they are defined, |
|
eroman
2013/10/23 20:02:46
nit: use the format TODO(padolph):
This doesn't m
padolph
2013/10/23 23:21:47
Done.
|
| + // e.g. EC and DH. |
| + return (algorithm_id == WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 || |
| + algorithm_id == WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
| + algorithm_id == WebKit::WebCryptoAlgorithmIdRsaOaep); |
| +} |
| + |
| +} // namespace |
| + |
| WebCryptoImpl::WebCryptoImpl() { |
| Init(); |
| } |
| @@ -80,15 +93,40 @@ void WebCryptoImpl::generateKey( |
| bool exportable, |
| WebKit::WebCryptoKeyUsageMask usage, |
| 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)); |
| - result.completeWithKey(key); |
| + if (IsAlgorithmAsymmetric(algorithm)) { |
| + scoped_ptr<WebKit::WebCryptoKeyHandle> public_key_handle; |
| + scoped_ptr<WebKit::WebCryptoKeyHandle> private_key_handle; |
| + if (!GenerateKeyPairInternal(algorithm, |
| + &public_key_handle, |
| + &private_key_handle)) { |
| + result.completeWithError(); |
|
eroman
2013/10/23 20:02:46
I think the structure of this function would be mo
padolph
2013/10/23 23:21:47
Agreed for the error cases. But do you also want t
|
| + } else { |
| + WebKit::WebCryptoKey public_key( |
| + WebKit::WebCryptoKey::create(public_key_handle.release(), |
| + WebKit::WebCryptoKeyTypePublic, |
| + exportable, |
| + algorithm, |
| + usage)); |
| + WebKit::WebCryptoKey private_key( |
| + WebKit::WebCryptoKey::create(private_key_handle.release(), |
| + WebKit::WebCryptoKeyTypePrivate, |
| + exportable, |
| + algorithm, |
| + usage)); |
| + result.completeWithKeyPair(public_key, private_key); |
| + } |
| + } |
| + else { |
| + 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)); |
| + result.completeWithKey(key); |
| + } |
| } |
| } |