From c573505826426359db9bacf4467c5dae454bf1a9 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Tue, 21 Nov 2023 23:52:40 +0000 Subject: [PATCH] More Pythonic Python binding --- randquik/cha.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/randquik/cha.py b/randquik/cha.py index 1e1216e..7f75448 100644 --- a/randquik/cha.py +++ b/randquik/cha.py @@ -81,9 +81,16 @@ class Cha: return out -def generate(out: bytearray | Any, key: bytes | Any, iv: bytes | Any): - """Setup a generator, fill the out buffer and dispose the generator""" +def generate_into( + out: bytearray | memoryview | Any, key: bytes | Any, iv: bytes | Any = bytes(16) +): + """Fill in random bytes into an existing array (buffer interface)""" key, iv = _processKeys(key, iv) outbuf, outlen = _processBuffer(out) lib.cha_generate(outbuf, outlen, key, iv) return out + + +def generate(outlen: int, key: bytes | Any, iv: bytes | Any = bytes(16)): + """Return a bytearray of random bytes""" + return generate_into(bytearray(outlen), key, iv)