Class: Shrine::Plugins::Signature::SignatureCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/signature.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm, format:) ⇒ SignatureCalculator

Returns a new instance of SignatureCalculator.

Raises:



58
59
60
61
62
63
64
# File 'lib/shrine/plugins/signature.rb', line 58

def initialize(algorithm, format:)
  raise Error, "unknown hash algorithm #{algorithm.inspect}, supported algorithms are: #{SUPPORTED_ALGORITHMS.join(",")}" unless SUPPORTED_ALGORITHMS.include?(algorithm)
  raise Error, "unknown hash format #{format.inspect}, supported formats are: #{SUPPORTED_FORMATS.join(",")}" unless SUPPORTED_FORMATS.include?(format)

  @algorithm = algorithm
  @format    = format
end

Instance Attribute Details

#algorithmObject (readonly)

Returns the value of attribute algorithm.



56
57
58
# File 'lib/shrine/plugins/signature.rb', line 56

def algorithm
  @algorithm
end

#formatObject (readonly)

Returns the value of attribute format.



56
57
58
# File 'lib/shrine/plugins/signature.rb', line 56

def format
  @format
end

Instance Method Details

#call(io) ⇒ Object



66
67
68
69
# File 'lib/shrine/plugins/signature.rb', line 66

def call(io)
  hash = send(:"calculate_#{algorithm}", io)
  send(:"encode_#{format}", hash)
end