Skip to content

Commit

Permalink
feat: Always set alg header to EdDSA (#13)
Browse files Browse the repository at this point in the history
Define a static header no mater what the input is
  • Loading branch information
anakinj authored Aug 4, 2024
1 parent a0f8200 commit daaa740
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/jwt/eddsa/algo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ 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

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
Expand All @@ -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
Expand Down

0 comments on commit daaa740

Please sign in to comment.