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.



39
40
41
42
43
44
45
46
47
# File 'lib/signer/digester.rb', line 39

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.



49
50
51
# File 'lib/signer/digester.rb', line 49

def symbol
  @symbol
end

Instance Method Details

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

Digest



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

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

#digest_idObject

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



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

def digest_id
  @digest_info[:id]
end

#digest_nameObject

Human-friendly name



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

def digest_name
  @digest_info[:name]
end

#digesterObject

Returns OpenSSL::Digest (or derived class) instance



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

def digester
  @digest_info[:digester].reset
end