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

Unified Diff: Source/modules/crypto/SubtleCrypto.cpp

Issue 109223002: [webcrypto] Add crypto.subtle.wrapKey() and crypto.subtle.unwrapKey() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase test expectations (to match latest changes I had made) Created 7 years 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 | « Source/modules/crypto/SubtleCrypto.h ('k') | Source/modules/crypto/SubtleCrypto.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/SubtleCrypto.cpp
diff --git a/Source/modules/crypto/SubtleCrypto.cpp b/Source/modules/crypto/SubtleCrypto.cpp
index 4f00316f9ad93706be7e49db077cf7e23b9e0c4d..e92c1dbf8373523931adec6be5ab7af48342ca54 100644
--- a/Source/modules/crypto/SubtleCrypto.cpp
+++ b/Source/modules/crypto/SubtleCrypto.cpp
@@ -203,4 +203,80 @@ ScriptPromise SubtleCrypto::exportKey(const String& rawFormat, Key* key, Excepti
return promise;
}
+ScriptPromise SubtleCrypto::wrapKey(const String& rawFormat, Key* key, Key* wrappingKey, const Dictionary& rawWrapAlgorithm, ExceptionState& exceptionState)
+{
+ blink::WebCryptoKeyFormat format;
+ if (!Key::parseFormat(rawFormat, format, exceptionState))
+ return ScriptPromise();
+
+ if (!key) {
+ exceptionState.throwTypeError("Invalid key argument");
+ return ScriptPromise();
+ }
+
+ if (!wrappingKey) {
+ exceptionState.throwTypeError("Invalid wrappingKey argument");
+ return ScriptPromise();
+ }
+
+ blink::WebCryptoAlgorithm wrapAlgorithm;
+ if (!normalizeAlgorithm(rawWrapAlgorithm, WrapKey, wrapAlgorithm, exceptionState))
+ return ScriptPromise();
+
+ if (!key->extractable()) {
+ exceptionState.throwDOMException(NotSupportedError, "key is not extractable");
+ return ScriptPromise();
+ }
+
+ if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WrapKey, exceptionState))
+ return ScriptPromise();
+
+ ScriptPromise promise = ScriptPromise::createPending();
+ RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise);
+ blink::Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(), wrapAlgorithm, result->result());
+ return promise;
+}
+
+ScriptPromise SubtleCrypto::unwrapKey(const String& rawFormat, ArrayBufferView* wrappedKey, Key* unwrappingKey, const Dictionary& rawUnwrapAlgorithm, const Dictionary& rawUnwrappedKeyAlgorithm, bool extractable, const Vector<String>& rawKeyUsages, ExceptionState& exceptionState)
+{
+ blink::WebCryptoKeyFormat format;
+ if (!Key::parseFormat(rawFormat, format, exceptionState))
+ return ScriptPromise();
+
+ if (!wrappedKey) {
+ exceptionState.throwTypeError("Invalid wrappedKey argument");
+ return ScriptPromise();
+ }
+
+ if (!unwrappingKey) {
+ exceptionState.throwTypeError("Invalid unwrappingKey argument");
+ return ScriptPromise();
+ }
+
+ blink::WebCryptoAlgorithm unwrapAlgorithm;
+ if (!normalizeAlgorithm(rawUnwrapAlgorithm, UnwrapKey, unwrapAlgorithm, exceptionState))
+ return ScriptPromise();
+
+ // The unwrappedKeyAlgorithm is optional.
+ blink::WebCryptoAlgorithm unwrappedKeyAlgorithm;
+ if (!rawUnwrappedKeyAlgorithm.isUndefinedOrNull() && !normalizeAlgorithm(rawUnwrappedKeyAlgorithm, ImportKey, unwrappedKeyAlgorithm, exceptionState))
+ return ScriptPromise();
+
+ blink::WebCryptoKeyUsageMask keyUsages;
+ if (!Key::parseUsageMask(rawKeyUsages, keyUsages, exceptionState))
+ return ScriptPromise();
+
+ if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, UnwrapKey, exceptionState))
+ return ScriptPromise();
+
+ const unsigned char* wrappedKeyData = static_cast<const unsigned char*>(wrappedKey->baseAddress());
+ unsigned wrappedKeyDataSize = wrappedKey->byteLength();
+
+ ScriptPromise promise = ScriptPromise::createPending();
+ RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(promise);
+ blink::Platform::current()->crypto()->unwrapKey(format, wrappedKeyData, wrappedKeyDataSize, unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
+ return promise;
+}
+
+
} // namespace WebCore
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.h ('k') | Source/modules/crypto/SubtleCrypto.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698