commit 14e4c0d2fbbad560031532901a7d0f6aff22cf5a
parent d6a83c1a73fbab71d2e32f9eea612c34f6a6f777
Author: Sebastian <sebastian@sebsite.pw>
Date: Wed, 27 Apr 2022 21:00:48 -0400
all: use io::readall when full read is required
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
4 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/bufio/scanner.ha b/bufio/scanner.ha
@@ -12,7 +12,7 @@ use types;
export fn scanbyte(file: io::handle) (u8 | io::EOF | io::error) = {
let buf: [1]u8 = [0...];
- match (io::read(file, buf)?) {
+ match (io::readall(file, buf)?) {
case let read: size =>
if (read > 0) {
return buf[0];
@@ -57,9 +57,8 @@ export fn scanrune(
file: io::handle,
) (rune | utf8::invalid | io::EOF | io::error) = {
let b: [4]u8 = [0...];
- match (io::read(file, b[..1])?) {
- case let n: size =>
- assert(n == 1);
+ match (io::readall(file, b[..1])?) {
+ case let n: size => void;
case io::EOF =>
return io::EOF;
};
@@ -75,9 +74,8 @@ export fn scanrune(
return b[0]: u32: rune;
};
- match (io::read(file, b[1..sz])?) {
- case let n: size =>
- assert(n == sz - 1);
+ match (io::readall(file, b[1..sz])?) {
+ case let n: size => void;
case io::EOF =>
return io::EOF;
};
diff --git a/crypto/curve25519/+test.ha b/crypto/curve25519/+test.ha
@@ -203,9 +203,8 @@ use crypto::random;
let s: [SCALARSZ]u8 = [0...];
let u: [POINTSZ]u8 = [0...];
- // FIXME(laumann): check that enough was read
- io::read(random::stream, s[..])!;
- io::read(random::stream, u[..])!;
+ io::readall(random::stream, s[..])!;
+ io::readall(random::stream, u[..])!;
let hi0: [32]u8 = [0...];
let hi1: [32]u8 = [0...];
diff --git a/crypto/random/random.ha b/crypto/random/random.ha
@@ -30,7 +30,7 @@ export let stream: *io::stream = &_stream;
@test fn reader() void = {
let buf: [4096]u8 = [0...];
let test: []u8 = [];
- match (io::read(stream, buf[..])) {
+ match (io::readall(stream, buf[..])) {
case (io::error | io::EOF) =>
abort();
case let n: size =>
diff --git a/uuid/uuid.ha b/uuid/uuid.ha
@@ -112,11 +112,10 @@ export fn decode(in: io::handle) (uuid | invalid | io::error) = {
let u: uuid = [0...];
for (let i = 0z; i < len(u); i += 1) {
let buf: [2]u8 = [0...];
- match (io::read(in, buf)?) {
+ match (io::readall(in, buf)?) {
case io::EOF =>
return invalid;
- case let z: size =>
- assert(z == len(buf));
+ case let z: size => void;
};
u[i] = match (strconv::stou8b(
strings::fromutf8_unsafe(buf),
@@ -132,11 +131,10 @@ export fn decode(in: io::handle) (uuid | invalid | io::error) = {
|| i + 1 == TIME_HI_AND_VERSION
|| i + 1 == CLOCK_SEQ_HI_AND_RESERVED
|| i + 1 == NODE) {
- match (io::read(in, buf[..1])?) {
+ match (io::readall(in, buf[..1])?) {
case io::EOF =>
return invalid;
- case let z: size =>
- assert(z == 1);
+ case let z: size => void;
};
if (buf[0] != '-') {
return invalid;