blob: 6c209dc3753ea31f1b6949d25c6e91e221b6ab28 [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001Imported from Gentoo
2https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9c50acec16bc7c33d6dc122c007d713e7fbecf9c
3
4Signed-off-by: Khem Raj <raj.khem@gmail.com>
5
Andrew Geisslerc5535c92023-01-27 16:10:19 -06006Rebase for crda 4.15.
7
8Signed-off-by: Kai Kang <kai.kang@windriver.com>
9
10 utils/key2pub.py | 28 +++++++++++++++-------------
11 1 file changed, 15 insertions(+), 13 deletions(-)
12
13diff --git a/utils/key2pub.py b/utils/key2pub.py
14index 22fda55..2a4980b 100755
Andrew Geissler82c905d2020-04-13 13:39:40 -050015--- a/utils/key2pub.py
16+++ b/utils/key2pub.py
17@@ -1,22 +1,22 @@
18-#!/usr/bin/env python
19+#!/usr/bin/env python3
20
21 import sys
22 try:
23 from M2Crypto import RSA
24-except ImportError, e:
25+except ImportError as e:
26 sys.stderr.write('ERROR: Failed to import the "M2Crypto" module: %s\n' % e.message)
27 sys.stderr.write('Please install the "M2Crypto" Python module.\n')
28 sys.stderr.write('On Debian GNU/Linux the package is called "python-m2crypto".\n')
29 sys.exit(1)
30
31 def print_ssl_64(output, name, val):
32- while val[0] == '\0':
33+ while val[0:1] == b'\0':
34 val = val[1:]
35 while len(val) % 8:
36- val = '\0' + val
37+ val = b'\0' + val
38 vnew = []
39 while len(val):
40- vnew.append((val[0], val[1], val[2], val[3], val[4], val[5], val[6], val[7]))
41+ vnew.append((val[0:1], val[1:2], val[2:3], val[3:4], val[4:5], val[5:6], val[6:7], val[7:8]))
42 val = val[8:]
43 vnew.reverse()
44 output.write('static BN_ULONG %s[%d] = {\n' % (name, len(vnew)))
45@@ -34,13 +34,13 @@ def print_ssl_64(output, name, val):
46 output.write('};\n\n')
47
48 def print_ssl_32(output, name, val):
49- while val[0] == '\0':
50+ while val[0:1] == b'\0':
51 val = val[1:]
52 while len(val) % 4:
53- val = '\0' + val
54+ val = b'\0' + val
55 vnew = []
56 while len(val):
57- vnew.append((val[0], val[1], val[2], val[3], ))
58+ vnew.append((val[0:1], val[1:2], val[2:3], val[3:4]))
59 val = val[4:]
60 vnew.reverse()
61 output.write('static BN_ULONG %s[%d] = {\n' % (name, len(vnew)))
62@@ -81,21 +81,21 @@ struct pubkey {
63
64 static struct pubkey keys[] __attribute__((unused))= {
65 ''')
66- for n in xrange(n + 1):
67+ for n in range(n + 1):
68 output.write(' KEYS(e_%d, n_%d),\n' % (n, n))
69 output.write('};\n')
70 pass
71
72 def print_gcrypt(output, name, val):
73 output.write('#include <stdint.h>\n')
74- while val[0] == '\0':
75+ while val[0:1] == b'\0':
76 val = val[1:]
77 output.write('static const uint8_t %s[%d] = {\n' % (name, len(val)))
78 idx = 0
79 for v in val:
80 if not idx:
81 output.write('\t')
82- output.write('0x%.2x, ' % ord(v))
83+ output.write('0x%.2x, ' % (v if sys.version_info[0] >=3 else ord(v)))
84 idx += 1
85 if idx == 8:
86 idx = 0
87@@ -118,7 +118,7 @@ struct key_params {
88
Andrew Geisslerc5535c92023-01-27 16:10:19 -060089 static const struct key_params __attribute__ ((unused)) keys[] = {
Andrew Geissler82c905d2020-04-13 13:39:40 -050090 ''')
91- for n in xrange(n + 1):
92+ for n in range(n + 1):
93 output.write(' KEYS(e_%d, n_%d),\n' % (n, n))
94 output.write('};\n')
95
96@@ -136,7 +136,7 @@ except IndexError:
97 mode = None
98
99 if not mode in modes:
100- print 'Usage: %s [%s] input-file... output-file' % (sys.argv[0], '|'.join(modes.keys()))
101+ print('Usage: %s [%s] input-file... output-file' % (sys.argv[0], '|'.join(modes.keys())))
102 sys.exit(2)
103
104 output = open(outfile, 'w')
105@@ -154,3 +154,5 @@ for f in files:
106 idx += 1
107
108 modes[mode][1](output, idx - 1)
109+
110+output.close()