File: blake2b2s.py

package info (click to toggle)
python3.13 3.13.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 121,256 kB
  • sloc: python: 703,743; ansic: 653,888; xml: 31,250; sh: 5,844; cpp: 4,326; makefile: 1,981; objc: 787; lisp: 502; javascript: 213; asm: 75; csh: 12
file content (49 lines) | stat: -rwxr-xr-x 1,208 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3

import os
import re

HERE = os.path.dirname(os.path.abspath(__file__))
BLAKE2 = os.path.join(HERE, 'impl')

PUBLIC_SEARCH = re.compile(r'\ int (blake2[bs]p?[a-z_]*)\(')


def getfiles():
    for name in os.listdir(BLAKE2):
        name = os.path.join(BLAKE2, name)
        if os.path.isfile(name):
            yield name


def find_public():
    public_funcs = set()
    for name in getfiles():
        with open(name) as f:
            for line in f:
                # find public functions
                mo = PUBLIC_SEARCH.search(line)
                if mo:
                    public_funcs.add(mo.group(1))

    for f in sorted(public_funcs):
        print('#define {0:<18} PyBlake2_{0}'.format(f))

    return public_funcs


def main():
    lines = []
    with open(os.path.join(HERE, 'blake2b_impl.c')) as f:
        for line in f:
            line = line.replace('blake2b', 'blake2s')
            line = line.replace('BLAKE2b', 'BLAKE2s')
            line = line.replace('BLAKE2B', 'BLAKE2S')
            lines.append(line)
    with open(os.path.join(HERE, 'blake2s_impl.c'), 'w') as f:
        f.write(''.join(lines))
    # find_public()


if __name__ == '__main__':
    main()