Skip to content

Commit

Permalink
hash and hmac
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiwu committed Aug 3, 2024
1 parent ecc079b commit 2f167a8
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
24 changes: 23 additions & 1 deletion src/njs/crypto.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import gleam/javascript/array.{type Array}
import gleam/javascript/promise.{type Promise}
import njs/buffer.{type ArrayBuffer, type TypedArray}
import njs/buffer.{type ArrayBuffer, type Encoding, type TypedArray}

pub type Hmac

pub type Hash

pub type CryptoKey

Expand Down Expand Up @@ -71,3 +75,21 @@ pub fn import_key(
extractable e: Bool,
usages ku: Array(String),
) -> Promise(CryptoKey)

@external(javascript, "./crypto_ffi.mjs", "create_hash")
pub fn create_hash(algorithm a: String) -> Hash

@external(javascript, "./crypto_ffi.mjs", "hash_update")
pub fn hash_update(hash h: Hash, data d: BitArray) -> Hash

@external(javascript, "./crypto_ffi.mjs", "hash_digest")
pub fn hash_digest(hash h: Hash, encoding e: Encoding) -> String

@external(javascript, "./crypto_ffi.mjs", "create_hmac")
pub fn create_hmac(algorithm a: String, secret k: String) -> Hmac

@external(javascript, "./crypto_ffi.mjs", "hmac_update")
pub fn hmac_update(hmac h: Hmac, data d: BitArray) -> Hmac

@external(javascript, "./crypto_ffi.mjs", "hmac_digest")
pub fn hmac_digest(hmac h: Hmac, encoding e: Encoding) -> String
1 change: 0 additions & 1 deletion src/njs/fs.gleam

This file was deleted.

1 change: 0 additions & 1 deletion src/njs/misc.gleam

This file was deleted.

Empty file removed src/njs/njs_ffi.mjs
Empty file.
1 change: 0 additions & 1 deletion src/njs/stream.gleam

This file was deleted.

1 change: 0 additions & 1 deletion src/njs/xml.gleam

This file was deleted.

1 change: 0 additions & 1 deletion src/njs/zlib.gleam

This file was deleted.

0 comments on commit 2f167a8

Please sign in to comment.