Class: EncodedId::Encoders::HashidSalt
- Inherits:
-
Object
- Object
- EncodedId::Encoders::HashidSalt
- Defined in:
- lib/encoded_id/encoders/hashid_salt.rb
Overview
Simple wrapper class for HashID salt values.
This class encapsulates the salt string and provides convenient access to:
-
The original salt string
-
The salt as an array of individual characters
Both representations are frozen to prevent accidental modification.
Security Note:
The salt is the ‘secret’ that makes your Hashids unique. Without knowing the salt, it’s harder to reverse-engineer the encoding scheme or predict hash values BUT Hashids is not a secure encryption technique. It is only to be used to obfuscate values which are not secure (you would just prefer the average person cannot see them).
Instance Attribute Summary collapse
-
#chars ⇒ Object
readonly
The salt as an array of individual characters (frozen).
-
#salt ⇒ Object
readonly
The original salt string (frozen).
Instance Method Summary collapse
-
#initialize(salt) ⇒ HashidSalt
constructor
Initialize a new salt wrapper.
Constructor Details
#initialize(salt) ⇒ HashidSalt
Initialize a new salt wrapper.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/encoded_id/encoders/hashid_salt.rb', line 33 def initialize(salt) unless salt.is_a?(String) raise SaltError, "The salt must be a String" end # Freeze both representations to prevent modification. # This ensures the salt remains constant and thread-safe. @salt = salt.freeze @chars = salt.chars.freeze end |
Instance Attribute Details
#chars ⇒ Object (readonly)
The salt as an array of individual characters (frozen)
48 49 50 |
# File 'lib/encoded_id/encoders/hashid_salt.rb', line 48 def chars @chars end |
#salt ⇒ Object (readonly)
The original salt string (frozen)
45 46 47 |
# File 'lib/encoded_id/encoders/hashid_salt.rb', line 45 def salt @salt end |