Module: HasChecksum::ClassMethods
- Defined in:
- lib/has_checksum.rb
Instance Method Summary collapse
Instance Method Details
#has_checksum(*config) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/has_checksum.rb', line 71 def has_checksum(*config) source, = has_checksum_configure(config) if ![:algorithm].respond_to?(:call) # TODO: use OpenSSL here too? begin [:algorithm] = Digest.const_get([:algorithm].upcase) # Digest seems to only raise LoadError here but we add NameError for good measure rescue LoadError, NameError raise ArgumentError, "unknown algorithm '#{options[:algorithm]}'" end end [:method] ||= "%s_checksum" % source.join("_") define_methods(:calculate_checksum, source, ) end |
#has_signature(*config) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/has_checksum.rb', line 55 def has_signature(*config) source, = has_checksum_configure(config) raise ArgumentError, "key option required to calculate a signature" unless [:key] if ![:algorithm].respond_to?(:call) begin [:algorithm] = OpenSSL::Digest.new([:algorithm]) rescue RuntimeError raise ArgumentError, "unknown algorithm '#{options[:algorithm]}'" end end [:method] ||= "%s_signature" % source.join("_") define_methods(:calculate_signature, source, ) end |