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 "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "net/base/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
10 #include "net/cert/pem_tokenizer.h" | 10 #include "net/cert/pem_tokenizer.h" |
11 #include "net/der/input.h" | 11 #include "net/der/input.h" |
12 #include "net/der/parser.h" | 12 #include "net/der/parser.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 // Creates a SignatureAlgorithm given the DER as a byte array. Returns true on | 19 // Creates a SignatureAlgorithm given the DER as a byte array. Returns true on |
20 // success and fills |*out| with a non-null pointer. | 20 // success and fills |*out| with a non-null pointer. |
21 template <size_t N> | 21 template <size_t N> |
22 bool ParseDer(const uint8_t(&data)[N], scoped_ptr<SignatureAlgorithm>* out) { | 22 bool ParseDer(const uint8_t(&data)[N], scoped_ptr<SignatureAlgorithm>* out) { |
23 *out = SignatureAlgorithm::CreateFromDer(der::Input(data, N)); | 23 *out = SignatureAlgorithm::CreateFromDer(der::Input(data, N)); |
24 return *out; | 24 return !!*out; |
25 } | 25 } |
26 | 26 |
27 // Parses a SignatureAlgorithm given an empty DER input. | 27 // Parses a SignatureAlgorithm given an empty DER input. |
28 TEST(SignatureAlgorithmTest, ParseDerEmpty) { | 28 TEST(SignatureAlgorithmTest, ParseDerEmpty) { |
29 scoped_ptr<SignatureAlgorithm> algorithm = | 29 scoped_ptr<SignatureAlgorithm> algorithm = |
30 SignatureAlgorithm::CreateFromDer(der::Input()); | 30 SignatureAlgorithm::CreateFromDer(der::Input()); |
31 ASSERT_FALSE(algorithm); | 31 ASSERT_FALSE(algorithm); |
32 } | 32 } |
33 | 33 |
34 // Parses a SignatureAlgorithm given invalid DER input. | 34 // Parses a SignatureAlgorithm given invalid DER input. |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); | 1031 const RsaPssParameters* params = algorithm->ParamsForRsaPss(); |
1032 | 1032 |
1033 ASSERT_TRUE(params); | 1033 ASSERT_TRUE(params); |
1034 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); | 1034 EXPECT_EQ(DigestAlgorithm::Sha256, params->mgf1_hash()); |
1035 EXPECT_EQ(10u, params->salt_length()); | 1035 EXPECT_EQ(10u, params->salt_length()); |
1036 } | 1036 } |
1037 | 1037 |
1038 } // namespace | 1038 } // namespace |
1039 | 1039 |
1040 } // namespace net | 1040 } // namespace net |
OLD | NEW |