Class: LightJWT::JWA::JWS::BaseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/light_jwt/jwa/jws.rb

Direct Known Subclasses

ECDSAHandler, HMACHandler, NoneHandler, RSAHandler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alg) ⇒ BaseHandler

Returns a new instance of BaseHandler.



61
62
63
64
# File 'lib/light_jwt/jwa/jws.rb', line 61

def initialize(alg)
  @alg = alg
  @digest = build_digest unless alg == 'none'
end

Instance Attribute Details

#algObject (readonly)

Returns the value of attribute alg.



59
60
61
# File 'lib/light_jwt/jwa/jws.rb', line 59

def alg
  @alg
end

#digestObject (readonly)

Returns the value of attribute digest.



59
60
61
# File 'lib/light_jwt/jwa/jws.rb', line 59

def digest
  @digest
end

Instance Method Details

#secure_compare(a, b) ⇒ Object

Constant-time comparison algorithm to prevent timing attacks



67
68
69
70
71
# File 'lib/light_jwt/jwa/jws.rb', line 67

def secure_compare(a, b)
  return false if a.bytesize != b.bytesize

  a.bytes.zip(b.bytes).map { |x, y| x ^ y }.sum.zero?
end