Module: JWT::JWA::SigningAlgorithm

Included in:
Ecdsa, Eddsa, Hmac, HmacRbNaCl, HmacRbNaClFixed, None, Ps, Rsa, Unsupported, Wrapper
Defined in:
lib/jwt/jwa/signing_algorithm.rb

Overview

Base functionality for signing algorithms

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#algObject (readonly)

Returns the value of attribute alg.



20
21
22
# File 'lib/jwt/jwa/signing_algorithm.rb', line 20

def alg
  @alg
end

Class Method Details

.included(klass) ⇒ Object



15
16
17
18
# File 'lib/jwt/jwa/signing_algorithm.rb', line 15

def self.included(klass)
  klass.extend(ClassMethods)
  klass.include(JWT::JWA::Compat)
end

Instance Method Details

#headerObject



26
27
28
# File 'lib/jwt/jwa/signing_algorithm.rb', line 26

def header(*)
  { 'alg' => alg }
end

#raise_sign_error!(message) ⇒ Object



42
43
44
# File 'lib/jwt/jwa/signing_algorithm.rb', line 42

def raise_sign_error!(message)
  raise(EncodeError.new(message).tap { |e| e.set_backtrace(caller(1)) })
end

#raise_verify_error!(message) ⇒ Object



38
39
40
# File 'lib/jwt/jwa/signing_algorithm.rb', line 38

def raise_verify_error!(message)
  raise(DecodeError.new(message).tap { |e| e.set_backtrace(caller(1)) })
end

#signObject



30
31
32
# File 'lib/jwt/jwa/signing_algorithm.rb', line 30

def sign(*)
  raise_sign_error!('Algorithm implementation is missing the sign method')
end

#valid_alg?(alg_to_check) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/jwt/jwa/signing_algorithm.rb', line 22

def valid_alg?(alg_to_check)
  alg&.casecmp(alg_to_check)&.zero? == true
end

#verifyObject



34
35
36
# File 'lib/jwt/jwa/signing_algorithm.rb', line 34

def verify(*)
  raise_verify_error!('Algorithm implementation is missing the verify method')
end