| 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/pem_tokenizer.h" | 12 #include "net/cert/pem_tokenizer.h" |
| 12 #include "net/der/input.h" | 13 #include "net/der/input.h" |
| 13 #include "net/der/parser.h" | 14 #include "net/der/parser.h" |
| 14 #include "net/test/test_data_directory.h" | 15 #include "net/test/test_data_directory.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // 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 |
| 22 // success and fills |*out| with a non-null pointer. | 23 // success and fills |*out| with a non-null pointer. |
| 23 template <size_t N> | 24 template <size_t N> |
| 24 bool ParseDer(const uint8_t (&data)[N], | 25 bool ParseDer(const uint8_t (&data)[N], |
| 25 std::unique_ptr<SignatureAlgorithm>* out) { | 26 std::unique_ptr<SignatureAlgorithm>* out) { |
| 26 *out = SignatureAlgorithm::CreateFromDer(der::Input(data, N)); | 27 // TODO(crbug.com/634443): Test the errors. |
| 28 CertErrors errors; |
| 29 *out = SignatureAlgorithm::Create(der::Input(data, N), &errors); |
| 27 return !!*out; | 30 return !!*out; |
| 28 } | 31 } |
| 29 | 32 |
| 30 // Parses a SignatureAlgorithm given an empty DER input. | 33 // Parses a SignatureAlgorithm given an empty DER input. |
| 31 TEST(SignatureAlgorithmTest, ParseDerEmpty) { | 34 TEST(SignatureAlgorithmTest, ParseDerEmpty) { |
| 35 // TODO(crbug.com/634443): Test the errors. |
| 36 CertErrors errors; |
| 32 std::unique_ptr<SignatureAlgorithm> algorithm = | 37 std::unique_ptr<SignatureAlgorithm> algorithm = |
| 33 SignatureAlgorithm::CreateFromDer(der::Input()); | 38 SignatureAlgorithm::Create(der::Input(), &errors); |
| 34 ASSERT_FALSE(algorithm); | 39 ASSERT_FALSE(algorithm); |
| 35 } | 40 } |
| 36 | 41 |
| 37 // Parses a SignatureAlgorithm given invalid DER input. | 42 // Parses a SignatureAlgorithm given invalid DER input. |
| 38 TEST(SignatureAlgorithmTest, ParseDerBogus) { | 43 TEST(SignatureAlgorithmTest, ParseDerBogus) { |
| 39 const uint8_t kData[] = {0x00}; | 44 const uint8_t kData[] = {0x00}; |
| 40 std::unique_ptr<SignatureAlgorithm> algorithm; | 45 std::unique_ptr<SignatureAlgorithm> algorithm; |
| 41 ASSERT_FALSE(ParseDer(kData, &algorithm)); | 46 ASSERT_FALSE(ParseDer(kData, &algorithm)); |
| 42 } | 47 } |
| 43 | 48 |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); | 1054 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
| 1050 | 1055 |
| 1051 ASSERT_TRUE(params); | 1056 ASSERT_TRUE(params); |
| 1052 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); | 1057 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); |
| 1053 EXPECT_EQ(10u, params->salt_length()); | 1058 EXPECT_EQ(10u, params->salt_length()); |
| 1054 } | 1059 } |
| 1055 | 1060 |
| 1056 } // namespace | 1061 } // namespace |
| 1057 | 1062 |
| 1058 } // namespace net | 1063 } // namespace net |
| OLD | NEW |