annotate OrthancFramework/Resources/Patches/OpenSSL-ExtractProvidersOIDs.py @ 5519:2c5eb1ef26a0 pg-transactions

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