| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "wtf/Vector.h" | 45 #include "wtf/Vector.h" |
| 46 #include "wtf/text/StringBuilder.h" | 46 #include "wtf/text/StringBuilder.h" |
| 47 #include "wtf/text/StringHash.h" | 47 #include "wtf/text/StringHash.h" |
| 48 | 48 |
| 49 namespace WebCore { | 49 namespace WebCore { |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 struct AlgorithmNameMapping { | 53 struct AlgorithmNameMapping { |
| 54 const char* const algorithmName; | 54 const char* const algorithmName; |
| 55 WebKit::WebCryptoAlgorithmId algorithmId; | 55 blink::WebCryptoAlgorithmId algorithmId; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Indicates that the algorithm doesn't support the specified operation. | 58 // Indicates that the algorithm doesn't support the specified operation. |
| 59 const int UnsupportedOp = -1; | 59 const int UnsupportedOp = -1; |
| 60 | 60 |
| 61 // Either UnsupportedOp, or a value from WebKit::WebCryptoAlgorithmParamsType | 61 // Either UnsupportedOp, or a value from blink::WebCryptoAlgorithmParamsType |
| 62 typedef int AlgorithmParamsForOperation; | 62 typedef int AlgorithmParamsForOperation; |
| 63 | 63 |
| 64 struct OperationParamsMapping { | 64 struct OperationParamsMapping { |
| 65 WebKit::WebCryptoAlgorithmId algorithmId; | 65 blink::WebCryptoAlgorithmId algorithmId; |
| 66 AlgorithmOperation operation; | 66 AlgorithmOperation operation; |
| 67 AlgorithmParamsForOperation params; | 67 AlgorithmParamsForOperation params; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 const AlgorithmNameMapping algorithmNameMappings[] = { | 70 const AlgorithmNameMapping algorithmNameMappings[] = { |
| 71 {"AES-CBC", WebKit::WebCryptoAlgorithmIdAesCbc}, | 71 {"AES-CBC", blink::WebCryptoAlgorithmIdAesCbc}, |
| 72 {"HMAC", WebKit::WebCryptoAlgorithmIdHmac}, | 72 {"HMAC", blink::WebCryptoAlgorithmIdHmac}, |
| 73 {"RSASSA-PKCS1-v1_5", WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, | 73 {"RSASSA-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, |
| 74 {"RSAES-PKCS1-v1_5", WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, | 74 {"RSAES-PKCS1-v1_5", blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5}, |
| 75 {"SHA-1", WebKit::WebCryptoAlgorithmIdSha1}, | 75 {"SHA-1", blink::WebCryptoAlgorithmIdSha1}, |
| 76 {"SHA-224", WebKit::WebCryptoAlgorithmIdSha224}, | 76 {"SHA-224", blink::WebCryptoAlgorithmIdSha224}, |
| 77 {"SHA-256", WebKit::WebCryptoAlgorithmIdSha256}, | 77 {"SHA-256", blink::WebCryptoAlgorithmIdSha256}, |
| 78 {"SHA-384", WebKit::WebCryptoAlgorithmIdSha384}, | 78 {"SHA-384", blink::WebCryptoAlgorithmIdSha384}, |
| 79 {"SHA-512", WebKit::WebCryptoAlgorithmIdSha512}, | 79 {"SHA-512", blink::WebCryptoAlgorithmIdSha512}, |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // What operations each algorithm supports, and what parameters it expects. | 82 // What operations each algorithm supports, and what parameters it expects. |
| 83 const OperationParamsMapping operationParamsMappings[] = { | 83 const OperationParamsMapping operationParamsMappings[] = { |
| 84 // AES-CBC | 84 // AES-CBC |
| 85 {WebKit::WebCryptoAlgorithmIdAesCbc, Decrypt, WebKit::WebCryptoAlgorithmPara
msTypeAesCbcParams}, | 85 {blink::WebCryptoAlgorithmIdAesCbc, Decrypt, blink::WebCryptoAlgorithmParams
TypeAesCbcParams}, |
| 86 {WebKit::WebCryptoAlgorithmIdAesCbc, Encrypt, WebKit::WebCryptoAlgorithmPara
msTypeAesCbcParams}, | 86 {blink::WebCryptoAlgorithmIdAesCbc, Encrypt, blink::WebCryptoAlgorithmParams
TypeAesCbcParams}, |
| 87 {WebKit::WebCryptoAlgorithmIdAesCbc, GenerateKey, WebKit::WebCryptoAlgorithm
ParamsTypeAesKeyGenParams}, | 87 {blink::WebCryptoAlgorithmIdAesCbc, GenerateKey, blink::WebCryptoAlgorithmPa
ramsTypeAesKeyGenParams}, |
| 88 {WebKit::WebCryptoAlgorithmIdAesCbc, ImportKey, WebKit::WebCryptoAlgorithmPa
ramsTypeNone}, | 88 {blink::WebCryptoAlgorithmIdAesCbc, ImportKey, blink::WebCryptoAlgorithmPara
msTypeNone}, |
| 89 | 89 |
| 90 // HMAC | 90 // HMAC |
| 91 {WebKit::WebCryptoAlgorithmIdHmac, Sign, WebKit::WebCryptoAlgorithmParamsTyp
eHmacParams}, | 91 {blink::WebCryptoAlgorithmIdHmac, Sign, blink::WebCryptoAlgorithmParamsTypeH
macParams}, |
| 92 {WebKit::WebCryptoAlgorithmIdHmac, Verify, WebKit::WebCryptoAlgorithmParamsT
ypeHmacParams}, | 92 {blink::WebCryptoAlgorithmIdHmac, Verify, blink::WebCryptoAlgorithmParamsTyp
eHmacParams}, |
| 93 {WebKit::WebCryptoAlgorithmIdHmac, GenerateKey, WebKit::WebCryptoAlgorithmPa
ramsTypeHmacKeyParams}, | 93 {blink::WebCryptoAlgorithmIdHmac, GenerateKey, blink::WebCryptoAlgorithmPara
msTypeHmacKeyParams}, |
| 94 {WebKit::WebCryptoAlgorithmIdHmac, ImportKey, WebKit::WebCryptoAlgorithmPara
msTypeHmacParams}, | 94 {blink::WebCryptoAlgorithmIdHmac, ImportKey, blink::WebCryptoAlgorithmParams
TypeHmacParams}, |
| 95 | 95 |
| 96 // RSASSA-PKCS1-v1_5 | 96 // RSASSA-PKCS1-v1_5 |
| 97 {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, WebKit::WebCryptoAlgorit
hmParamsTypeRsaSsaParams}, | 97 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, blink::WebCryptoAlgorithm
ParamsTypeRsaSsaParams}, |
| 98 {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, WebKit::WebCryptoAlgor
ithmParamsTypeRsaSsaParams}, | 98 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, blink::WebCryptoAlgorit
hmParamsTypeRsaSsaParams}, |
| 99 {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, WebKit::WebCrypto
AlgorithmParamsTypeRsaKeyGenParams}, | 99 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, blink::WebCryptoAl
gorithmParamsTypeRsaKeyGenParams}, |
| 100 {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, WebKit::WebCryptoAl
gorithmParamsTypeNone}, | 100 {blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, blink::WebCryptoAlgo
rithmParamsTypeNone}, |
| 101 | 101 |
| 102 // RSAES-PKCS1-v1_5 | 102 // RSAES-PKCS1-v1_5 |
| 103 {WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, WebKit::WebCryptoAlgor
ithmParamsTypeNone}, | 103 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Encrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
| 104 {WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Decrypt, WebKit::WebCryptoAlgor
ithmParamsTypeNone}, | 104 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, Decrypt, blink::WebCryptoAlgorit
hmParamsTypeNone}, |
| 105 {WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, GenerateKey, WebKit::WebCryptoA
lgorithmParamsTypeRsaKeyGenParams}, | 105 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, GenerateKey, blink::WebCryptoAlg
orithmParamsTypeRsaKeyGenParams}, |
| 106 {WebKit::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, ImportKey, WebKit::WebCryptoAlg
orithmParamsTypeNone}, | 106 {blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, ImportKey, blink::WebCryptoAlgor
ithmParamsTypeNone}, |
| 107 | 107 |
| 108 // SHA-* | 108 // SHA-* |
| 109 {WebKit::WebCryptoAlgorithmIdSha1, Digest, WebKit::WebCryptoAlgorithmParamsT
ypeNone}, | 109 {blink::WebCryptoAlgorithmIdSha1, Digest, blink::WebCryptoAlgorithmParamsTyp
eNone}, |
| 110 {WebKit::WebCryptoAlgorithmIdSha224, Digest, WebKit::WebCryptoAlgorithmParam
sTypeNone}, | 110 {blink::WebCryptoAlgorithmIdSha224, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
| 111 {WebKit::WebCryptoAlgorithmIdSha256, Digest, WebKit::WebCryptoAlgorithmParam
sTypeNone}, | 111 {blink::WebCryptoAlgorithmIdSha256, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
| 112 {WebKit::WebCryptoAlgorithmIdSha384, Digest, WebKit::WebCryptoAlgorithmParam
sTypeNone}, | 112 {blink::WebCryptoAlgorithmIdSha384, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
| 113 {WebKit::WebCryptoAlgorithmIdSha512, Digest, WebKit::WebCryptoAlgorithmParam
sTypeNone}, | 113 {blink::WebCryptoAlgorithmIdSha512, Digest, blink::WebCryptoAlgorithmParamsT
ypeNone}, |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 // This structure describes an algorithm and its supported operations. | 116 // This structure describes an algorithm and its supported operations. |
| 117 struct AlgorithmInfo { | 117 struct AlgorithmInfo { |
| 118 AlgorithmInfo() | 118 AlgorithmInfo() |
| 119 : algorithmName(0) | 119 : algorithmName(0) |
| 120 { | 120 { |
| 121 for (size_t i = 0; i < WTF_ARRAY_LENGTH(paramsForOperation); ++i) | 121 for (size_t i = 0; i < WTF_ARRAY_LENGTH(paramsForOperation); ++i) |
| 122 paramsForOperation[i] = UnsupportedOp; | 122 paramsForOperation[i] = UnsupportedOp; |
| 123 } | 123 } |
| 124 | 124 |
| 125 WebKit::WebCryptoAlgorithmId algorithmId; | 125 blink::WebCryptoAlgorithmId algorithmId; |
| 126 const char* algorithmName; | 126 const char* algorithmName; |
| 127 AlgorithmParamsForOperation paramsForOperation[NumberOfAlgorithmOperations]; | 127 AlgorithmParamsForOperation paramsForOperation[NumberOfAlgorithmOperations]; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // AlgorithmRegistry enumerates each of the different algorithms and its | 130 // AlgorithmRegistry enumerates each of the different algorithms and its |
| 131 // parameters. This describes the same information as the static tables above, | 131 // parameters. This describes the same information as the static tables above, |
| 132 // but in a more convenient runtime form. | 132 // but in a more convenient runtime form. |
| 133 class AlgorithmRegistry { | 133 class AlgorithmRegistry { |
| 134 public: | 134 public: |
| 135 static AlgorithmRegistry& instance(); | 135 static AlgorithmRegistry& instance(); |
| 136 | 136 |
| 137 const AlgorithmInfo* lookupAlgorithmByName(const String&) const; | 137 const AlgorithmInfo* lookupAlgorithmByName(const String&) const; |
| 138 const AlgorithmInfo* lookupAlgorithmById(WebKit::WebCryptoAlgorithmId) const
; | 138 const AlgorithmInfo* lookupAlgorithmById(blink::WebCryptoAlgorithmId) const; |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 AlgorithmRegistry(); | 141 AlgorithmRegistry(); |
| 142 | 142 |
| 143 // Algorithm name to ID. | 143 // Algorithm name to ID. |
| 144 typedef HashMap<String, WebKit::WebCryptoAlgorithmId, CaseFoldingHash> Algor
ithmNameToIdMap; | 144 typedef HashMap<String, blink::WebCryptoAlgorithmId, CaseFoldingHash> Algori
thmNameToIdMap; |
| 145 AlgorithmNameToIdMap m_algorithmNameToId; | 145 AlgorithmNameToIdMap m_algorithmNameToId; |
| 146 | 146 |
| 147 // Algorithm ID to information. | 147 // Algorithm ID to information. |
| 148 AlgorithmInfo m_algorithms[WebKit::NumberOfWebCryptoAlgorithmId]; | 148 AlgorithmInfo m_algorithms[blink::NumberOfWebCryptoAlgorithmId]; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 AlgorithmRegistry& AlgorithmRegistry::instance() | 151 AlgorithmRegistry& AlgorithmRegistry::instance() |
| 152 { | 152 { |
| 153 DEFINE_STATIC_LOCAL(AlgorithmRegistry, registry, ()); | 153 DEFINE_STATIC_LOCAL(AlgorithmRegistry, registry, ()); |
| 154 return registry; | 154 return registry; |
| 155 } | 155 } |
| 156 | 156 |
| 157 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmByName(const String& algo
rithmName) const | 157 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmByName(const String& algo
rithmName) const |
| 158 { | 158 { |
| 159 AlgorithmNameToIdMap::const_iterator it = m_algorithmNameToId.find(algorithm
Name); | 159 AlgorithmNameToIdMap::const_iterator it = m_algorithmNameToId.find(algorithm
Name); |
| 160 if (it == m_algorithmNameToId.end()) | 160 if (it == m_algorithmNameToId.end()) |
| 161 return 0; | 161 return 0; |
| 162 return lookupAlgorithmById(it->value); | 162 return lookupAlgorithmById(it->value); |
| 163 } | 163 } |
| 164 | 164 |
| 165 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmById(WebKit::WebCryptoAlg
orithmId algorithmId) const | 165 const AlgorithmInfo* AlgorithmRegistry::lookupAlgorithmById(blink::WebCryptoAlgo
rithmId algorithmId) const |
| 166 { | 166 { |
| 167 ASSERT(algorithmId >= 0 && algorithmId < WTF_ARRAY_LENGTH(m_algorithms)); | 167 ASSERT(algorithmId >= 0 && algorithmId < WTF_ARRAY_LENGTH(m_algorithms)); |
| 168 return &m_algorithms[algorithmId]; | 168 return &m_algorithms[algorithmId]; |
| 169 } | 169 } |
| 170 | 170 |
| 171 AlgorithmRegistry::AlgorithmRegistry() | 171 AlgorithmRegistry::AlgorithmRegistry() |
| 172 { | 172 { |
| 173 for (size_t i = 0; i < WTF_ARRAY_LENGTH(algorithmNameMappings); ++i) { | 173 for (size_t i = 0; i < WTF_ARRAY_LENGTH(algorithmNameMappings); ++i) { |
| 174 const AlgorithmNameMapping& mapping = algorithmNameMappings[i]; | 174 const AlgorithmNameMapping& mapping = algorithmNameMappings[i]; |
| 175 m_algorithmNameToId.add(mapping.algorithmName, mapping.algorithmId); | 175 m_algorithmNameToId.add(mapping.algorithmName, mapping.algorithmId); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ExceptionContext& context, ExceptionState& es) | 316 bool getOptionalUint32(const Dictionary& raw, const char* propertyName, bool& ha
sValue, uint32_t& value, const ExceptionContext& context, ExceptionState& es) |
| 317 { | 317 { |
| 318 double number; | 318 double number; |
| 319 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, es)) | 319 if (!getOptionalInteger(raw, propertyName, hasValue, number, 0, 0xFFFFFFFF,
context, es)) |
| 320 return false; | 320 return false; |
| 321 if (hasValue) | 321 if (hasValue) |
| 322 value = number; | 322 value = number; |
| 323 return true; | 323 return true; |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) | 326 bool parseAesCbcParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ExceptionContext& context, ExceptionState& es) |
| 327 { | 327 { |
| 328 RefPtr<ArrayBufferView> iv; | 328 RefPtr<ArrayBufferView> iv; |
| 329 if (!getArrayBufferView(raw, "iv", iv, context, es)) | 329 if (!getArrayBufferView(raw, "iv", iv, context, es)) |
| 330 return false; | 330 return false; |
| 331 | 331 |
| 332 if (iv->byteLength() != 16) { | 332 if (iv->byteLength() != 16) { |
| 333 es.throwTypeError(context.toString("iv", "Must be 16 bytes")); | 333 es.throwTypeError(context.toString("iv", "Must be 16 bytes")); |
| 334 return false; | 334 return false; |
| 335 } | 335 } |
| 336 | 336 |
| 337 params = adoptPtr(new WebKit::WebCryptoAesCbcParams(static_cast<unsigned cha
r*>(iv->baseAddress()), iv->byteLength())); | 337 params = adoptPtr(new blink::WebCryptoAesCbcParams(static_cast<unsigned char
*>(iv->baseAddress()), iv->byteLength())); |
| 338 return true; | 338 return true; |
| 339 } | 339 } |
| 340 | 340 |
| 341 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorit
hmParams>& params, const ExceptionContext& context, ExceptionState& es) | 341 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ExceptionContext& context, ExceptionState& es) |
| 342 { | 342 { |
| 343 uint16_t length; | 343 uint16_t length; |
| 344 if (!getUint16(raw, "length", length, context, es)) | 344 if (!getUint16(raw, "length", length, context, es)) |
| 345 return false; | 345 return false; |
| 346 | 346 |
| 347 params = adoptPtr(new WebKit::WebCryptoAesKeyGenParams(length)); | 347 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); |
| 348 return true; | 348 return true; |
| 349 } | 349 } |
| 350 | 350 |
| 351 bool normalizeAlgorithm(const Dictionary&, AlgorithmOperation, WebKit::WebCrypto
Algorithm&, ExceptionContext, ExceptionState&); | 351 bool normalizeAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoA
lgorithm&, ExceptionContext, ExceptionState&); |
| 352 | 352 |
| 353 bool parseHash(const Dictionary& raw, WebKit::WebCryptoAlgorithm& hash, Exceptio
nContext context, ExceptionState& es) | 353 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, Exception
Context context, ExceptionState& es) |
| 354 { | 354 { |
| 355 Dictionary rawHash; | 355 Dictionary rawHash; |
| 356 if (!raw.get("hash", rawHash)) { | 356 if (!raw.get("hash", rawHash)) { |
| 357 es.throwTypeError(context.toString("hash", "Missing or not a dictionary"
)); | 357 es.throwTypeError(context.toString("hash", "Missing or not a dictionary"
)); |
| 358 return false; | 358 return false; |
| 359 } | 359 } |
| 360 | 360 |
| 361 context.add("hash"); | 361 context.add("hash"); |
| 362 return normalizeAlgorithm(rawHash, Digest, hash, context, es); | 362 return normalizeAlgorithm(rawHash, Digest, hash, context, es); |
| 363 } | 363 } |
| 364 | 364 |
| 365 bool parseHmacParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmPar
ams>& params, const ExceptionContext& context, ExceptionState& es) | 365 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ExceptionContext& context, ExceptionState& es) |
| 366 { | 366 { |
| 367 WebKit::WebCryptoAlgorithm hash; | 367 blink::WebCryptoAlgorithm hash; |
| 368 if (!parseHash(raw, hash, context, es)) | 368 if (!parseHash(raw, hash, context, es)) |
| 369 return false; | 369 return false; |
| 370 | 370 |
| 371 params = adoptPtr(new WebKit::WebCryptoHmacParams(hash)); | 371 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); |
| 372 return true; | 372 return true; |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithm
Params>& params, const ExceptionContext& context, ExceptionState& es) | 375 bool parseHmacKeyParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) |
| 376 { | 376 { |
| 377 WebKit::WebCryptoAlgorithm hash; | 377 blink::WebCryptoAlgorithm hash; |
| 378 if (!parseHash(raw, hash, context, es)) | 378 if (!parseHash(raw, hash, context, es)) |
| 379 return false; | 379 return false; |
| 380 | 380 |
| 381 bool hasLength; | 381 bool hasLength; |
| 382 uint32_t length = 0; | 382 uint32_t length = 0; |
| 383 if (!getOptionalUint32(raw, "length", hasLength, length, context, es)) | 383 if (!getOptionalUint32(raw, "length", hasLength, length, context, es)) |
| 384 return false; | 384 return false; |
| 385 | 385 |
| 386 params = adoptPtr(new WebKit::WebCryptoHmacKeyParams(hash, hasLength, length
)); | 386 params = adoptPtr(new blink::WebCryptoHmacKeyParams(hash, hasLength, length)
); |
| 387 return true; | 387 return true; |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorithmP
arams>& params, const ExceptionContext& context, ExceptionState& es) | 390 bool parseRsaSsaParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPa
rams>& params, const ExceptionContext& context, ExceptionState& es) |
| 391 { | 391 { |
| 392 WebKit::WebCryptoAlgorithm hash; | 392 blink::WebCryptoAlgorithm hash; |
| 393 if (!parseHash(raw, hash, context, es)) | 393 if (!parseHash(raw, hash, context, es)) |
| 394 return false; | 394 return false; |
| 395 | 395 |
| 396 params = adoptPtr(new WebKit::WebCryptoRsaSsaParams(hash)); | 396 params = adoptPtr(new blink::WebCryptoRsaSsaParams(hash)); |
| 397 return true; | 397 return true; |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<WebKit::WebCryptoAlgorit
hmParams>& params, const ExceptionContext& context, ExceptionState& es) | 400 bool parseRsaKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ExceptionContext& context, ExceptionState& es) |
| 401 { | 401 { |
| 402 uint32_t modulusLength; | 402 uint32_t modulusLength; |
| 403 if (!getUint32(raw, "modulusLength", modulusLength, context, es)) | 403 if (!getUint32(raw, "modulusLength", modulusLength, context, es)) |
| 404 return false; | 404 return false; |
| 405 | 405 |
| 406 RefPtr<Uint8Array> publicExponent; | 406 RefPtr<Uint8Array> publicExponent; |
| 407 if (!getUint8Array(raw, "publicExponent", publicExponent, context, es)) | 407 if (!getUint8Array(raw, "publicExponent", publicExponent, context, es)) |
| 408 return false; | 408 return false; |
| 409 | 409 |
| 410 params = adoptPtr(new WebKit::WebCryptoRsaKeyGenParams(modulusLength, static
_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byte
Length())); | 410 params = adoptPtr(new blink::WebCryptoRsaKeyGenParams(modulusLength, static_
cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteL
ength())); |
| 411 return true; | 411 return true; |
| 412 } | 412 } |
| 413 | 413 |
| 414 bool parseAlgorithmParams(const Dictionary& raw, WebKit::WebCryptoAlgorithmParam
sType type, OwnPtr<WebKit::WebCryptoAlgorithmParams>& params, ExceptionContext&
context, ExceptionState& es) | 414 bool parseAlgorithmParams(const Dictionary& raw, blink::WebCryptoAlgorithmParams
Type type, OwnPtr<blink::WebCryptoAlgorithmParams>& params, ExceptionContext& co
ntext, ExceptionState& es) |
| 415 { | 415 { |
| 416 switch (type) { | 416 switch (type) { |
| 417 case WebKit::WebCryptoAlgorithmParamsTypeNone: | 417 case blink::WebCryptoAlgorithmParamsTypeNone: |
| 418 return true; | 418 return true; |
| 419 case WebKit::WebCryptoAlgorithmParamsTypeAesCbcParams: | 419 case blink::WebCryptoAlgorithmParamsTypeAesCbcParams: |
| 420 context.add("AesCbcParams"); | 420 context.add("AesCbcParams"); |
| 421 return parseAesCbcParams(raw, params, context, es); | 421 return parseAesCbcParams(raw, params, context, es); |
| 422 case WebKit::WebCryptoAlgorithmParamsTypeAesKeyGenParams: | 422 case blink::WebCryptoAlgorithmParamsTypeAesKeyGenParams: |
| 423 context.add("AesKeyGenParams"); | 423 context.add("AesKeyGenParams"); |
| 424 return parseAesKeyGenParams(raw, params, context, es); | 424 return parseAesKeyGenParams(raw, params, context, es); |
| 425 case WebKit::WebCryptoAlgorithmParamsTypeHmacParams: | 425 case blink::WebCryptoAlgorithmParamsTypeHmacParams: |
| 426 context.add("HmacParams"); | 426 context.add("HmacParams"); |
| 427 return parseHmacParams(raw, params, context, es); | 427 return parseHmacParams(raw, params, context, es); |
| 428 case WebKit::WebCryptoAlgorithmParamsTypeHmacKeyParams: | 428 case blink::WebCryptoAlgorithmParamsTypeHmacKeyParams: |
| 429 context.add("HmacKeyParams"); | 429 context.add("HmacKeyParams"); |
| 430 return parseHmacKeyParams(raw, params, context, es); | 430 return parseHmacKeyParams(raw, params, context, es); |
| 431 case WebKit::WebCryptoAlgorithmParamsTypeRsaSsaParams: | 431 case blink::WebCryptoAlgorithmParamsTypeRsaSsaParams: |
| 432 context.add("RsaSSaParams"); | 432 context.add("RsaSSaParams"); |
| 433 return parseRsaSsaParams(raw, params, context, es); | 433 return parseRsaSsaParams(raw, params, context, es); |
| 434 case WebKit::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 434 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
| 435 context.add("RsaKeyGenParams"); | 435 context.add("RsaKeyGenParams"); |
| 436 return parseRsaKeyGenParams(raw, params, context, es); | 436 return parseRsaKeyGenParams(raw, params, context, es); |
| 437 case WebKit::WebCryptoAlgorithmParamsTypeAesGcmParams: | 437 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
| 438 case WebKit::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 438 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
| 439 // TODO | 439 // TODO |
| 440 notImplemented(); | 440 notImplemented(); |
| 441 break; | 441 break; |
| 442 } | 442 } |
| 443 ASSERT_NOT_REACHED(); | 443 ASSERT_NOT_REACHED(); |
| 444 return false; | 444 return false; |
| 445 } | 445 } |
| 446 | 446 |
| 447 const AlgorithmInfo* algorithmInfo(const Dictionary& raw, const ExceptionContext
& context, ExceptionState& es) | 447 const AlgorithmInfo* algorithmInfo(const Dictionary& raw, const ExceptionContext
& context, ExceptionState& es) |
| 448 { | 448 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 461 if (!info) { | 461 if (!info) { |
| 462 es.throwDOMException(NotSupportedError, context.toString("Unrecognized a
lgorithm name")); | 462 es.throwDOMException(NotSupportedError, context.toString("Unrecognized a
lgorithm name")); |
| 463 return 0; | 463 return 0; |
| 464 } | 464 } |
| 465 | 465 |
| 466 return info; | 466 return info; |
| 467 } | 467 } |
| 468 | 468 |
| 469 // This implementation corresponds with: | 469 // This implementation corresponds with: |
| 470 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules | 470 // http://www.w3.org/TR/WebCryptoAPI/#algorithm-normalizing-rules |
| 471 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionContext context, ExceptionState& es) | 471 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::Web
CryptoAlgorithm& algorithm, ExceptionContext context, ExceptionState& es) |
| 472 { | 472 { |
| 473 context.add("Algorithm"); | 473 context.add("Algorithm"); |
| 474 | 474 |
| 475 const AlgorithmInfo* info = algorithmInfo(raw, context, es); | 475 const AlgorithmInfo* info = algorithmInfo(raw, context, es); |
| 476 if (!info) | 476 if (!info) |
| 477 return false; | 477 return false; |
| 478 | 478 |
| 479 context.add(info->algorithmName); | 479 context.add(info->algorithmName); |
| 480 | 480 |
| 481 if (info->paramsForOperation[op] == UnsupportedOp) { | 481 if (info->paramsForOperation[op] == UnsupportedOp) { |
| 482 es.throwDOMException(NotSupportedError, context.toString("Unsupported op
eration")); | 482 es.throwDOMException(NotSupportedError, context.toString("Unsupported op
eration")); |
| 483 return false; | 483 return false; |
| 484 } | 484 } |
| 485 | 485 |
| 486 WebKit::WebCryptoAlgorithmParamsType paramsType = static_cast<WebKit::WebCry
ptoAlgorithmParamsType>(info->paramsForOperation[op]); | 486 blink::WebCryptoAlgorithmParamsType paramsType = static_cast<blink::WebCrypt
oAlgorithmParamsType>(info->paramsForOperation[op]); |
| 487 OwnPtr<WebKit::WebCryptoAlgorithmParams> params; | 487 OwnPtr<blink::WebCryptoAlgorithmParams> params; |
| 488 if (!parseAlgorithmParams(raw, paramsType, params, context, es)) | 488 if (!parseAlgorithmParams(raw, paramsType, params, context, es)) |
| 489 return false; | 489 return false; |
| 490 | 490 |
| 491 algorithm = WebKit::WebCryptoAlgorithm(info->algorithmId, params.release()); | 491 algorithm = blink::WebCryptoAlgorithm(info->algorithmId, params.release()); |
| 492 return true; | 492 return true; |
| 493 } | 493 } |
| 494 | 494 |
| 495 } // namespace | 495 } // namespace |
| 496 | 496 |
| 497 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, WebKit::We
bCryptoAlgorithm& algorithm, ExceptionState& es) | 497 bool normalizeAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::Web
CryptoAlgorithm& algorithm, ExceptionState& es) |
| 498 { | 498 { |
| 499 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); | 499 return normalizeAlgorithm(raw, op, algorithm, ExceptionContext(), es); |
| 500 } | 500 } |
| 501 | 501 |
| 502 const char* algorithmIdToName(WebKit::WebCryptoAlgorithmId id) | 502 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
| 503 { | 503 { |
| 504 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; | 504 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; |
| 505 } | 505 } |
| 506 | 506 |
| 507 } // namespace WebCore | 507 } // namespace WebCore |
| OLD | NEW |