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

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

Issue 179353002: [webcrypto] Add the KeyAlgorithm interface. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Inline the empty trace() Created 6 years, 10 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/modules/crypto/NormalizeAlgorithm.cpp
diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp
index 713c04beeffdfc6316939a2b5742f67dca32bde4..69fa12846e92da5c8f0abe30e9c0a3a08e2797b6 100644
--- a/Source/modules/crypto/NormalizeAlgorithm.cpp
+++ b/Source/modules/crypto/NormalizeAlgorithm.cpp
@@ -99,16 +99,16 @@ const OperationParamsMapping operationParamsMappings[] = {
{blink::WebCryptoAlgorithmIdAesCtr, WrapKey, blink::WebCryptoAlgorithmParamsTypeAesCtrParams},
// HMAC
- {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeHmacParams},
- {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTypeHmacParams},
- {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmParamsTypeHmacKeyParams},
- {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParamsTypeHmacParams},
+ {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeNone},
+ {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTypeNone},
+ {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams},
+ {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParamsTypeHmacImportParams},
// RSASSA-PKCS1-v1_5
- {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithmParamsTypeRsaSsaParams},
- {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorithmParamsTypeRsaSsaParams},
- {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams},
- {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgorithmParamsTypeNone},
+ {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithmParamsTypeNone},
+ {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorithmParamsTypeNone},
+ {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams},
+ {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams},
// RSAES-PKCS1-v1_5
{blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, blink::WebCryptoAlgorithmParamsTypeNone},
@@ -390,13 +390,13 @@ bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
return parseAlgorithm(rawHash, Digest, hash, context, errorDetails);
}
-bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
+bool parseHmacImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
{
blink::WebCryptoAlgorithm hash;
if (!parseHash(raw, hash, context, errorDetails))
return false;
- params = adoptPtr(new blink::WebCryptoHmacParams(hash));
+ params = adoptPtr(new blink::WebCryptoHmacImportParams(hash));
return true;
}
@@ -411,34 +411,57 @@ bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
if (!getOptionalUint32(raw, "length", hasLength, length, context, errorDetails))
return false;
- params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length));
+ params = adoptPtr(new blink::WebCryptoHmacKeyGenParams(hash, hasLength, length));
return true;
}
-bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
+bool parseRsaHashedImportParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
{
blink::WebCryptoAlgorithm hash;
if (!parseHash(raw, hash, context, errorDetails))
return false;
- params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash));
+ params = adoptPtr(new blink::WebCryptoRsaHashedImportParams(hash));
return true;
}
-bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
+bool parseRsaKeyGenParams(const Dictionary& raw, uint32_t& modulusLength, RefPtr<Uint8Array>& publicExponent, const ErrorContext& context, String& errorDetails)
{
- uint32_t modulusLength;
if (!getUint32(raw, "modulusLength", modulusLength, context, errorDetails))
return false;
- RefPtr<Uint8Array> publicExponent;
if (!getUint8Array(raw, "publicExponent", publicExponent, context, errorDetails))
return false;
+ return true;
+}
+
+bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
+{
+ uint32_t modulusLength;
+ RefPtr<Uint8Array> publicExponent;
+ if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, errorDetails))
+ return false;
+
params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteLength()));
return true;
}
+bool parseRsaHashedKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& errorDetails)
+{
+ uint32_t modulusLength;
+ RefPtr<Uint8Array> publicExponent;
+ if (!parseRsaKeyGenParams(raw, modulusLength, publicExponent, context, errorDetails))
+ return false;
+
+ blink::WebCryptoAlgorithm hash;
+ if (!parseHash(raw, hash, context, errorDetails))
+ return false;
+
+ params = adoptPtr(new blink::WebCryptoRsaHashedKeyGenParams(hash, modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteLength()));
+ return true;
+}
+
bool parseAesCtrParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmParams>& params, const ErrorContext& context, String& es)
{
RefPtr<Uint8Array> counter;
@@ -464,15 +487,18 @@ bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams:
context.add("AesKeyGenParams");
return parseAesKeyGenParams(raw, params, context, errorDetails);
- case blink::WebCryptoAlgorithmParamsTypeHmacParams:
- context.add("HmacParams");
- return parseHmacParams(raw, params, context, errorDetails);
- case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams:
- context.add("HmacKeyParams");
+ case blink::WebCryptoAlgorithmParamsTypeHmacImportParams:
+ context.add("HmacImporParams");
+ return parseHmacImportParams(raw, params, context, errorDetails);
+ case blink::WebCryptoAlgorithmParamsTypeHmacKeyGenParams:
+ context.add("HmacKeyGenParams");
return parseHmacKeyParams(raw, params, context, errorDetails);
- case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams:
- context.add("RsaSSaParams");
- return parseRsaSsaParams(raw, params, context, errorDetails);
+ case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams:
+ context.add("RsaHashedKeyGenParams");
+ return parseRsaHashedKeyGenParams(raw, params, context, errorDetails);
+ case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams:
+ context.add("RsaHashedImportParams");
+ return parseRsaHashedImportParams(raw, params, context, errorDetails);
case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams:
context.add("RsaKeyGenParams");
return parseRsaKeyGenParams(raw, params, context, errorDetails);

Powered by Google App Engine
This is Rietveld 408576698