1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0 OR ISC
3
3
4
- #ifndef INTERNAL_H
5
- #define INTERNAL_H
4
+ #ifndef TOOL_OPENSSL_INTERNAL_H
5
+ #define TOOL_OPENSSL_INTERNAL_H
6
6
7
- #include " ../tool/internal.h"
8
7
#include < openssl/digest.h>
8
+ #include < algorithm>
9
9
#include < string>
10
+ #include < utility>
10
11
#include < vector>
12
+ #include " ../tool/internal.h"
11
13
12
14
#if !defined(O_BINARY)
13
15
#define O_BINARY 0
@@ -20,12 +22,13 @@ struct Tool {
20
22
tool_func_t func;
21
23
};
22
24
23
- bool IsNumeric (const std::string& str);
25
+ bool IsNumeric (const std::string & str);
24
26
25
- X509* CreateAndSignX509Certificate ();
26
- X509_CRL* createTestCRL ();
27
+ X509 * CreateAndSignX509Certificate ();
28
+ X509_CRL * createTestCRL ();
27
29
28
- bool LoadPrivateKeyAndSignCertificate (X509 *x509, const std::string &signkey_path);
30
+ bool LoadPrivateKeyAndSignCertificate (X509 *x509,
31
+ const std::string &signkey_path);
29
32
30
33
tool_func_t FindTool (const std::string &name);
31
34
tool_func_t FindTool (int argc, char **argv, int &starting_arg);
@@ -46,27 +49,76 @@ bssl::UniquePtr<X509_NAME> parse_subject_name(std::string &subject_string);
46
49
47
50
48
51
// Rehash tool Utils
49
- typedef struct hash_entry_st { // Represents a single certificate/CRL file
50
- struct hash_entry_st *next; // Links to next entry in same bucket
51
- char *filename; // Actual filename
52
- uint8_t digest[EVP_MAX_MD_SIZE]; // File's cryptographic digest
52
+ typedef struct hash_entry_st { // Represents a single certificate/CRL file
53
+ struct hash_entry_st *next; // Links to next entry in same bucket
54
+ char *filename; // Actual filename
55
+ uint8_t digest[EVP_MAX_MD_SIZE]; // File's cryptographic digest
53
56
} HASH_ENTRY;
54
57
55
- typedef struct bucket_st { // Groups entries with same hash
56
- struct bucket_st *next; // Links to next bucket in hash table slot
57
- HASH_ENTRY *first_entry; // Start of entry list
58
- HASH_ENTRY *last_entry; // End of entry list
59
- uint32_t hash; // Hash value of the certificates/CRLs
60
- uint16_t type; // CERT or CRL Bucket
61
- uint16_t num_entries; // Count of entries
58
+ typedef struct bucket_st { // Groups entries with same hash
59
+ struct bucket_st *next; // Links to next bucket in hash table slot
60
+ HASH_ENTRY *first_entry; // Start of entry list
61
+ HASH_ENTRY *last_entry; // End of entry list
62
+ uint32_t hash; // Hash value of the certificates/CRLs
63
+ uint16_t type; // CERT or CRL Bucket
64
+ uint16_t num_entries; // Count of entries
62
65
} BUCKET;
63
66
64
- enum Type {
65
- TYPE_CERT=0 , TYPE_CRL=1
66
- };
67
+ enum Type { TYPE_CERT = 0 , TYPE_CRL = 1 };
67
68
void add_entry (enum Type type, uint32_t hash, const char *filename,
68
- const uint8_t *digest);
69
- BUCKET** get_table ();
69
+ const uint8_t *digest);
70
+ BUCKET ** get_table ();
70
71
void cleanup_hash_table ();
71
72
72
- #endif // INTERNAL_H
73
+ // Ordered argument processing (specific to tool-openssl)
74
+ namespace ordered_args {
75
+ typedef std::vector<std::pair<std::string, std::string>> ordered_args_map_t ;
76
+
77
+ // Helper function to find an argument in the ordered args vector
78
+ static inline bool HasArgument (const ordered_args_map_t &args,
79
+ const std::string &arg_name) {
80
+ return std::find_if (
81
+ args.begin (), args.end (),
82
+ [&arg_name](const std::pair<std::string, std::string> &pair) {
83
+ return pair.first == arg_name;
84
+ }) != args.end ();
85
+ }
86
+
87
+ // Helper function to count occurrences of an argument
88
+ static inline size_t CountArgument (const ordered_args_map_t &args,
89
+ const std::string &arg_name) {
90
+ size_t count = 0 ;
91
+ for (const auto &pair : args) {
92
+ if (pair.first == arg_name) {
93
+ count++;
94
+ }
95
+ }
96
+ return count;
97
+ }
98
+
99
+ // Helper function to find an argument in the ordered args vector
100
+ static inline ordered_args_map_t ::const_iterator FindArg (
101
+ const ordered_args_map_t &args, const std::string &arg_name) {
102
+ return std::find_if (
103
+ args.begin (), args.end (),
104
+ [&arg_name](const std::pair<std::string, std::string> &pair) {
105
+ return pair.first == arg_name;
106
+ });
107
+ }
108
+
109
+ // Parse arguments in order of appearance
110
+ bool ParseOrderedKeyValueArguments (ordered_args_map_t &out_args,
111
+ args_list_t &extra_args,
112
+ const args_list_t &args,
113
+ const argument_t *templates);
114
+
115
+ // Get helpers for ordered arguments
116
+ bool GetUnsigned (unsigned *out, const std::string &arg_name,
117
+ unsigned default_value, const ordered_args_map_t &args);
118
+ bool GetString (std::string *out, const std::string &arg_name,
119
+ std::string default_value, const ordered_args_map_t &args);
120
+ bool GetBoolArgument (bool *out, const std::string &arg_name,
121
+ const ordered_args_map_t &args);
122
+ } // namespace ordered_args
123
+
124
+ #endif // TOOL_OPENSSL_INTERNAL_H
0 commit comments