Imported Upstream version 2.72.alpha
[platform/upstream/glib-networking.git] / tls / tests / files / update-test-database.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3
4 import sys
5 import cryptography.x509
6
7 try:
8     in_path = sys.argv[1]
9     out_path = sys.argv[2]
10 except IndexError:
11     sys.exit('USAGE: update-test-database.py ca.pem output_header.h')
12
13 with open(in_path, 'rb') as in_file:
14     cert_data = in_file.read()
15
16 cert = cryptography.x509.load_pem_x509_certificate(cert_data)
17 subject_data = cert.subject.public_bytes()
18 hex_subject = ''.join('\\x%02X' % b for b in subject_data)
19
20 header = '''/* This file is generated from update-test-database.py */
21
22 #define ISSUER_DATA "{}"
23 '''.format(hex_subject)
24
25 with open(out_path, 'w') as out_file:
26     out_file.write(header)