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

Unified Diff: Source/platform/exported/WebCryptoKeyAlgorithm.cpp

Issue 195543002: [webcrypto] Implement structured clone of keys (blink-side). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update serialized-script-value.html for version bump Created 6 years, 9 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 | « Source/platform/exported/WebCryptoAlgorithm.cpp ('k') | public/platform/WebCrypto.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/exported/WebCryptoKeyAlgorithm.cpp
diff --git a/Source/platform/exported/WebCryptoKeyAlgorithm.cpp b/Source/platform/exported/WebCryptoKeyAlgorithm.cpp
index 1308033b139f648f8f70023e00a3d37e25c81dcd..ae759d9e31cfc3a5ae9718d857b1db4992f5199b 100644
--- a/Source/platform/exported/WebCryptoKeyAlgorithm.cpp
+++ b/Source/platform/exported/WebCryptoKeyAlgorithm.cpp
@@ -36,6 +36,12 @@
namespace blink {
+// FIXME: Remove the need for this.
+WebCryptoAlgorithm createHash(WebCryptoAlgorithmId hash)
+{
+ return WebCryptoAlgorithm::adoptParamsAndCreate(hash, 0);
+}
+
class WebCryptoKeyAlgorithmPrivate : public ThreadSafeRefCounted<WebCryptoKeyAlgorithmPrivate> {
public:
WebCryptoKeyAlgorithmPrivate(WebCryptoAlgorithmId id, PassOwnPtr<WebCryptoKeyAlgorithmParams> params)
@@ -58,6 +64,36 @@ WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::adoptParamsAndCreate(WebCryptoAlgor
return WebCryptoKeyAlgorithm(id, adoptPtr(params));
}
+WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createAes(WebCryptoAlgorithmId id, unsigned short keyLengthBits)
+{
+ // FIXME: Verify that id is an AES algorithm.
+ // FIXME: Move this somewhere more general.
+ if (keyLengthBits != 128 && keyLengthBits != 192 && keyLengthBits != 256)
+ return WebCryptoKeyAlgorithm();
+ return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoAesKeyAlgorithmParams(keyLengthBits)));
+}
+
+WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createHmac(WebCryptoAlgorithmId hash, unsigned keyLengthBits)
+{
+ if (!WebCryptoAlgorithm::isHash(hash))
+ return WebCryptoKeyAlgorithm();
+ return WebCryptoKeyAlgorithm(WebCryptoAlgorithmIdHmac, adoptPtr(new WebCryptoHmacKeyAlgorithmParams(createHash(hash), keyLengthBits)));
+}
+
+WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsa(WebCryptoAlgorithmId id, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize)
+{
+ // FIXME: Verify that id is an RSA algorithm without a hash
+ return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoRsaKeyAlgorithmParams(modulusLengthBits, publicExponent, publicExponentSize)));
+}
+
+WebCryptoKeyAlgorithm WebCryptoKeyAlgorithm::createRsaHashed(WebCryptoAlgorithmId id, unsigned modulusLengthBits, const unsigned char* publicExponent, unsigned publicExponentSize, WebCryptoAlgorithmId hash)
+{
+ // FIXME: Verify that id is an RSA algorithm which expects a hash
+ if (!WebCryptoAlgorithm::isHash(hash))
+ return WebCryptoKeyAlgorithm();
+ return WebCryptoKeyAlgorithm(id, adoptPtr(new WebCryptoRsaHashedKeyAlgorithmParams(modulusLengthBits, publicExponent, publicExponentSize, createHash(hash))));
+}
+
bool WebCryptoKeyAlgorithm::isNull() const
{
return m_private.isNull();
« no previous file with comments | « Source/platform/exported/WebCryptoAlgorithm.cpp ('k') | public/platform/WebCrypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698