From 2bfad6f587170f1d5dfc821ae4a9458877e2371f Mon Sep 17 00:00:00 2001 From: Mattthew Heath Date: Thu, 12 Sep 2024 21:26:19 +0100 Subject: [PATCH] Docs for exposed functions and types --- crates/compiler/builtins/roc/Crypt.roc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/compiler/builtins/roc/Crypt.roc b/crates/compiler/builtins/roc/Crypt.roc index f96857ab9f..10b24348cf 100644 --- a/crates/compiler/builtins/roc/Crypt.roc +++ b/crates/compiler/builtins/roc/Crypt.roc @@ -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 @@ -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)