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, line 64
def initialize(algorithm, format))
  raise ArgumentError, "hash algorithm not supported: #{algorithm}" unless SUPPORTED_ALGORITHMS.include?(algorithm)
  raise ArgumentError, "hash format not supported: #{format}" unless SUPPORTED_FORMATS.include?(format)

  @algorithm = algorithm
  @format    = format
end

Public Instance methods

call (io)
[show source]
# File lib/shrine/plugins/signature.rb, line 72
def call(io)
  hash = send(:"calculate_#{algorithm}", io)
  io.rewind

  encoded_hash = send(:"encode_#{format}", hash)
  encoded_hash
end