Skip to content

Commit

Permalink
fix: get around iter (#62)
Browse files Browse the repository at this point in the history
* ci: check all and release

* fix: temporary get around iter

* ci: fix moon coverage command
  • Loading branch information
peter-jerry-ye authored Sep 26, 2024
1 parent 3a09c6d commit babcf4a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crypto/sha224.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crypto/sha256.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crypto/sm3.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crypto/utils.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions fs/fs_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit babcf4a

Please sign in to comment.