Class: Kiji::Digester
- Inherits:
-
Object
- Object
- Kiji::Digester
- Defined in:
- lib/kiji/digester.rb
Overview
Class that holds OpenSSL::Digest
instance with some meta information for digesting in XML.
Instance Attribute Summary collapse
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #base64(message) ⇒ Object
-
#digest(message) ⇒ Object
(also: #call)
Digest.
-
#digest_id ⇒ Object
XML-friendly name (for specifying in XML
DigestMethod
nodeAlgorithm
attribute). -
#digest_name ⇒ Object
Human-friendly name.
-
#digester ⇒ Object
Returns
OpenSSL::Digest
(or derived class) instance. - #hexdigest(message) ⇒ Object
-
#initialize(algorithm) ⇒ Digester
constructor
You may pass either a one of
:sha1
,:sha256
or:gostr3411
symbols orHash
with keys:id
with a string, which will denote algorithm in XML Reference tag and:digester
with instance of class with interface compatible withOpenSSL::Digest
class.
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.
34 35 36 37 38 39 40 41 42 |
# File 'lib/kiji/digester.rb', line 34 def initialize(algorithm) if algorithm.is_a? 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
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
44 45 46 |
# File 'lib/kiji/digester.rb', line 44 def symbol @symbol end |
Instance Method Details
#base64(message) ⇒ Object
55 56 57 58 |
# File 'lib/kiji/digester.rb', line 55 def base64() hex = digester.hexdigest() [[hex].pack('H*')].pack('m0') end |
#digest(message) ⇒ Object Also known as: call
Digest
47 48 49 |
# File 'lib/kiji/digester.rb', line 47 def digest() digester.digest() end |
#digest_id ⇒ Object
XML-friendly name (for specifying in XML DigestMethod
node Algorithm
attribute)
73 74 75 |
# File 'lib/kiji/digester.rb', line 73 def digest_id @digest_info[:id] end |
#digest_name ⇒ Object
Human-friendly name
68 69 70 |
# File 'lib/kiji/digester.rb', line 68 def digest_name @digest_info[:name] end |
#digester ⇒ Object
Returns OpenSSL::Digest
(or derived class) instance
63 64 65 |
# File 'lib/kiji/digester.rb', line 63 def digester @digest_info[:digester].reset end |
#hexdigest(message) ⇒ Object
51 52 53 |
# File 'lib/kiji/digester.rb', line 51 def hexdigest() digester.hexdigest() end |