class Shrine::Plugins::Signature::SignatureCalculator

  1. lib/shrine/plugins/signature.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. algorithm
  2. call
  3. format

Constants

SUPPORTED_ALGORITHMS = [:sha1, :sha256, :sha384, :sha512, :md5, :crc32]  
SUPPORTED_FORMATS = [:none, :hex, :base64]  

Attributes

algorithm [R]
format [R]

Public Class methods

new (algorithm, format:)
[show source]
   # File lib/shrine/plugins/signature.rb
32 def initialize(algorithm, format:)
33   raise Error, "unknown hash algorithm #{algorithm.inspect}, supported algorithms are: #{SUPPORTED_ALGORITHMS.join(",")}" unless SUPPORTED_ALGORITHMS.include?(algorithm)
34   raise Error, "unknown hash format #{format.inspect}, supported formats are: #{SUPPORTED_FORMATS.join(",")}" unless SUPPORTED_FORMATS.include?(format)
35 
36   @algorithm = algorithm
37   @format    = format
38 end

Public Instance methods

call (io)
[show source]
   # File lib/shrine/plugins/signature.rb
40 def call(io)
41   hash = send(:"calculate_#{algorithm}", io)
42   io.rewind
43 
44   send(:"encode_#{format}", hash)
45 end