hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 65775f44d5f3984c4746c4700aa3da57224cc89d
parent ad851674d7f88fb13f36484c6fa9bf757d412589
Author: Ajay R <ar324@protonmail.com>
Date:   Mon, 21 Feb 2022 07:05:26 +0000

encoding::base32: add ASCII check for encoding alphabet

Signed-off-by: Ajay R <ar324@protonmail.com>

Diffstat:
Mencoding/base32/base32.ha | 9+++++----
Mscripts/gen-stdlib | 2+-
Mstdlib.mk | 4++--
3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/encoding/base32/base32.ha b/encoding/base32/base32.ha @@ -1,3 +1,4 @@ +use ascii; use bufio; use bytes; use errors; @@ -22,11 +23,11 @@ export const hex_encoding: encoding = encoding { ... }; // Initializes a new encoding based on the passed alphabet, which must be a // 32-byte ASCII string. export fn encoding_init(enc: *encoding, alphabet: str) void = { - let runes = strings::runes(alphabet); - assert(len(runes) == 32); - defer free(runes); + const alphabet = strings::toutf8(alphabet); + assert(len(alphabet) == 32); for (let i: u8 = 0; i < 32; i += 1) { - let ch = runes[i]: u32: u8; + const ch = alphabet[i]; + assert(ascii::isascii(ch: u32: rune)); enc.encmap[i] = ch; enc.decmap[ch] = i; enc.valid[ch] = true; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -428,7 +428,7 @@ encoding_base64() { encoding_base32() { gen_srcs encoding::base32 \ base32.ha - gen_ssa encoding::base32 bufio bytes errors io strings os + gen_ssa encoding::base32 ascii bufio bytes errors io strings os } encoding_hex() { diff --git a/stdlib.mk b/stdlib.mk @@ -909,7 +909,7 @@ $(HARECACHE)/encoding/base64/encoding_base64-any.ssa: $(stdlib_encoding_base64_a stdlib_encoding_base32_any_srcs= \ $(STDLIB)/encoding/base32/base32.ha -$(HARECACHE)/encoding/base32/encoding_base32-any.ssa: $(stdlib_encoding_base32_any_srcs) $(stdlib_rt) $(stdlib_bufio_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) +$(HARECACHE)/encoding/base32/encoding_base32-any.ssa: $(stdlib_encoding_base32_any_srcs) $(stdlib_rt) $(stdlib_ascii_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/encoding/base32 @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nencoding::base32 \ @@ -2752,7 +2752,7 @@ $(TESTCACHE)/encoding/base64/encoding_base64-any.ssa: $(testlib_encoding_base64_ testlib_encoding_base32_any_srcs= \ $(STDLIB)/encoding/base32/base32.ha -$(TESTCACHE)/encoding/base32/encoding_base32-any.ssa: $(testlib_encoding_base32_any_srcs) $(testlib_rt) $(testlib_bufio_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_os_$(PLATFORM)) +$(TESTCACHE)/encoding/base32/encoding_base32-any.ssa: $(testlib_encoding_base32_any_srcs) $(testlib_rt) $(testlib_ascii_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_os_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/encoding/base32 @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nencoding::base32 \