Skip to content

Commit

Permalink
fix: deprecated warnings and stdlib version
Browse files Browse the repository at this point in the history
  • Loading branch information
brettkolodny committed Apr 29, 2024
1 parent d5fc5d5 commit d473db0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name = "gwt"
version = "0.3.0"
version = "0.4.0"

description = "A JWT library written in Gleam"

licences = ["Apache-2.0"]

[dependencies]
gleam_stdlib = "~> 0.35.1"
gleam_stdlib = "~> 0.34 or ~> 1.0"
gleam_json = "~> 1.0"
gleam_crypto = "~> 1.3"
birl = "~> 1.5"
Expand Down
16 changes: 8 additions & 8 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# You typically do not need to edit this file

packages = [
{ name = "birl", version = "1.5.0", build_tools = ["gleam"], requirements = ["ranger", "gleam_stdlib"], otp_app = "birl", source = "hex", outer_checksum = "23BFE5AB0D7D9E4ECC5BB89B7ABDDF8E976D98C65D2E173D116E6AAFBF24E633" },
{ name = "birl", version = "1.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "976CFF85D34D50F7775896615A71745FBE0C325E50399787088F941B539A0497" },
{ name = "gleam_crypto", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_crypto", source = "hex", outer_checksum = "ADD058DEDE8F0341F1ADE3AAC492A224F15700829D9A3A3F9ADF370F875C51B7" },
{ name = "gleam_json", version = "1.0.0", build_tools = ["gleam"], requirements = ["thoas", "gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "8B197DD5D578EA6AC2C0D4BDC634C71A5BCA8E7DB5F47091C263ECB411A60DF3" },
{ name = "gleam_stdlib", version = "0.35.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5443EEB74708454B65650FEBBB1EF5175057D1DEC62AEA9D7C6D96F41DA79152" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
{ name = "ranger", version = "1.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "28E615AE7590ED922AF1510DDF606A2ECBBC2A9609AF36D412EDC925F06DFD20" },
{ name = "thoas", version = "0.4.1", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "4918D50026C073C4AB1388437132C77A6F6F7C8AC43C60C13758CC0ADCE2134E" },
{ name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" },
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "ranger", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "1566C272B1D141B3BBA38B25CB761EF56E312E79EC0E2DFD4D3C19FB0CC1F98C" },
{ name = "thoas", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "540C8CB7D9257F2AD0A14145DC23560F91ACDCA995F0CCBA779EB33AF5D859D1" },
]

[requirements]
birl = { version = "~> 1.5"}
birl = { version = "~> 1.5" }
gleam_crypto = { version = "~> 1.3" }
gleam_json = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.35.1" }
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" }
gleeunit = { version = "~> 1.0" }
25 changes: 20 additions & 5 deletions src/gwt.gleam
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// IMPORTS ---------------------------------------------------------------------

import birl
import gleam/bit_array
import gleam/crypto
import gleam/dict.{type Dict}
Expand All @@ -9,7 +10,6 @@ import gleam/list
import gleam/option.{type Option, None, Some}
import gleam/result
import gleam/string
import birl

// TYPES -----------------------------------------------------------------------

Expand Down Expand Up @@ -739,19 +739,34 @@ fn get_signature(data: String, algorithm: Algorithm, secret: String) -> String {
fn parts(
jwt_string: String,
) -> Result(#(Header, Payload, Option(String)), JwtDecodeError) {
let jwt_parts = string.split(jwt_string, ".")
let #(maybe_header, maybe_payload, maybe_signature) =
string.split(jwt_string, ".")
|> list.take(3)
|> list.index_fold(
#(Error(Nil), Error(Nil), Error(Nil)),
fn(acc, part, index) {
let #(header, payload, signature) = acc

case index {
0 -> #(Ok(part), payload, signature)
1 -> #(header, Ok(part), signature)
2 -> #(header, payload, Ok(part))
_ -> acc
}
},
)

let signature =
list.at(jwt_parts, 2)
maybe_signature
|> option.from_result()

use encoded_payload <- result.try(
list.at(jwt_parts, 1)
maybe_payload
|> result.replace_error(MissingPayload),
)

use encoded_header <- result.try(
list.at(jwt_parts, 0)
maybe_header
|> result.replace_error(MissingHeader),
)
use header_data <- result.try(
Expand Down

0 comments on commit d473db0

Please sign in to comment.