Skip to content

Commit

Permalink
Attempt to fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewJohnHeath committed Sep 11, 2024
1 parent 9839326 commit 7768aec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
23 changes: 6 additions & 17 deletions crates/compiler/builtins/roc/Crypt.roc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ import Bool exposing [Eq]
import List
import Num exposing [U8, U64, U128]

Sha256 := { location : U64, }

Sha256 := {
location : U64,
}

Digest256 := {
firstHalf : U128,
secondHalf : U128,
} implements[Eq]
Digest256 := { firstHalf : U128, secondHalf : U128, } implements [Eq]

emptySha256 : {} -> Sha256

Expand All @@ -29,22 +23,17 @@ sha256AddBytes : Sha256, List U8 -> Sha256
sha256Digest : Sha256 -> Digest256

hashSha256 : List U8 -> Digest256
hashSha256 = \bytes ->
{} |> emptySha256
|> sha256AddBytes bytes
|> sha256Digest
hashSha256 = \bytes -> {} |> emptySha256 |> sha256AddBytes bytes |> sha256Digest

u128Bytes : U128 -> List U8
u128Bytes = \number ->
loop = \ n, bytes, place ->
loop = \n, bytes, place ->
if place == 16 then bytes
else
newByte = n
|> Num.bitwiseAnd 255
|> Num.toU8
newByte = n |> Num.bitwiseAnd 255 |> Num.toU8
loop (Num.shiftRightBy n 8) (List.prepend bytes newByte) (place + 1)
loop number [] 0

digest256ToBytes : Digest256 -> List U8
digest256ToBytes = \@Digest256{firstHalf, secondHalf} ->
digest256ToBytes = \@Digest256{ firstHalf, secondHalf } ->
List.concat (u128Bytes firstHalf) (u128Bytes secondHalf)
4 changes: 3 additions & 1 deletion crates/compiler/gen_wasm/src/low_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,9 @@ impl<'a> LowLevelCall<'a> {
NumF64FromParts => self.load_args_and_call_zig(backend, bitcode::NUM_F64_FROM_PARTS),
// Crypt
CryptEmptySha256 => self.load_args_and_call_zig(backend, bitcode::CRYPT_EMPTY_SHA256),
CryptSha256AddBytes => self.load_args_and_call_zig(backend, bitcode::CRYPT_SHA256_ADD_BYTES),
CryptSha256AddBytes => {
self.load_args_and_call_zig(backend, bitcode::CRYPT_SHA256_ADD_BYTES)
}
CryptSha256Digest => self.load_args_and_call_zig(backend, bitcode::CRYPT_SHA256_DIGEST),

And => {
Expand Down

0 comments on commit 7768aec

Please sign in to comment.