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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 | 418 |
419 // HMAC SHA-384 | 419 // HMAC SHA-384 |
420 ImportExportJwkSymmetricKey( | 420 ImportExportJwkSymmetricKey( |
421 384, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha384), | 421 384, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha384), |
422 blink::WebCryptoKeyUsageSign, "HS384"); | 422 blink::WebCryptoKeyUsageSign, "HS384"); |
423 | 423 |
424 // HMAC SHA-512 | 424 // HMAC SHA-512 |
425 ImportExportJwkSymmetricKey( | 425 ImportExportJwkSymmetricKey( |
426 512, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha512), | 426 512, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha512), |
427 blink::WebCryptoKeyUsageVerify, "HS512"); | 427 blink::WebCryptoKeyUsageVerify, "HS512"); |
428 | |
429 // Zero usage value | |
430 ImportExportJwkSymmetricKey( | |
431 512, CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha512), 0, | |
432 "HS512"); | |
433 } | 428 } |
434 | 429 |
435 TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { | 430 TEST(WebCryptoHmacTest, ExportJwkEmptyKey) { |
436 const blink::WebCryptoAlgorithm import_algorithm = | 431 const blink::WebCryptoAlgorithm import_algorithm = |
437 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1); | 432 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1); |
438 | 433 |
439 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; | 434 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageSign; |
440 blink::WebCryptoKey key; | 435 blink::WebCryptoKey key; |
441 | 436 |
442 // Import a zero-byte HMAC key. | 437 // Import a zero-byte HMAC key. |
(...skipping 30 matching lines...) Expand all Loading... |
473 CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length. | 468 CryptoData big_data(NULL, UINT_MAX); // Invalid data of big length. |
474 | 469 |
475 blink::WebCryptoKey key; | 470 blink::WebCryptoKey key; |
476 EXPECT_EQ( | 471 EXPECT_EQ( |
477 Status::ErrorDataTooLarge(), | 472 Status::ErrorDataTooLarge(), |
478 ImportKey(blink::WebCryptoKeyFormatRaw, CryptoData(big_data), | 473 ImportKey(blink::WebCryptoKeyFormatRaw, CryptoData(big_data), |
479 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), | 474 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), |
480 true, blink::WebCryptoKeyUsageSign, &key)); | 475 true, blink::WebCryptoKeyUsageSign, &key)); |
481 } | 476 } |
482 | 477 |
| 478 TEST(WebCryptoHmacTest, ImportKeyEmptyUsage) { |
| 479 blink::WebCryptoKey key; |
| 480 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; |
| 481 EXPECT_EQ( |
| 482 Status::ErrorImportKeyEmptyUsages(), |
| 483 ImportKey(blink::WebCryptoKeyFormatRaw, |
| 484 CryptoData(HexStringToBytes(key_raw_hex_in)), |
| 485 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1), |
| 486 true, 0, &key)); |
| 487 } |
| 488 |
483 } // namespace | 489 } // namespace |
484 | 490 |
485 } // namespace webcrypto | 491 } // namespace webcrypto |
486 | 492 |
487 } // namespace content | 493 } // namespace content |
OLD | NEW |