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

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

Issue 23361019: WebCrypto: properly normalize optional numeric parameters. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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
« Source/bindings/v8/Dictionary.h ('K') | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/crypto/NormalizeAlgorithm.cpp
diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp
index 91925e71a6be08647747935958a39741c9d0150c..abd44106b0fb75931cde0358812fe5c9f0a27593 100644
--- a/Source/modules/crypto/NormalizeAlgorithm.cpp
+++ b/Source/modules/crypto/NormalizeAlgorithm.cpp
@@ -235,6 +235,7 @@ bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
return true;
}
+// Gets an integer according to WebIDL's [EnforceRange].
bool getInteger(const Dictionary& raw, const char* propertyName, double& value, double minValue, double maxValue, const ExceptionContext& context, ExceptionState& es)
{
double number;
@@ -243,8 +244,11 @@ bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
return false;
}
- // Convert to an integer according to WebIDL's [EnforceRange].
- if (std::isinf(number) || std::isnan(number)) {
+ if (std::isnan(number)) {
+ es.throwTypeError(context.toString(propertyName, "Is not a number"));
+ return false;
+ }
+ if (std::isinf(number)) {
es.throwTypeError(context.toString(propertyName, "Outside of numeric range"));
return false;
}
@@ -260,19 +264,6 @@ bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
return true;
}
-bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& hasValue, double& value, double minValue, double maxValue, const ExceptionContext& context, ExceptionState& es)
-{
- double number;
- if (!raw.get(propertyName, number)) {
- // FIXME: If the property exists but is NOT a number, should fail.
- hasValue = false;
- return true;
- }
-
- hasValue = true;
- return getInteger(raw, propertyName, value, minValue, maxValue, context, es);
-}
-
bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value, const ExceptionContext& context, ExceptionState& es)
{
double number;
@@ -291,16 +282,6 @@ bool getUint16(const Dictionary& raw, const char* propertyName, uint16_t& value,
return true;
}
-bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& hasValue, uint32_t& value, const ExceptionContext& context, ExceptionState& es)
-{
- double number;
- if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF, context, es))
- return false;
- if (hasValue)
- value = number;
- return true;
-}
-
bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmParams>& params, const ExceptionContext& context, ExceptionState& es)
{
RefPtr<ArrayBufferView> iv;
@@ -356,9 +337,9 @@ bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
if (!parseHash(raw, hash, context, es))
return false;
- bool hasLength;
- uint32_t length;
- if (!getOptionalUint32(raw, "length", hasLength, length, context, es))
+ bool hasLength = raw.hasValue("length");
+ uint32_t length = 0;
+ if (hasLength && !getUint32(raw, "length", length, context, es))
return false;
params = adoptPtr(new WebKit::WebCryptoHmacKeyParams(hash, hasLength, length));
« Source/bindings/v8/Dictionary.h ('K') | « Source/bindings/v8/Dictionary.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698