Skip to content

Commit

Permalink
fix: Compatibility with ruby-jwt (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj authored Aug 24, 2024
1 parent d1d1cc1 commit 4c674a2
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/jwt/eddsa/algo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,37 @@
module JWT
module EdDSA
# EdDSA algorithm implementation
module Algo
include JWT::JWA::SignatureAlgorithm
class Algo
include JWT::JWA::SigningAlgorithm

register_algorithm("EdDSA")
register_algorithm("ED25519")

class << self
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
def initialize(alg)
@alg = alg
end

key.sign(msg)
def sign(data:, signing_key:)
unless signing_key.is_a?(Ed25519::SigningKey)
raise_sign_error!("Key given is a #{signing_key.class} but needs to be a Ed25519::SigningKey")
end

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
signing_key.sign(data)
end

public_key.verify(signature, signing_input)
rescue Ed25519::VerifyError
false
def verify(data:, signature:, verification_key:)
unless verification_key.is_a?(Ed25519::VerifyKey)
raise_verify_error!("Key given is a #{verification_key.class} but needs to be a Ed25519::VerifyKey")
end

def header(*)
{ "alg" => "EdDSA" }
end
verification_key.verify(signature, data)
rescue Ed25519::VerifyError
false
end

def header(*)
{ "alg" => "EdDSA" }
end

register_algorithm(new("EdDSA"))
register_algorithm(new("ED25519"))
end
end
end

0 comments on commit 4c674a2

Please sign in to comment.