| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/cert/internal/signature_algorithm.h" | 5 #include "net/cert/internal/signature_algorithm.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "net/cert/internal/cert_errors.h" | 11 #include "net/cert/internal/cert_errors.h" |
| 12 #include "net/cert/pem_tokenizer.h" | 12 #include "net/cert/pem_tokenizer.h" |
| 13 #include "net/der/input.h" | 13 #include "net/der/input.h" |
| 14 #include "net/der/parser.h" | 14 #include "net/der/parser.h" |
| 15 #include "net/test/test_data_directory.h" | 15 #include "net/test/test_data_directory.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Creates a SignatureAlgorithm given the DER as a byte array. Returns true on | 22 // Creates a SignatureAlgorithm given the DER as a byte array. Returns true on |
| 23 // success and fills |*out| with a non-null pointer. | 23 // success and fills |*out| with a non-null pointer. |
| 24 template <size_t N> | 24 template <size_t N> |
| 25 bool ParseDer(const uint8_t (&data)[N], | 25 bool ParseDer(const uint8_t (&data)[N], |
| 26 std::unique_ptr<SignatureAlgorithm>* out) { | 26 std::unique_ptr<SignatureAlgorithm>* out) { |
| 27 // TODO(crbug.com/634443): Test the errors. | |
| 28 CertErrors errors; | 27 CertErrors errors; |
| 29 *out = SignatureAlgorithm::Create(der::Input(data, N), &errors); | 28 *out = SignatureAlgorithm::Create(der::Input(data, N), &errors); |
| 30 return !!*out; | 29 bool success = !!*out; |
| 30 |
| 31 // TODO(crbug.com/634443): Test the errors. |
| 32 // if (!success) |
| 33 // EXPECT_FALSE(errors.empty()); |
| 34 |
| 35 return success; |
| 31 } | 36 } |
| 32 | 37 |
| 33 // Parses a SignatureAlgorithm given an empty DER input. | 38 // Parses a SignatureAlgorithm given an empty DER input. |
| 34 TEST(SignatureAlgorithmTest, ParseDerEmpty) { | 39 TEST(SignatureAlgorithmTest, ParseDerEmpty) { |
| 35 // TODO(crbug.com/634443): Test the errors. | |
| 36 CertErrors errors; | 40 CertErrors errors; |
| 37 std::unique_ptr<SignatureAlgorithm> algorithm = | 41 std::unique_ptr<SignatureAlgorithm> algorithm = |
| 38 SignatureAlgorithm::Create(der::Input(), &errors); | 42 SignatureAlgorithm::Create(der::Input(), &errors); |
| 39 ASSERT_FALSE(algorithm); | 43 ASSERT_FALSE(algorithm); |
| 44 // TODO(crbug.com/634443): Test the errors. |
| 45 // EXPECT_FALSE(errors.empty()); |
| 40 } | 46 } |
| 41 | 47 |
| 42 // Parses a SignatureAlgorithm given invalid DER input. | 48 // Parses a SignatureAlgorithm given invalid DER input. |
| 43 TEST(SignatureAlgorithmTest, ParseDerBogus) { | 49 TEST(SignatureAlgorithmTest, ParseDerBogus) { |
| 44 const uint8_t kData[] = {0x00}; | 50 const uint8_t kData[] = {0x00}; |
| 45 std::unique_ptr<SignatureAlgorithm> algorithm; | 51 std::unique_ptr<SignatureAlgorithm> algorithm; |
| 46 ASSERT_FALSE(ParseDer(kData, &algorithm)); | 52 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 47 } | 53 } |
| 48 | 54 |
| 49 // Parses a sha1WithRSAEncryption which contains a NULL parameters field. | 55 // Parses a sha1WithRSAEncryption which contains a NULL parameters field. |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); | 1060 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 1055 | 1061 |
| 1056 ASSERT_TRUE(params); | 1062 ASSERT_TRUE(params); |
| 1057 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); | 1063 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); |
| 1058 EXPECT_EQ(10u, params->salt_length()); | 1064 EXPECT_EQ(10u, params->salt_length()); |
| 1059 } | 1065 } |
| 1060 | 1066 |
| 1061 } // namespace | 1067 } // namespace |
| 1062 | 1068 |
| 1063 } // namespace net | 1069 } // namespace net |
| OLD | NEW |