From daaa740e653c9786c7ac9c5d086ad5ef9c432df7 Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Sun, 4 Aug 2024 11:29:09 +0300 Subject: [PATCH] feat: Always set `alg` header to `EdDSA` (#13) Define a static header no mater what the input is --- lib/jwt/eddsa/algo.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/jwt/eddsa/algo.rb b/lib/jwt/eddsa/algo.rb index 0a857ac..ca64850 100644 --- a/lib/jwt/eddsa/algo.rb +++ b/lib/jwt/eddsa/algo.rb @@ -4,12 +4,12 @@ module JWT module EdDSA # EdDSA algorithm implementation module Algo - include JWT::JWA::Algorithm + include JWT::JWA::SignatureAlgorithm register_algorithm("EdDSA") class << self - def sign(_algorithm, msg, key) + def sign(_alg, msg, key) unless key.is_a?(Ed25519::SigningKey) raise_sign_error!("Key given is a #{key.class} but needs to be a Ed25519::SigningKey") end @@ -17,7 +17,7 @@ def sign(_algorithm, msg, key) key.sign(msg) end - def verify(_algorithm, public_key, signing_input, signature) + def verify(_alg, public_key, signing_input, signature) unless public_key.is_a?(Ed25519::VerifyKey) raise_verify_error!("Key given is a #{public_key.class} but needs to be a Ed25519::VerifyKey") end @@ -26,6 +26,10 @@ def verify(_algorithm, public_key, signing_input, signature) rescue Ed25519::VerifyError false end + + def header(*) + { "alg" => "EdDSA" } + end end end end