Class: Signer::Digester

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

Overview

Class that holds OpenSSL::Digest instance with some meta information for digesting in XML.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm) ⇒ Digester

You may pass either a one of :sha1, :sha256 or :gostr3411 symbols or Hash with keys :id with a string, which will denote algorithm in XML Reference tag and :digester with instance of class with interface compatible with OpenSSL::Digest class.



33
34
35
36
37
38
39
40
41
# File 'lib/signer/digester.rb', line 33

def initialize(algorithm)
  if algorithm.kind_of? Symbol
    @digest_info = DIGEST_ALGORITHMS[algorithm].dup
    @digest_info[:digester] = @digest_info[:digester].call
    @symbol = algorithm
  else
    @digest_info = algorithm
  end
end

Instance Attribute Details

#symbolObject (readonly)

Returns the value of attribute symbol.



43
44
45
# File 'lib/signer/digester.rb', line 43

def symbol
  @symbol
end

Instance Method Details

#digest(message) ⇒ Object Also known as: call

Digest



46
47
48
# File 'lib/signer/digester.rb', line 46

def digest(message)
  self.digester.digest(message)
end

#digest_idObject

XML-friendly name (for specifying in XML DigestMethod node Algorithm attribute)



63
64
65
# File 'lib/signer/digester.rb', line 63

def digest_id
  @digest_info[:id]
end

#digest_nameObject

Human-friendly name



58
59
60
# File 'lib/signer/digester.rb', line 58

def digest_name
  @digest_info[:name]
end

#digesterObject

Returns OpenSSL::Digest (or derived class) instance



53
54
55
# File 'lib/signer/digester.rb', line 53

def digester
  @digest_info[:digester].reset
end