Class: JWT::EdDSA::Algo

Inherits:
Object
  • Object
show all
Includes:
JWA::SigningAlgorithm
Defined in:
lib/jwt/eddsa/algo.rb

Overview

EdDSA algorithm implementation

Instance Method Summary collapse

Constructor Details

#initialize(alg) ⇒ Algo

Returns a new instance of Algo.



9
10
11
# File 'lib/jwt/eddsa/algo.rb', line 9

def initialize(alg)
  @alg = alg
end

Instance Method Details

#headerObject



31
32
33
# File 'lib/jwt/eddsa/algo.rb', line 31

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

#sign(data:, signing_key:) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/jwt/eddsa/algo.rb', line 13

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

  signing_key.sign(data)
end

#verify(data:, signature:, verification_key:) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/jwt/eddsa/algo.rb', line 21

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

  verification_key.verify(signature, data)
rescue Ed25519::VerifyError
  false
end