module engine import crypto.md5 import crypto.sha256 import os fn test_checksums() ! { dir := os.join_path(os.vtmp_dir(), 'alpm-native-checksum-${os.getpid()}') os.mkdir_all(dir)! defer { os.rmdir_all(dir) or { eprintln(err) } } path := os.join_path(dir, 'payload') for data in [[]u8{}, 'abc'.bytes(), []u8{len: 32768, init: u8(index % 251)}, []u8{len: 100003, init: u8(index % 251)}] { os.write_file_array(path, data)! assert compute_md5sum(path)? == md5.sum(data).hex() assert compute_sha256sum(path)? == sha256.sum256(data).hex() } assert compute_md5sum(path + '-missing') == none assert compute_sha256sum(path + '-missing') == none // opening a directory succeeds on linux; reading it must fail, not hash EOF. assert compute_md5sum(dir) == none assert compute_sha256sum(dir) == none }