Class: Familia::Migration::Script::ScriptEntry

Inherits:
Data
  • Object
show all
Defined in:
lib/familia/migration/script.rb

Overview

Holds script source and its precomputed SHA-1.

SECURITY NOTE (issue #310, S5): this SHA-1 is the Redis script identity used as the EVALSHA cache key, not a security/integrity checksum. The Redis EVALSHA/SCRIPT LOAD protocol identifies cached scripts by the SHA-1 of their body, so this value MUST be SHA-1 -- swapping in SHA-256 would make every EVALSHA miss (NOSCRIPT) and silently fall back to EVAL, re-sending the full script on each call. The scripts here are hardcoded library constants (or developer-supplied), never attacker-controlled, so SHA-1 collision attacks do not apply. Genuine change-detection that needs collision resistance uses SHA-256 elsewhere (see Migration::Registry#schema_digest).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, sha: nil) ⇒ ScriptEntry

Returns a new instance of ScriptEntry.



48
49
50
51
52
# File 'lib/familia/migration/script.rb', line 48

def initialize(source:, sha: nil)
  # Digest::SHA1 here mirrors what Redis computes for EVALSHA/SCRIPT LOAD.
  computed_sha = sha || Digest::SHA1.hexdigest(source)
  super(source: source.freeze, sha: computed_sha.freeze)
end

Instance Attribute Details

#shaObject (readonly)

Returns the value of attribute sha

Returns:

  • (Object)

    the current value of sha



47
48
49
# File 'lib/familia/migration/script.rb', line 47

def sha
  @sha
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



47
48
49
# File 'lib/familia/migration/script.rb', line 47

def source
  @source
end