Skip to content

Commit

Permalink
v0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Mar 7, 2023
1 parent 2058379 commit d92e79b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 2 additions & 2 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 10 additions & 7 deletions src/gleam/crypto.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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(<<text:utf8>>, digest_type, secret)
case secure_compare(challenge, signature) {
True -> Ok(payload)
Expand Down

0 comments on commit d92e79b

Please sign in to comment.