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