commit 089d090d1387158fbcf8db842b220a56655b56c7 parent cb2d3b21a75864d7cebc4d85b54741ba9512e24a Author: Armin Preiml <apreiml@strohwolke.at> Date: Wed, 14 Aug 2024 11:13:23 +0200 crypto::rsa: improve bitlen Signed-off-by: Armin Preiml <apreiml@strohwolke.at> Diffstat:
M | crypto/rsa/keys.ha | | | 8 | +++----- |
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/crypto/rsa/keys.ha b/crypto/rsa/keys.ha @@ -114,11 +114,9 @@ fn writeslice(dest: io::handle, a: []u8) (size | io::error) = { // Counts the bits for given slice 'n'. fn bitlen(s: []u8) size = { - for (s[0] == 0) { - s = s[1..]; - }; - - return countbits(s[0]) + 8 * (len(s) - 1); + let i = 0z; + for (i < len(s) && s[i] == 0; i += 1) void; + return countbits(s[i]) + 8 * (len(s) - i - 1); }; fn countbits(x: u8) size = {