Module: Veronica

Defined in:
lib/veronica.rb,
lib/veronica/version.rb

Constant Summary collapse

VALID_SHA2_BIT_LENGTHS =
[256, 384, 512]
VALID_SHA2_ENCODING_FORMATS =
["hexdigest", "base64digest", "digest"]
VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.generate_sha2(digest_bits:, string:, encoding_format: "hexdigest") ⇒ Object

We use hexdigest by default for familiarities sake



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/veronica.rb', line 9

def self.generate_sha2(digest_bits: , string: , encoding_format: "hexdigest")
  unless VALID_SHA2_BIT_LENGTHS.include?(digest_bits)
    raise ArgumentError, "You can only use 256, 384, or 512 for bit length."
  end

  unless VALID_SHA2_ENCODING_FORMATS.include?(encoding_format)
    raise ArgumentError, "You can only use hexdigest, base64digest or just digest for an encoding format."
  end

  # This lets us dynamically pass in digest_bits as well as encoding formats to the Digest class.
  Digest::SHA2.new(digest_bits).method(encoding_format.to_sym).(string)
end