| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "content/child/webcrypto/algorithm_dispatch.h" | 7 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 8 #include "content/child/webcrypto/crypto_data.h" | 8 #include "content/child/webcrypto/crypto_data.h" |
| 9 #include "content/child/webcrypto/status.h" | 9 #include "content/child/webcrypto/status.h" |
| 10 #include "content/child/webcrypto/test/test_helpers.h" | 10 #include "content/child/webcrypto/test/test_helpers.h" |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 404 |
| 405 // HMAC SHA-384 | 405 // HMAC SHA-384 |
| 406 ImportExportJwkSymmetricKey( | 406 ImportExportJwkSymmetricKey( |
| 407 384, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha384), | 407 384, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha384), |
| 408 blink::WebCryptoKeyUsageSign, "HS384"); | 408 blink::WebCryptoKeyUsageSign, "HS384"); |
| 409 | 409 |
| 410 // HMAC SHA-512 | 410 // HMAC SHA-512 |
| 411 ImportExportJwkSymmetricKey( | 411 ImportExportJwkSymmetricKey( |
| 412 512, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha512), | 412 512, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha512), |
| 413 blink::WebCryptoKeyUsageVerify, "HS512"); | 413 blink::WebCryptoKeyUsageVerify, "HS512"); |
| 414 | |
| 415 // Zero usage value | |
| 416 ImportExportJwkSymmetricKey( | |
| 417 512, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha512), 0, | |
| 418 "HS512"); | |
| 419 } | 414 } |
| 420 | 415 |
| 421 TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { | 416 TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { |
| 422 const blink::WebCryptoAlgorithm import_algorithm = | 417 const blink::WebCryptoAlgorithm import_algorithm = |
| 423 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1); | 418 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1); |
| 424 | 419 |
| 425 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; | 420 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
| 426 blink::WebCryptoKey key; | 421 blink::WebCryptoKey key; |
| 427 | 422 |
| 428 // Import a zero-byte HMAC key. | 423 // Import a zero-byte HMAC key. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 459 CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length. | 454 CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length. |
| 460 | 455 |
| 461 blink::WebCryptoKey key; | 456 blink::WebCryptoKey key; |
| 462 EXPECT_EQ( | 457 EXPECT_EQ( |
| 463 Status::ErrorDataTooLarge(), | 458 Status::ErrorDataTooLarge(), |
| 464 ImportKey(blink::WebCryptoKeyFormatRaw, CryptoData(big_data), | 459 ImportKey(blink::WebCryptoKeyFormatRaw, CryptoData(big_data), |
| 465 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), | 460 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), |
| 466 true, blink::WebCryptoKeyUsageSign, &key)); | 461 true, blink::WebCryptoKeyUsageSign, &key)); |
| 467 } | 462 } |
| 468 | 463 |
| 464 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) { |
| 465 blink::WebCryptoKey key; |
| 466 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; |
| 467 EXPECT_EQ( |
| 468 Status::ErrorImportEmptyKeyUsage(), |
| 469 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 470 CryptoData(HexStringToBytes(key_raw_hex_in)), |
| 471 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), |
| 472 true, 0, &key)); |
| 473 } |
| 474 |
| 469 } // namespace | 475 } // namespace |
| 470 | 476 |
| 471 } // namespace webcrypto | 477 } // namespace webcrypto |
| 472 | 478 |
| 473 } // namespace content | 479 } // namespace content |
| OLD | NEW |