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.



45
46
47
48
49
50
51
52
53
# File 'lib/signer/digester.rb', line 45

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.



55
56
57
# File 'lib/signer/digester.rb', line 55

def symbol
  @symbol
end

Instance Method Details

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

Digest



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

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

#digest_idObject

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



75
76
77
# File 'lib/signer/digester.rb', line 75

def digest_id
  @digest_info[:id]
end

#digest_nameObject

Human-friendly name



70
71
72
# File 'lib/signer/digester.rb', line 70

def digest_name
  @digest_info[:name]
end

#digesterObject

Returns OpenSSL::Digest (or derived class) instance



65
66
67
# File 'lib/signer/digester.rb', line 65

def digester
  @digest_info[:digester].reset
end