Skip to content

Commit

Permalink
Docs for exposed functions and types
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewJohnHeath committed Sep 12, 2024
1 parent d61a7ee commit 2bfad6f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/compiler/builtins/roc/Crypt.roc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ import Num exposing [U8, U64, U128]
import Result
import Str

## Represents, as an opaque type, the state of a SHA256 cryptographic hashing function, after some (or no) data have been added to the hash.
Sha256 := { location : U64 }

## Represents the digest of soem data produced by the SHA256 cryptographic hashing function as an opaque type.
## `Digest256`implements the `Eq` ability.
Digest256 := { firstHalf : U128, secondHalf : U128 } implements [Eq]

## Returns a `Sha256` to which no data have been added.
emptySha256 : {} -> Sha256

## Adds bytes of data to be hashed in the `Sha256`.
sha256AddBytes : Sha256, List U8 -> Sha256

## Returns the digest of the cryptographic hashing function represted by a`Sha256`.
sha256Digest : Sha256 -> Digest256

## Applies the SHA256 crytographic hashing function to some bytes.
hashSha256 : List U8 -> Digest256
hashSha256 = \bytes -> emptySha256 {} |> sha256AddBytes bytes |> sha256Digest

Expand All @@ -37,6 +44,7 @@ u128Bytes = \number ->
loop (Num.shiftRightBy n 8) (List.prepend bytes newByte) (place + 1)
loop number [] 0

## Returns the bytes of a `Digest256`as a list.
digest256ToBytes : Digest256 -> List U8
digest256ToBytes = \@Digest256 { firstHalf, secondHalf } ->
List.concat (u128Bytes firstHalf) (u128Bytes secondHalf)
Expand Down

0 comments on commit 2bfad6f

Please sign in to comment.