diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index fe9556f..4c504f0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -51,8 +51,8 @@ jobs: - name: moon test run: | - moon test - moon test --target js + moon test --target all + moon test --target all --release - name: format diff run: | @@ -75,7 +75,7 @@ jobs: - name: coverage report run: | - moon coverage report -f summary summary > coverage_summary.txt + moon coverage report -f summary > coverage_summary.txt # Put the coverage report in the pipline output cat coverage_summary.txt >> "$GITHUB_STEP_SUMMARY" # We don't use the official coveralls upload tool because it takes >1min to build itself diff --git a/crypto/sha224.mbt b/crypto/sha224.mbt index 36c6726..90193bf 100644 --- a/crypto/sha224.mbt +++ b/crypto/sha224.mbt @@ -20,7 +20,7 @@ pub fn sha224(data : Bytes) -> Bytes { ], ) let _ = ctx.update(data) - arr_u32_to_u8be(ctx.sha256_compute().iter().take(7)) + arr_u32_to_u8be(ctx.sha256_compute().iter().take(7), 224) } pub fn sha224_from_iter(data : Iter[Byte]) -> Bytes { @@ -31,7 +31,7 @@ pub fn sha224_from_iter(data : Iter[Byte]) -> Bytes { ], ) let _ = ctx.update_from_iter(data) - arr_u32_to_u8be(ctx.sha256_compute().iter().take(7)) + arr_u32_to_u8be(ctx.sha256_compute().iter().take(7), 224) } test { diff --git a/crypto/sha256.mbt b/crypto/sha256.mbt index 3ecb9ad..f62e8b7 100644 --- a/crypto/sha256.mbt +++ b/crypto/sha256.mbt @@ -175,20 +175,20 @@ fn sha256_compute( /// Compute the Sha256 digest from given Sha256Context pub fn finalize(self : Sha256Context) -> Bytes { - arr_u32_to_u8be(self.sha256_compute().iter()) + arr_u32_to_u8be(self.sha256_compute().iter(), 256) } /// Compute the Sha256 digest in `Bytes` of some `data`. Note that Sha256 is big-endian. pub fn sha256(data : Bytes) -> Bytes { let ctx = Sha256Context::new() let _ = ctx.update(data) - arr_u32_to_u8be(ctx.sha256_compute().iter()) + arr_u32_to_u8be(ctx.sha256_compute().iter(), 256) } pub fn sha256_from_iter(data : Iter[Byte]) -> Bytes { let ctx = Sha256Context::new() let _ = ctx.update_from_iter(data) - arr_u32_to_u8be(ctx.sha256_compute().iter()) + arr_u32_to_u8be(ctx.sha256_compute().iter(), 256) } test { diff --git a/crypto/sm3.mbt b/crypto/sm3.mbt index 1d99507..4260657 100644 --- a/crypto/sm3.mbt +++ b/crypto/sm3.mbt @@ -236,20 +236,20 @@ fn sm3_compute( /// Compute the SM3 digest from given SM3Context pub fn finalize(self : SM3Context) -> Bytes { - arr_u32_to_u8be(self.sm3_compute().iter()) + arr_u32_to_u8be(self.sm3_compute().iter(), 256) } /// Compute the SM3 digest in `Bytes` of some `data`. Note that SM3 is big-endian. pub fn sm3(data : Bytes) -> Bytes { let ctx = SM3Context::new() let _ = ctx.update(data) - arr_u32_to_u8be(ctx.sm3_compute().iter()) + arr_u32_to_u8be(ctx.sm3_compute().iter(), 256) } pub fn sm3_from_iter(data : Iter[Byte]) -> Bytes { let ctx = SM3Context::new() let _ = ctx.update_from_iter(data) - arr_u32_to_u8be(ctx.sm3_compute().iter()) + arr_u32_to_u8be(ctx.sm3_compute().iter(), 256) } test { diff --git a/crypto/utils.mbt b/crypto/utils.mbt index caeb066..ee4a15e 100644 --- a/crypto/utils.mbt +++ b/crypto/utils.mbt @@ -90,8 +90,8 @@ fn bytes_u8_to_u32be(x : Bytes, ~i : Int = 0) -> UInt { /// convert an array of UInt to Bytes in big endian -fn arr_u32_to_u8be(x : Iter[UInt]) -> Bytes { - let temp : Bytes = Bytes::make(x.count() * 4, b'\x00') +fn arr_u32_to_u8be(x : Iter[UInt], bits : Int) -> Bytes { + let temp : Bytes = Bytes::new(bits / 8) x.eachi( fn(i, d) { temp[i * 4 + 0] = d.lsr(24).to_byte() diff --git a/fs/fs_test.mbt b/fs/fs_test.mbt index 1ce0042..05005d6 100644 --- a/fs/fs_test.mbt +++ b/fs/fs_test.mbt @@ -23,10 +23,12 @@ test "write_and_read" { , ) assert_true!(@fs.path_exists(~path)) - let byte = @fs.read_file_to_bytes!(~path).iter().map(fn(x) { x.to_uint() }) + let byte = @fs.read_file_to_bytes!(~path) inspect!( byte, - content="[116, 97, 114, 103, 101, 116, 47, 10, 46, 109, 111, 111, 110, 99, 97, 107, 101, 115, 47, 10]", + content= + #|b"\x74\x61\x72\x67\x65\x74\x2f\x0a\x2e\x6d\x6f\x6f\x6e\x63\x61\x6b\x65\x73\x2f\x0a" + , ) @fs.remove_file!(~path) assert_false!(@fs.path_exists(~path))