1 | n/a | #!/usr/bin/python3 |
---|
2 | n/a | |
---|
3 | n/a | import os |
---|
4 | n/a | import re |
---|
5 | n/a | |
---|
6 | n/a | HERE = os.path.dirname(os.path.abspath(__file__)) |
---|
7 | n/a | BLAKE2 = os.path.join(HERE, 'impl') |
---|
8 | n/a | |
---|
9 | n/a | PUBLIC_SEARCH = re.compile(r'\ int (blake2[bs]p?[a-z_]*)\(') |
---|
10 | n/a | |
---|
11 | n/a | |
---|
12 | n/a | def getfiles(): |
---|
13 | n/a | for name in os.listdir(BLAKE2): |
---|
14 | n/a | name = os.path.join(BLAKE2, name) |
---|
15 | n/a | if os.path.isfile(name): |
---|
16 | n/a | yield name |
---|
17 | n/a | |
---|
18 | n/a | |
---|
19 | n/a | def find_public(): |
---|
20 | n/a | public_funcs = set() |
---|
21 | n/a | for name in getfiles(): |
---|
22 | n/a | with open(name) as f: |
---|
23 | n/a | for line in f: |
---|
24 | n/a | # find public functions |
---|
25 | n/a | mo = PUBLIC_SEARCH.search(line) |
---|
26 | n/a | if mo: |
---|
27 | n/a | public_funcs.add(mo.group(1)) |
---|
28 | n/a | |
---|
29 | n/a | for f in sorted(public_funcs): |
---|
30 | n/a | print('#define {0:<18} PyBlake2_{0}'.format(f)) |
---|
31 | n/a | |
---|
32 | n/a | return public_funcs |
---|
33 | n/a | |
---|
34 | n/a | |
---|
35 | n/a | def main(): |
---|
36 | n/a | lines = [] |
---|
37 | n/a | with open(os.path.join(HERE, 'blake2b_impl.c')) as f: |
---|
38 | n/a | for line in f: |
---|
39 | n/a | line = line.replace('blake2b', 'blake2s') |
---|
40 | n/a | line = line.replace('BLAKE2b', 'BLAKE2s') |
---|
41 | n/a | line = line.replace('BLAKE2B', 'BLAKE2S') |
---|
42 | n/a | lines.append(line) |
---|
43 | n/a | with open(os.path.join(HERE, 'blake2s_impl.c'), 'w') as f: |
---|
44 | n/a | f.write(''.join(lines)) |
---|
45 | n/a | # find_public() |
---|
46 | n/a | |
---|
47 | n/a | |
---|
48 | n/a | if __name__ == '__main__': |
---|
49 | n/a | main() |
---|