Class: Shrine::Plugins::Signature::SignatureCalculator
- Inherits:
-
Object
- Object
- Shrine::Plugins::Signature::SignatureCalculator
- 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
-
#algorithm ⇒ Object
readonly
Returns the value of attribute algorithm.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #call(io) ⇒ Object
-
#initialize(algorithm, format:) ⇒ SignatureCalculator
constructor
A new instance of SignatureCalculator.
Constructor Details
#initialize(algorithm, format:) ⇒ SignatureCalculator
Returns a new instance of SignatureCalculator.
62 63 64 65 66 67 68 |
# File 'lib/shrine/plugins/signature.rb', line 62 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
#algorithm ⇒ Object (readonly)
Returns the value of attribute algorithm.
60 61 62 |
# File 'lib/shrine/plugins/signature.rb', line 60 def algorithm @algorithm end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
60 61 62 |
# File 'lib/shrine/plugins/signature.rb', line 60 def format @format end |
Instance Method Details
#call(io) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/shrine/plugins/signature.rb', line 70 def call(io) hash = send(:"calculate_#{algorithm}", io) io.rewind send(:"encode_#{format}", hash) end |