Chromium Code Reviews| Index: content/renderer/webcrypto/webcrypto_impl_nss.cc |
| diff --git a/content/renderer/webcrypto/webcrypto_impl_nss.cc b/content/renderer/webcrypto/webcrypto_impl_nss.cc |
| index 73319df1a78b837fa4c7a93a762d6307cd06e3f8..3eb385d3ce192652d48b0d76aefb16f7cc0577cc 100644 |
| --- a/content/renderer/webcrypto/webcrypto_impl_nss.cc |
| +++ b/content/renderer/webcrypto/webcrypto_impl_nss.cc |
| @@ -325,6 +325,31 @@ bool ImportKeyInternalRaw( |
| return true; |
| } |
| +bool ExportKeyInternalRaw( |
| + const blink::WebCryptoKey& key, |
| + blink::WebArrayBuffer* buffer) { |
| + |
| + DCHECK(key.handle()); |
| + DCHECK(buffer); |
| + |
| + if (key.type() != blink::WebCryptoKeyTypeSecret || !key.extractable()) |
| + return false; |
| + |
| + SymKeyHandle* const sym_key = reinterpret_cast<SymKeyHandle*>(key.handle()); |
|
eroman
2013/12/05 01:47:53
I don't see any value in making the pointer "const
padolph
2013/12/05 02:45:57
The Scott Meyers books trained me to make as much
|
| + |
| + if (PK11_ExtractKeyValue(sym_key->key()) != SECSuccess) |
| + return false; |
| + |
| + SECItem* const key_data = PK11_GetKeyData(sym_key->key()); |
|
eroman
2013/12/05 01:47:53
It is uncommon in chromium code to make the pointe
padolph
2013/12/05 02:45:57
Done.
|
| + if (!key_data) |
| + return false; |
| + DCHECK(key_data->data); |
|
eroman
2013/12/05 01:47:53
Would it ever be possible for key_data->len to be
padolph
2013/12/05 02:45:57
Yes. Empty symmetric keys are possible and already
|
| + |
| + *buffer = webcrypto::CreateArrayBuffer(key_data->data, key_data->len); |
| + |
| + return true; |
| +} |
| + |
| typedef scoped_ptr<CERTSubjectPublicKeyInfo, |
| crypto::NSSDestroyer<CERTSubjectPublicKeyInfo, |
| SECKEY_DestroySubjectPublicKeyInfo> > |
| @@ -424,8 +449,7 @@ bool ExportKeyInternalSpki( |
| DCHECK(spki_der->data); |
| DCHECK(spki_der->len); |
| - *buffer = blink::WebArrayBuffer::create(spki_der->len, 1); |
| - memcpy(buffer->data(), spki_der->data, spki_der->len); |
| + *buffer = webcrypto::CreateArrayBuffer(spki_der->data, spki_der->len); |
| return true; |
| } |
| @@ -827,8 +851,7 @@ bool WebCryptoImpl::ExportKeyInternal( |
| blink::WebArrayBuffer* buffer) { |
| switch (format) { |
| case blink::WebCryptoKeyFormatRaw: |
| - // TODO(padolph): Implement raw export |
| - return false; |
| + return ExportKeyInternalRaw(key, buffer); |
| case blink::WebCryptoKeyFormatSpki: |
| return ExportKeyInternalSpki(key, buffer); |
| case blink::WebCryptoKeyFormatPkcs8: |