| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ExceptionContext& context, ExceptionState& es) | 229 bool getUint8Array(const Dictionary& raw, const char* propertyName, RefPtr<Uint8
Array>& array, const ExceptionContext& context, ExceptionState& es) |
| 230 { | 230 { |
| 231 if (!raw.get(propertyName, array) || !array) { | 231 if (!raw.get(propertyName, array) || !array) { |
| 232 es.throwTypeError(context.toString(propertyName, "Missing or not a Uint8
Array")); | 232 es.throwTypeError(context.toString(propertyName, "Missing or not a Uint8
Array")); |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 return true; | 235 return true; |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Gets an integer according to WebIDL's [EnforceRange]. |
| 238 bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
double minValue, double maxValue, const ExceptionContext& context, ExceptionStat
e& es) | 239 bool getInteger(const Dictionary& raw, const char* propertyName, double& value,
double minValue, double maxValue, const ExceptionContext& context, ExceptionStat
e& es) |
| 239 { | 240 { |
| 240 double number; | 241 double number; |
| 241 if (!raw.get(propertyName, number)) { | 242 if (!raw.get(propertyName, number)) { |
| 242 es.throwTypeError(context.toString(propertyName, "Missing or not a numbe
r")); | 243 es.throwTypeError(context.toString(propertyName, "Missing or not a numbe
r")); |
| 243 return false; | 244 return false; |
| 244 } | 245 } |
| 245 | 246 |
| 246 // Convert to an integer according to WebIDL's [EnforceRange]. | 247 if (std::isnan(number)) { |
| 247 if (std::isinf(number) || std::isnan(number)) { | 248 es.throwTypeError(context.toString(propertyName, "Is not a number")); |
| 249 return false; |
| 250 } |
| 251 if (std::isinf(number)) { |
| 248 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); | 252 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); |
| 249 return false; | 253 return false; |
| 250 } | 254 } |
| 251 | 255 |
| 252 number = trunc(number); | 256 number = trunc(number); |
| 253 | 257 |
| 254 if (number < minValue || number > maxValue) { | 258 if (number < minValue || number > maxValue) { |
| 255 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); | 259 es.throwTypeError(context.toString(propertyName, "Outside of numeric ran
ge")); |
| 256 return false; | 260 return false; |
| 257 } | 261 } |
| 258 | 262 |
| 259 value = number; | 263 value = number; |
| 260 return true; | 264 return true; |
| 261 } | 265 } |
| 262 | 266 |
| 263 bool getOptionalInteger(const Dictionary& raw, const char* propertyName, bool& h
asValue, double& value, double minValue, double maxValue, const ExceptionContext
& context, ExceptionState& es) | |
| 264 { | |
| 265 double number; | |
| 266 if (!raw.get(propertyName, number)) { | |
| 267 // FIXME: If the property exists but is NOT a number, should fail. | |
| 268 hasValue = false; | |
| 269 return true; | |
| 270 } | |
| 271 | |
| 272 hasValue = true; | |
| 273 return getInteger(raw, propertyName, value, minValue, maxValue, context, es)
; | |
| 274 } | |
| 275 | |
| 276 bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value,
const ExceptionContext& context, ExceptionState& es) | 267 bool getUint32(const Dictionary& raw, const char* propertyName, uint32_t& value,
const ExceptionContext& context, ExceptionState& es) |
| 277 { | 268 { |
| 278 double number; | 269 double number; |
| 279 if (!getInteger(raw, propertyName, number, 0, 0xFFFFFFFF, context, es)) | 270 if (!getInteger(raw, propertyName, number, 0, 0xFFFFFFFF, context, es)) |
| 280 return false; | 271 return false; |
| 281 value = number; | 272 value = number; |
| 282 return true; | 273 return true; |
| 283 } | 274 } |
| 284 | 275 |
| 285 bool getUint16(const Dictionary& raw, const char* propertyName, uint16_t& value,
const ExceptionContext& context, ExceptionState& es) | 276 bool getUint16(const Dictionary& raw, const char* propertyName, uint16_t& value,
const ExceptionContext& context, ExceptionState& es) |
| 286 { | 277 { |
| 287 double number; | 278 double number; |
| 288 if (!getInteger(raw, propertyName, number, 0, 0xFFFF, context, es)) | 279 if (!getInteger(raw, propertyName, number, 0, 0xFFFF, context, es)) |
| 289 return false; | 280 return false; |
| 290 value = number; | 281 value = number; |
| 291 return true; | 282 return true; |
| 292 } | 283 } |
| 293 | 284 |
| 294 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ExceptionContext& context, ExceptionState& es) | |
| 295 { | |
| 296 double number; | |
| 297 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, es)) | |
| 298 return false; | |
| 299 if (hasValue) | |
| 300 value = number; | |
| 301 return true; | |
| 302 } | |
| 303 | |
| 304 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) | 285 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) |
| 305 { | 286 { |
| 306 RefPtr<ArrayBufferView> iv; | 287 RefPtr<ArrayBufferView> iv; |
| 307 if (!getArrayBufferView(raw, "iv", iv, context, es)) | 288 if (!getArrayBufferView(raw, "iv", iv, context, es)) |
| 308 return false; | 289 return false; |
| 309 | 290 |
| 310 if (iv->byteLength() != 16) { | 291 if (iv->byteLength() != 16) { |
| 311 es.throwTypeError(context.toString("iv", "Must be 16 bytes")); | 292 es.throwTypeError(context.toString("iv", "Must be 16 bytes")); |
| 312 return false; | 293 return false; |
| 313 } | 294 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 params = adoptPtr(new WebKit::WebCryptoHmacParams(hash)); | 330 params = adoptPtr(new WebKit::WebCryptoHmacParams(hash)); |
| 350 return true; | 331 return true; |
| 351 } | 332 } |
| 352 | 333 |
| 353 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
Params>& params, const ExceptionContext& context, ExceptionState& es) | 334 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
Params>& params, const ExceptionContext& context, ExceptionState& es) |
| 354 { | 335 { |
| 355 WebKit::WebCryptoAlgorithm hash; | 336 WebKit::WebCryptoAlgorithm hash; |
| 356 if (!parseHash(raw, hash, context, es)) | 337 if (!parseHash(raw, hash, context, es)) |
| 357 return false; | 338 return false; |
| 358 | 339 |
| 359 bool hasLength; | 340 bool hasLength = raw.contains("length"); |
| 360 uint32_t length; | 341 uint32_t length = 0; |
| 361 if (!getOptionalUint32(raw, "length", hasLength, length, context, es)) | 342 if (hasLength && !getUint32(raw, "length", length, context, es)) |
| 362 return false; | 343 return false; |
| 363 | 344 |
| 364 params = adoptPtr(new WebKit::WebCryptoHmacKeyParams(hash, hasLength, length
)); | 345 params = adoptPtr(new WebKit::WebCryptoHmacKeyParams(hash, hasLength, length
)); |
| 365 return true; | 346 return true; |
| 366 } | 347 } |
| 367 | 348 |
| 368 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) | 349 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) |
| 369 { | 350 { |
| 370 WebKit::WebCryptoAlgorithm hash; | 351 WebKit::WebCryptoAlgorithm hash; |
| 371 if (!parseHash(raw, hash, context, es)) | 352 if (!parseHash(raw, hash, context, es)) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 447 } |
| 467 | 448 |
| 468 } // namespace | 449 } // namespace |
| 469 | 450 |
| 470 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionState& es) | 451 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionState& es) |
| 471 { | 452 { |
| 472 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); | 453 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); |
| 473 } | 454 } |
| 474 | 455 |
| 475 } // namespace WebCore | 456 } // namespace WebCore |
| OLD | NEW |