diff options
| author | Donald Sharp <donaldsharp72@gmail.com> | 2022-11-03 08:54:09 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-03 08:54:09 -0400 |
| commit | d7cde18c63c4eef83e12f562aa025cf1dbeaee05 (patch) | |
| tree | 591e68540bb026cfe9f212a69c150bfcfa8bbf36 /python/clippy/uidhash.py | |
| parent | 70f29b9f7bf157cd439518cba0ecd52efcf22429 (diff) | |
| parent | 6c7bc49428b594e0747af9813b4c510bd2817f4e (diff) | |
Merge pull request #12196 from opensourcerouting/xref-vtysh
*: rewrite `extract.pl` using `xref` infra
Diffstat (limited to 'python/clippy/uidhash.py')
| -rw-r--r-- | python/clippy/uidhash.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/python/clippy/uidhash.py b/python/clippy/uidhash.py index bf994d389e..0fd886221a 100644 --- a/python/clippy/uidhash.py +++ b/python/clippy/uidhash.py @@ -19,13 +19,14 @@ import struct from hashlib import sha256 -def bititer(data, bits, startbit = True): - ''' + +def bititer(data, bits, startbit=True): + """ just iterate the individual bits out from a bytes object if startbit is True, an '1' bit is inserted at the very beginning goes <bits> at a time, starts at LSB. - ''' + """ bitavail, v = 0, 0 if startbit and len(data) > 0: v = data.pop(0) @@ -41,31 +42,33 @@ def bititer(data, bits, startbit = True): bitavail -= bits v >>= bits + def base32c(data): - ''' + """ Crockford base32 with extra dashes - ''' + """ chs = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" - o = '' + o = "" if type(data) == str: data = [ord(v) for v in data] else: data = list(data) for i, bits in enumerate(bititer(data, 5)): if i == 5: - o = o + '-' + o = o + "-" elif i == 10: break o = o + chs[bits] return o + def uidhash(filename, hashstr, hashu32a, hashu32b): - ''' + """ xref Unique ID hash used in FRRouting - ''' - filename = '/'.join(filename.rsplit('/')[-2:]) + """ + filename = "/".join(filename.rsplit("/")[-2:]) - hdata = filename.encode('UTF-8') + hashstr.encode('UTF-8') - hdata += struct.pack('>II', hashu32a, hashu32b) + hdata = filename.encode("UTF-8") + hashstr.encode("UTF-8") + hdata += struct.pack(">II", hashu32a, hashu32b) i = sha256(hdata).digest() return base32c(i) |
