Module: ObjectHash

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

Overview

Contains functions which encode the input into a standardized format, then cryptographically hash it.

Constant Summary collapse

Encode =

rubocop:disable Lint/SelfAssignment

Encode
CryptoHash =
CryptoHash
VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.hash(input, algorithm: "sha1", replacer: nil, unordered_objects: true) ⇒ Object

Encode the input into a standardized format, then cryptographically hash it.

Parameters:

  • input:

    Any object that should be encoded.

  • algorithm: (defaults to: "sha1")

    Either a string naming the algorithm to use, or a Digest object that can hash the string. To preview the output of encoding, use “passthrough”.

  • replacer: (defaults to: nil)

    An optional function called on objects before they are encoded. Use this to replace unencodable objects with Strings or Hashes.

  • unordered_objects: (defaults to: true)

    If true, objects will have sorted keys. If false, objects with different order in their keys will have different hashes.



27
28
29
30
31
32
33
34
35
# File 'lib/object_hash_rb.rb', line 27

def hash(input, algorithm: "sha1", replacer: nil, unordered_objects: true)
  CryptoHash.perform_cryptohash(
    Encode::Encoder.new(
      replacer: replacer,
      unordered_objects: unordered_objects
    ).perform_encode(input),
    algorithm
  )
end