()
| 104 | |
| 105 | |
| 106 | def main(): |
| 107 | args = parser.parse_args() |
| 108 | |
| 109 | args.err_h = os.path.join(args.srcdir, "include", "openssl", "err.h") |
| 110 | if not os.path.isfile(args.err_h): |
| 111 | # Fall back to infile for OpenSSL 3.0.0 |
| 112 | args.err_h += ".in" |
| 113 | args.errcodes = os.path.join(args.srcdir, "crypto", "err", "openssl.ec") |
| 114 | args.errtxt = os.path.join(args.srcdir, "crypto", "err", "openssl.txt") |
| 115 | |
| 116 | if not os.path.isfile(args.errtxt): |
| 117 | parser.error(f"File {args.errtxt} not found in srcdir\n.") |
| 118 | |
| 119 | # {X509: 11, ...} |
| 120 | args.lib2errnum = parse_err_h(args) |
| 121 | |
| 122 | # [('X509_R_AKID_MISMATCH', 'X509', 'AKID_MISMATCH', 110), ...] |
| 123 | reasons = [] |
| 124 | reasons.extend(parse_openssl_error_text(args)) |
| 125 | reasons.extend(parse_extra_reasons(args)) |
| 126 | # sort by libname, numeric error code |
| 127 | args.reasons = sorted(reasons, key=operator.itemgetter(0, 3)) |
| 128 | |
| 129 | lines = [ |
| 130 | "// File generated by tools/make_ssl_data_rs.py", |
| 131 | f"// Generated on {datetime.datetime.now(datetime.timezone.utc).isoformat()}", |
| 132 | f"// Source: OpenSSL from {args.srcdir}", |
| 133 | "// spell-checker: disable", |
| 134 | "", |
| 135 | "use phf::phf_map;", |
| 136 | "", |
| 137 | ] |
| 138 | lines.extend(gen_library_codes_rust(args)) |
| 139 | lines.extend(gen_error_codes_rust(args)) |
| 140 | |
| 141 | # Add helper function |
| 142 | lines.extend( |
| 143 | [ |
| 144 | "/// Helper function to create encoded key from (lib, reason) pair", |
| 145 | "#[inline]", |
| 146 | "pub fn encode_error_key(lib: i32, reason: i32) -> u64 {", |
| 147 | " ((lib as u64) << 32) | (reason as u64 & 0xFFFFFFFF)", |
| 148 | "}", |
| 149 | "", |
| 150 | ] |
| 151 | ) |
| 152 | |
| 153 | if args.output is None: |
| 154 | for line in lines: |
| 155 | print(line) |
| 156 | else: |
| 157 | with open(args.output, "w") as output: |
| 158 | for line in lines: |
| 159 | print(line, file=output) |
| 160 | |
| 161 | print(f"Generated {args.output}") |
| 162 | print(f"Found {len(args.lib2errnum)} library codes") |
| 163 | print(f"Found {len(args.reasons)} error codes") |
no test coverage detected