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/test_helpers.h" | 5 #include "net/cert/internal/test_helpers.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "net/cert/pem_tokenizer.h" | 11 #include "net/cert/pem_tokenizer.h" |
| 12 #include "net/der/parser.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
12 | 14 |
13 namespace net { | 15 namespace net { |
14 | 16 |
15 namespace der { | 17 namespace der { |
16 | 18 |
17 void PrintTo(const Input& data, ::std::ostream* os) { | 19 void PrintTo(const Input& data, ::std::ostream* os) { |
18 std::string b64; | 20 std::string b64; |
19 base::Base64Encode( | 21 base::Base64Encode( |
20 base::StringPiece(reinterpret_cast<const char*>(data.UnsafeData()), | 22 base::StringPiece(reinterpret_cast<const char*>(data.UnsafeData()), |
21 data.Length()), | 23 data.Length()), |
22 &b64); | 24 &b64); |
23 | 25 |
24 *os << "[" << b64 << "]"; | 26 *os << "[" << b64 << "]"; |
25 } | 27 } |
26 | 28 |
27 bool operator==(const Input& a, const Input& b) { | 29 bool operator==(const Input& a, const Input& b) { |
28 return a.Equals(b); | 30 return a.Equals(b); |
29 } | 31 } |
30 | 32 |
31 } // namespace der | 33 } // namespace der |
32 | 34 |
33 der::Input InputFromString(const std::string* s) { | 35 der::Input InputFromString(const std::string* s) { |
34 return der::Input(reinterpret_cast<const uint8_t*>(s->data()), s->size()); | 36 return der::Input(reinterpret_cast<const uint8_t*>(s->data()), s->size()); |
35 } | 37 } |
36 | 38 |
| 39 der::Input SequenceValueFromString(const std::string* s) { |
| 40 der::Parser parser(InputFromString(s)); |
| 41 der::Input data; |
| 42 if (!parser.ReadTag(der::kSequence, &data)) { |
| 43 ADD_FAILURE(); |
| 44 return der::Input(); |
| 45 } |
| 46 if (parser.HasMore()) { |
| 47 ADD_FAILURE(); |
| 48 return der::Input(); |
| 49 } |
| 50 return data; |
| 51 } |
| 52 |
37 ::testing::AssertionResult ReadTestDataFromPemFile( | 53 ::testing::AssertionResult ReadTestDataFromPemFile( |
38 const std::string& file_path_ascii, | 54 const std::string& file_path_ascii, |
39 const PemBlockMapping* mappings, | 55 const PemBlockMapping* mappings, |
40 size_t mappings_length) { | 56 size_t mappings_length) { |
41 // Compute the full path, relative to the src/ directory. | 57 // Compute the full path, relative to the src/ directory. |
42 base::FilePath src_root; | 58 base::FilePath src_root; |
43 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); | 59 PathService::Get(base::DIR_SOURCE_ROOT, &src_root); |
44 base::FilePath filepath = src_root.AppendASCII(file_path_ascii); | 60 base::FilePath filepath = src_root.AppendASCII(file_path_ascii); |
45 | 61 |
46 // Read the full contents of the PEM file. | 62 // Read the full contents of the PEM file. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (mapping.value && !mapping.optional) { | 102 if (mapping.value && !mapping.optional) { |
87 return ::testing::AssertionFailure() << "PEM block missing: " | 103 return ::testing::AssertionFailure() << "PEM block missing: " |
88 << mapping.block_name; | 104 << mapping.block_name; |
89 } | 105 } |
90 } | 106 } |
91 | 107 |
92 return ::testing::AssertionSuccess(); | 108 return ::testing::AssertionSuccess(); |
93 } | 109 } |
94 | 110 |
95 } // namespace net | 111 } // namespace net |
OLD | NEW |