Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(594)

Side by Side Diff: net/cert/internal/test_helpers.h

Issue 1279963003: Add a function for parsing RFC 5280's "TBSCertificate". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_mapper
Patch Set: one more comment fix Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cert/internal/parse_certificate_unittest.cc ('k') | net/cert/internal/test_helpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef NET_CERT_INTERNAL_TEST_HELPERS_H_ 5 #ifndef NET_CERT_INTERNAL_TEST_HELPERS_H_
6 #define NET_CERT_INTERNAL_TEST_HELPERS_H_ 6 #define NET_CERT_INTERNAL_TEST_HELPERS_H_
7 7
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 18 matching lines...) Expand all
29 // The returned der::Input() is only valid so long as the input string is alive 29 // The returned der::Input() is only valid so long as the input string is alive
30 // and is not mutated. 30 // and is not mutated.
31 // 31 //
32 // Note that the input parameter has been made a pointer to prevent callers 32 // Note that the input parameter has been made a pointer to prevent callers
33 // from accidentally passing an r-value. 33 // from accidentally passing an r-value.
34 der::Input InputFromString(const std::string* s); 34 der::Input InputFromString(const std::string* s);
35 35
36 // Helper structure that maps a PEM block header (for instance "CERTIFICATE") to 36 // Helper structure that maps a PEM block header (for instance "CERTIFICATE") to
37 // the destination where the value for that block should be written. 37 // the destination where the value for that block should be written.
38 struct PemBlockMapping { 38 struct PemBlockMapping {
39 // The name of the PEM header. Example "CERTIFICATE".
39 const char* block_name; 40 const char* block_name;
41
42 // The destination where the read value should be written to.
40 std::string* value; 43 std::string* value;
44
45 // True to indicate that the block is not required to be present. If the
46 // block is optional and is not present, then |value| will not be modified.
47 bool optional;
41 }; 48 };
42 49
43 // ReadTestDataFromPemFile() is a helper function that reads a PEM test file 50 // ReadTestDataFromPemFile() is a helper function that reads a PEM test file
44 // rooted in the "src/" directory. 51 // rooted in the "src/" directory.
45 // 52 //
46 // * file_path_ascii: 53 // * file_path_ascii:
47 // The path to the PEM file, relative to src. For instance 54 // The path to the PEM file, relative to src. For instance
48 // "net/data/verify_signed_data_unittest/foopy.pem" 55 // "net/data/verify_signed_data_unittest/foopy.pem"
49 // 56 //
50 // * mappings: 57 // * mappings:
51 // An array of length |mappings_length| which maps the expected PEM 58 // An array of length |mappings_length| which maps the expected PEM
52 // headers to the destination to write its data. 59 // headers to the destination to write its data.
53 // 60 //
54 // The function ensures that each of the chosen mappings is satisfied exactly 61 // The function ensures that each of the chosen mappings is satisfied exactly
55 // once. In other words, the header must be present, have valid data, and 62 // once. In other words, the header must be present (unless marked as
56 // appear no more than once. 63 // optional=true), have valid data, and appear no more than once.
57 ::testing::AssertionResult ReadTestDataFromPemFile( 64 ::testing::AssertionResult ReadTestDataFromPemFile(
58 const std::string& file_path_ascii, 65 const std::string& file_path_ascii,
59 const PemBlockMapping* mappings, 66 const PemBlockMapping* mappings,
60 size_t mappings_length); 67 size_t mappings_length);
61 68
62 // This is the same as the variant above, however it uses template magic so an 69 // This is the same as the variant above, however it uses template magic so an
63 // mappings array can be passed in directly (and the correct length is 70 // mappings array can be passed in directly (and the correct length is
64 // inferred). 71 // inferred).
65 template <size_t N> 72 template <size_t N>
66 ::testing::AssertionResult ReadTestDataFromPemFile( 73 ::testing::AssertionResult ReadTestDataFromPemFile(
67 const std::string& file_path_ascii, 74 const std::string& file_path_ascii,
68 const PemBlockMapping(&mappings)[N]) { 75 const PemBlockMapping(&mappings)[N]) {
69 return ReadTestDataFromPemFile(file_path_ascii, mappings, N); 76 return ReadTestDataFromPemFile(file_path_ascii, mappings, N);
70 } 77 }
71 78
72 } // namespace net 79 } // namespace net
73 80
74 #endif // NET_CERT_INTERNAL_TEST_HELPERS_H_ 81 #endif // NET_CERT_INTERNAL_TEST_HELPERS_H_
OLDNEW
« no previous file with comments | « net/cert/internal/parse_certificate_unittest.cc ('k') | net/cert/internal/test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698