From f5820dd0321540fb428dc796ed2ab893a3c8615b Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Wed, 15 Jan 2025 21:27:08 +0800 Subject: [PATCH 1/2] feat(crypto): add some new Hash module functions. - updateString - updateStringWithEncoding - digestWithEncoding NOTE: The second parameter of `digestWithEncoding` brings a new type `BinaryToTextEncodingThe.t`. --- src/Crypto.res | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Crypto.res b/src/Crypto.res index 24e3caf..62e38ad 100644 --- a/src/Crypto.res +++ b/src/Crypto.res @@ -31,6 +31,14 @@ KeyObject = { include Impl } +module BinaryToTextEncoding = { + type t = string + let base64: t = "base64" + let base64url: t = "base64url" + let hex: t = "hex" + let binary: t = "binary" +} + module PivateKey = { include KeyObject.Impl type kind = [KeyObject.privateKey] @@ -60,6 +68,9 @@ module Hash = { @send external copy: t => t = "copy" @send external digest: t => Buffer.t = "digest" @send external update: (t, Buffer.t) => unit = "update" + @send external updateString: (t, string) => t = "update" + @send external updateStringWithEncoding: (t, string, NodeJs.StringEncoding.t) => t = "update" + @send external digestWithEncoding: (t, BinaryToTextEncoding.t) => string = "digest" } include Impl } From 71b525d0c0f34689da9ad7d4c03ba6c4f95755a6 Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Sun, 19 Jan 2025 11:22:49 +0800 Subject: [PATCH 2/2] feat(crypto): Implementing binaryToTextEncoding using variant --- src/Crypto.res | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Crypto.res b/src/Crypto.res index 62e38ad..a0f7d0b 100644 --- a/src/Crypto.res +++ b/src/Crypto.res @@ -31,13 +31,11 @@ KeyObject = { include Impl } -module BinaryToTextEncoding = { - type t = string - let base64: t = "base64" - let base64url: t = "base64url" - let hex: t = "hex" - let binary: t = "binary" -} +type binaryToTextEncoding = + | @as("base64") Base64 + | @as("base64url") Base64url + | @as("hex") Hex + | @as("binary") Binary module PivateKey = { include KeyObject.Impl @@ -70,7 +68,7 @@ module Hash = { @send external update: (t, Buffer.t) => unit = "update" @send external updateString: (t, string) => t = "update" @send external updateStringWithEncoding: (t, string, NodeJs.StringEncoding.t) => t = "update" - @send external digestWithEncoding: (t, BinaryToTextEncoding.t) => string = "digest" + @send external digestWithEncoding: (t, binaryToTextEncoding) => string = "digest" } include Impl }