diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e5ee5d..bf31eba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.3.1 - 2022-01-29 + +- Updated for Gleam v0.27.0. + ## v0.3.0 - 2022-01-29 - Converted to use the Gleam build tool. diff --git a/gleam.toml b/gleam.toml index a2c1a60..b5fec37 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "gleam_crypto" -version = "0.3.0" +version = "0.3.1" licences = ["Apache-2.0"] description = "Gleam bindings to the BEAM cryptography functions" diff --git a/manifest.toml b/manifest.toml index fb4d29c..0e73893 100644 --- a/manifest.toml +++ b/manifest.toml @@ -3,8 +3,8 @@ packages = [ { name = "gleam_bitwise", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_bitwise", source = "hex", outer_checksum = "6064699EFBABB1CA392DCB193D0E8B402FB042B4B46857B01E6875E643B57F54" }, - { name = "gleam_stdlib", version = "0.22.3", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "F2C2D389B06426E1289D5419F89BDE8E0F7F35A40B2BBB3C88188481F0D44A9F" }, - { name = "gleeunit", version = "0.6.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "A006864621DB80C4FBB0746580703502FD81A4D38D23FCB20A8120984D353DF0" }, + { name = "gleam_stdlib", version = "0.27.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "9DBDD21B48C654182CDD8AA15ACF85E8E74A0438583C68BD7EF08BE89F999C6F" }, + { name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" }, ] [requirements] diff --git a/src/gleam/crypto.gleam b/src/gleam/crypto.gleam index 6b90231..9422339 100644 --- a/src/gleam/crypto.gleam +++ b/src/gleam/crypto.gleam @@ -4,6 +4,7 @@ import gleam/bit_string import gleam/bitwise import gleam/string import gleam/base +import gleam/result /// Generates N bytes randomly uniform 0..255, and returns the result in a binary. /// @@ -109,21 +110,23 @@ pub fn verify_signed_message( message: String, secret: BitString, ) -> Result(BitString, Nil) { - try #(protected, payload, signature) = case string.split(message, on: ".") { + use #(protected, payload, signature) <- result.then(case + string.split(message, on: ".") + { [a, b, c] -> Ok(#(a, b, c)) _ -> Error(Nil) - } + }) let text = string.concat([protected, ".", payload]) - try payload = base.url_decode64(payload) - try signature = base.url_decode64(signature) - try protected = base.url_decode64(protected) - try digest_type = case protected { + use payload <- result.then(base.url_decode64(payload)) + use signature <- result.then(base.url_decode64(signature)) + use protected <- result.then(base.url_decode64(protected)) + use digest_type <- result.then(case protected { <<"HS224":utf8>> -> Ok(Sha224) <<"HS256":utf8>> -> Ok(Sha256) <<"HS384":utf8>> -> Ok(Sha384) <<"HS512":utf8>> -> Ok(Sha512) _ -> Error(Nil) - } + }) let challenge = hmac(<>, digest_type, secret) case secure_compare(challenge, signature) { True -> Ok(payload)