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" | |
7 #include "base/values.h" | 6 #include "base/values.h" |
8 #include "components/webcrypto/algorithm_dispatch.h" | 7 #include "components/webcrypto/algorithm_dispatch.h" |
9 #include "components/webcrypto/algorithms/test_helpers.h" | 8 #include "components/webcrypto/algorithms/test_helpers.h" |
10 #include "components/webcrypto/crypto_data.h" | 9 #include "components/webcrypto/crypto_data.h" |
11 #include "components/webcrypto/status.h" | 10 #include "components/webcrypto/status.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 12 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
14 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 13 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
15 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" | 14 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
16 | 15 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 bool signature_match; | 538 bool signature_match; |
540 | 539 |
541 // Compute a signature. | 540 // Compute a signature. |
542 const std::vector<uint8_t> data = HexStringToBytes("010203040506070809"); | 541 const std::vector<uint8_t> data = HexStringToBytes("010203040506070809"); |
543 ASSERT_EQ(Status::Success(), | 542 ASSERT_EQ(Status::Success(), |
544 Sign(algorithm, private_key, CryptoData(data), &signature)); | 543 Sign(algorithm, private_key, CryptoData(data), &signature)); |
545 | 544 |
546 // Ensure truncated signature does not verify by passing one less byte. | 545 // Ensure truncated signature does not verify by passing one less byte. |
547 EXPECT_EQ(Status::Success(), | 546 EXPECT_EQ(Status::Success(), |
548 Verify(algorithm, public_key, | 547 Verify(algorithm, public_key, |
549 CryptoData(vector_as_array(&signature), | 548 CryptoData(signature.data(), |
550 static_cast<unsigned int>(signature.size()) - 1), | 549 static_cast<unsigned int>(signature.size()) - 1), |
551 CryptoData(data), &signature_match)); | 550 CryptoData(data), &signature_match)); |
552 EXPECT_FALSE(signature_match); | 551 EXPECT_FALSE(signature_match); |
553 | 552 |
554 // Ensure truncated signature does not verify by passing no bytes. | 553 // Ensure truncated signature does not verify by passing no bytes. |
555 EXPECT_EQ(Status::Success(), Verify(algorithm, public_key, CryptoData(), | 554 EXPECT_EQ(Status::Success(), Verify(algorithm, public_key, CryptoData(), |
556 CryptoData(data), &signature_match)); | 555 CryptoData(data), &signature_match)); |
557 EXPECT_FALSE(signature_match); | 556 EXPECT_FALSE(signature_match); |
558 | 557 |
559 // Ensure corrupted signature does not verify. | 558 // Ensure corrupted signature does not verify. |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 1010 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
1012 blink::WebCryptoAlgorithmIdSha256), | 1011 blink::WebCryptoAlgorithmIdSha256), |
1013 true, usages, &key); | 1012 true, usages, &key); |
1014 EXPECT_EQ(test_error, StatusToString(status)); | 1013 EXPECT_EQ(test_error, StatusToString(status)); |
1015 } | 1014 } |
1016 } | 1015 } |
1017 | 1016 |
1018 } // namespace | 1017 } // namespace |
1019 | 1018 |
1020 } // namespace webcrypto | 1019 } // namespace webcrypto |
OLD | NEW |