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

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: fix another comment 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
Index: Source/platform/exported/WebCryptoKeyAlgorithm.cpp
diff --git a/Source/platform/exported/WebCryptoKeyAlgorithm.cpp b/Source/platform/exported/WebCryptoKeyAlgorithm.cpp
index 1308033b139f648f8f70023e00a3d37e25c81dcd..87058d9a6116557674f42bc4b994874e5fcf0624 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)
+{
+ if (!WebCryptoAlgorithm::isHash(hash))
+ return WebCryptoKeyAlgorithm();
+ return WebCryptoKeyAlgorithm(WebCryptoAlgorithmIdHmac, adoptPtr(new WebCryptoHmacKeyAlgorithmParams(createHash(hash))));
+}
+
+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();

Powered by Google App Engine
This is Rietveld 408576698