Class: Blake3::Hasher

Inherits:
Object
  • Object
show all
Defined in:
lib/blake3.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: nil) ⇒ Hasher

Returns a new instance of Hasher.



25
26
27
28
29
30
31
32
# File 'lib/blake3.rb', line 25

def initialize(key: nil)
  if key
    hex = key.unpack1('H*')
    @hasher = Blake3KeyedHasher.new(hex)
  else
    @hasher = Blake3Hasher.new
  end
end

Class Method Details

.digest(plain, key: nil) ⇒ Object



44
45
46
# File 'lib/blake3.rb', line 44

def self.digest(plain, key: nil)
  new(key: key).update(plain).digest
end

.hexdigest(plain, key: nil) ⇒ Object



48
49
50
# File 'lib/blake3.rb', line 48

def self.hexdigest(plain, key: nil)
  new(key: key).update(plain).hexdigest
end

Instance Method Details

#digestObject



52
53
54
# File 'lib/blake3.rb', line 52

def digest
  [hexdigest].pack('H*')
end

#finalizeObject



40
41
42
# File 'lib/blake3.rb', line 40

def finalize
  @hasher.finalize
end

#hexdigestObject



56
57
58
# File 'lib/blake3.rb', line 56

def hexdigest
  finalize
end

#update(plain) ⇒ Object



34
35
36
37
38
# File 'lib/blake3.rb', line 34

def update(plain)
  hex = plain.unpack1('H*')
  @hasher.update(hex)
  self
end