Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(32502)

Delta Between Two Patch Sets: Modules/_blake2/blake2b2s.py

Issue 26798: add BLAKE2 to hashlib
Left Patch Set: Created 3 years, 5 months ago
Right Patch Set: Created 3 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Makefile.pre.in ('k') | Modules/_blake2/blake2b_impl.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/python3 1 #!/usr/bin/python3
2 2
3 import os 3 import os
4 import re 4 import re
5 5
6 HERE = os.path.dirname(os.path.abspath(__file__)) 6 HERE = os.path.dirname(os.path.abspath(__file__))
7 BLAKE2 = os.path.join(HERE, 'impl') 7 BLAKE2 = os.path.join(HERE, 'impl')
8 8
9 CPP1 = re.compile(r'^//(.*)')
10 CPP2 = re.compile(r'\ //(.*)')
11 INLINE = re.compile(r'^static\ inline\ ([a-z0-9_]+)')
12 PUBLIC_SEARCH = re.compile(r'\ int (blake2[bs]p?[a-z_]*)\(') 9 PUBLIC_SEARCH = re.compile(r'\ int (blake2[bs]p?[a-z_]*)\(')
13 10
14 11
15 def getfiles(): 12 def getfiles():
16 for name in os.listdir(BLAKE2): 13 for name in os.listdir(BLAKE2):
17 name = os.path.join(BLAKE2, name) 14 name = os.path.join(BLAKE2, name)
18 if os.path.isfile(name): 15 if os.path.isfile(name):
19 yield name 16 yield name
20 17
21 18
22 def cleanup(f): 19 def find_public():
23 lines = []
24 funcs = set()
25 for line in f:
26 # Py_LOCAL_INLINE()
27 line = INLINE.sub(r'Py_LOCAL_INLINE(\1)', line)
28 # transform C++ comments into ANSI C comments
29 line = CPP1.sub(r'/*\1 */', line)
30 line = CPP2.sub(r' /*\1 */', line)
31 # find public functions
32 mo = PUBLIC_SEARCH.search(line)
33 if mo:
34 funcs.add(mo.group(1))
35 lines.append(line)
36 return lines, funcs
37
38
39 def cleanup_files():
40 public_funcs = set() 20 public_funcs = set()
41 for name in getfiles(): 21 for name in getfiles():
42 with open(name) as f: 22 with open(name) as f:
43 lines, funcs = cleanup(f) 23 for line in f:
44 with open(name, 'w') as f: 24 # find public functions
45 f.write(''.join(lines)) 25 mo = PUBLIC_SEARCH.search(line)
46 public_funcs.update(funcs) 26 if mo:
27 public_funcs.add(mo.group(1))
47 28
48 for f in sorted(public_funcs): 29 for f in sorted(public_funcs):
49 print('#define {0:<18} PyBlake2_{0}'.format(f)) 30 print('#define {0:<18} PyBlake2_{0}'.format(f))
50 31
51 return public_funcs 32 return public_funcs
52 33
53 34
54 def main(): 35 def main():
55 lines = [] 36 lines = []
56 with open(os.path.join(HERE, 'blake2b_impl.c')) as f: 37 with open(os.path.join(HERE, 'blake2b_impl.c')) as f:
57 for line in f: 38 for line in f:
58 line = line.replace('blake2b', 'blake2s') 39 line = line.replace('blake2b', 'blake2s')
59 line = line.replace('BLAKE2b', 'BLAKE2s') 40 line = line.replace('BLAKE2b', 'BLAKE2s')
60 line = line.replace('BLAKE2B', 'BLAKE2S') 41 line = line.replace('BLAKE2B', 'BLAKE2S')
61 lines.append(line) 42 lines.append(line)
62 with open(os.path.join(HERE, 'blake2s_impl.c'), 'w') as f: 43 with open(os.path.join(HERE, 'blake2s_impl.c'), 'w') as f:
63 f.write(''.join(lines)) 44 f.write(''.join(lines))
64 # change reference implementation 45 # find_public()
65 # cleanup_files()
66 46
67 47
68 if __name__ == '__main__': 48 if __name__ == '__main__':
69 main() 49 main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+