Mercurial > hg > orthanc
comparison OrthancFramework/Resources/Patches/OpenSSL-ExtractProvidersOIDs.py @ 4702:312e0e29de90 openssl-3.x
compilation using openssl-3.0.0-beta1
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Jun 2021 07:09:34 +0200 |
parents | |
children | 0a5d05637701 |
comparison
equal
deleted
inserted
replaced
4701:68635d365a27 | 4702:312e0e29de90 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # Orthanc - A Lightweight, RESTful DICOM Store | |
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
5 # Department, University Hospital of Liege, Belgium | |
6 # Copyright (C) 2017-2021 Osimis S.A., Belgium | |
7 # | |
8 # This program is free software: you can redistribute it and/or | |
9 # modify it under the terms of the GNU Lesser General Public License | |
10 # as published by the Free Software Foundation, either version 3 of | |
11 # the License, or (at your option) any later version. | |
12 # | |
13 # This program is distributed in the hope that it will be useful, but | |
14 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 # Lesser General Public License for more details. | |
17 # | |
18 # You should have received a copy of the GNU Lesser General Public | |
19 # License along with this program. If not, see | |
20 # <http://www.gnu.org/licenses/>. | |
21 | |
22 | |
23 ## | |
24 ## This is a maintenance script to automatically extract the OIDs | |
25 ## generated from the ".asn1" files by the OpenSSL configuration | |
26 ## script "./Configure". This script generates the file | |
27 ## "OpenSSL-ExtractProvidersOIDs.json". The output JSON is then used | |
28 ## by "OpenSSL-ConfigureHeaders.py". | |
29 ## | |
30 | |
31 | |
32 import json | |
33 import os | |
34 import re | |
35 import sys | |
36 | |
37 if len(sys.argv) != 2: | |
38 raise Exception('Provide the path to your configured OpenSSL 3.x build directory') | |
39 | |
40 BASE = os.path.join(sys.argv[1], 'providers/common/include/prov') | |
41 TARGET = 'OpenSSL-ExtractProvidersOIDs.json' | |
42 RESULT = {} | |
43 | |
44 | |
45 for source in os.listdir(BASE): | |
46 if source.endswith('.h.in'): | |
47 path = os.path.join(BASE, re.sub('.in$', '', source)) | |
48 | |
49 content = {} | |
50 | |
51 with open(path, 'r') as f: | |
52 for definition in re.findall('#define (DER_OID_V_.+?)#define (DER_OID_SZ_.+?)extern const(.+?)$', f.read(), re.MULTILINE | re.DOTALL): | |
53 oid = definition[0].strip().split(' ') | |
54 | |
55 name = oid[0].replace('DER_OID_V_', '') | |
56 oid = oid[1:] | |
57 | |
58 sizes = definition[1].strip().split(' ') | |
59 if (name in content or | |
60 len(sizes) != 2 or | |
61 sizes[0] != 'DER_OID_SZ_%s' % name or | |
62 int(sizes[1]) != len(oid)): | |
63 raise Exception('Cannot parse %s, for OID %s' % (path, name)) | |
64 | |
65 content[name] = list(map(lambda x: x.replace(',', ''), oid)) | |
66 | |
67 RESULT[source] = content | |
68 | |
69 | |
70 with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), TARGET), 'w') as f: | |
71 f.write(json.dumps(RESULT, sort_keys = True, indent = 4)) |