| 1 | module engine |
| 2 | |
| 3 | import crypto.md5 |
| 4 | import crypto.sha256 |
| 5 | import os |
| 6 | |
| 7 | fn test_checksums() ! { |
| 8 | dir := os.join_path(os.vtmp_dir(), 'alpm-native-checksum-${os.getpid()}') |
| 9 | os.mkdir_all(dir)! |
| 10 | defer { os.rmdir_all(dir) or { eprintln(err) } } |
| 11 | path := os.join_path(dir, 'payload') |
| 12 | for data in [[]u8{}, 'abc'.bytes(), []u8{len: 32768, init: u8(index % 251)}, |
| 13 | []u8{len: 100003, init: u8(index % 251)}] { |
| 14 | os.write_file_array(path, data)! |
| 15 | assert compute_md5sum(path)? == md5.sum(data).hex() |
| 16 | assert compute_sha256sum(path)? == sha256.sum256(data).hex() |
| 17 | } |
| 18 | assert compute_md5sum(path + '-missing') == none |
| 19 | assert compute_sha256sum(path + '-missing') == none |
| 20 | // opening a directory succeeds on linux; reading it must fail, not hash EOF. |
| 21 | assert compute_md5sum(dir) == none |
| 22 | assert compute_sha256sum(dir) == none |
| 23 | } |
| 24 | |