diff options
author | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 09:58:56 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@ydb.tech> | 2023-11-14 10:20:20 +0300 |
commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/python/scramp/scramp/utils.py | |
parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
download | ydb-c2b2dfd9827a400a8495e172a56343462e3ceb82.tar.gz |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/python/scramp/scramp/utils.py')
-rw-r--r-- | contrib/python/scramp/scramp/utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/contrib/python/scramp/scramp/utils.py b/contrib/python/scramp/scramp/utils.py new file mode 100644 index 0000000000..47e454e1ae --- /dev/null +++ b/contrib/python/scramp/scramp/utils.py @@ -0,0 +1,34 @@ +import hmac as hmaca +from base64 import b64decode, b64encode + + +def hmac(hf, key, msg): + return hmaca.new(key, msg=msg, digestmod=hf).digest() + + +def h(hf, msg): + return hf(msg).digest() + + +def hi(hf, password, salt, iterations): + u = ui = hmac(hf, password, salt + b"\x00\x00\x00\x01") + for i in range(iterations - 1): + ui = hmac(hf, password, ui) + u = xor(u, ui) + return u + + +def xor(bytes1, bytes2): + return bytes(a ^ b for a, b in zip(bytes1, bytes2)) + + +def b64enc(binary): + return b64encode(binary).decode("utf8") + + +def b64dec(string): + return b64decode(string) + + +def uenc(string): + return string.encode("utf-8") |