class AwsSRP::Hasher
Depends on the `msg` presence acts as a digest or a hmac
Constants
- ALGORITHM
Public Class Methods
digest(key, msg = nil)
click to toggle source
# File lib/aws_srp/hasher.rb, line 8 def self.digest(key, msg = nil) new(key, msg).digest end
hexdigest(key, msg = nil)
click to toggle source
# File lib/aws_srp/hasher.rb, line 12 def self.hexdigest(key, msg = nil) new(key, msg).hexdigest end
new(key, msg = nil)
click to toggle source
# File lib/aws_srp/hasher.rb, line 16 def initialize(key, msg = nil) @key = key @digest = OpenSSL::Digest.new(ALGORITHM) update(msg) if msg end
Public Instance Methods
digest()
click to toggle source
# File lib/aws_srp/hasher.rb, line 30 def digest perform :digest end
digest64()
click to toggle source
# File lib/aws_srp/hasher.rb, line 38 def digest64 Base64.strict_encode64(digest) end
hexdigest()
click to toggle source
# File lib/aws_srp/hasher.rb, line 34 def hexdigest perform :hexdigest end
update(msg, base64: false)
click to toggle source
# File lib/aws_srp/hasher.rb, line 23 def update(msg, base64: false) msg = Base64.strict_decode64(msg) if base64 hmac.update(msg) self end
Private Instance Methods
hmac()
click to toggle source
# File lib/aws_srp/hasher.rb, line 44 def hmac @hmac ||= OpenSSL::HMAC.new(@key, @digest) end
perform(method)
click to toggle source
# File lib/aws_srp/hasher.rb, line 48 def perform(method) @hmac ? hmac.public_send(method) : @digest.public_send(method, @key) end