module ObjectHash

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

Constants

CryptoHash
Encode

rubocop:disable Lint/SelfAssignment

VERSION

Public Instance Methods

hash(input, algorithm: "sha1", replacer: nil, unordered_objects: true) click to toggle source

Encode the input into a standardized format, then cryptographically hash it. @param input: Any object that should be encoded. @param algorithm: 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".

@param replacer: An optional function called on objects before they are encoded.

Use this to replace unencodable objects with Strings or Hashes.

@param unordered_objects: If true, objects will have sorted keys.

If false, objects with different order in their keys will have different hashes.
# 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