
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Automatically calculate checksums and signatures from the values of your class' attributes/methods
Works with POROs and ActiveRecord.
Add this line to your application's Gemfile:
gem "has_checksum"
And then execute:
bundle
Or install it yourself as:
gem install has_checksum
Use the has_checksum
and/or has_signature
class methods to calculate checksums or signatures of your class' columns and/or methods' return values.
has_checksum
class User
include HasChecksum
attr_accessor :username
has_checksum :username
end
user = User.new
user.username = "sshaw"
user.username_checksum # 5b891e901f3c8859115dcdfe323944ec7b4abbde9f7b680430fca7d2c7af89e5
By default SHA256 is used.
Multiple attributes can be specified:
class User
include HasChecksum
attr_accessor :username
attr_accessor :updated_at
has_checksum :username, :updated_at
end
user = User.new
user.username = "sshaw"
user.updated_at = Time.now
user.username_updated_at_checksum # bf6bfb33a4927184eae61195afcff0b033b13da15d79629d513639717c06e15f
Use the:method
and :algorithm
arguments to change the method name and algorithm. Here we use an ActiveRecord subclass:
class User < ActiveRecord::Base
include HasChecksum
has_checksum :settings, :updated_at, :method => "settings_signature", :algorithm => "md5"
end
user.settings[:timezone] = "America/Los_Angeles"
user.save!
user.settings_signature # 4a390b8df412ab4168b9856291437bba
With ActiveRecord, if the generated method is a database column, the checksum will be persisted:
rails g migration add_settings_signature_to_users settings_signature:string # should use char(N), really
:algorithm
can also be a block:
class User < ActiveRecord::Base
include HasChecksum
has_checksum :settings, :updated_at, :algorithm => ->(value) { whirlpool(value) }
end
By default the checksum will be hex encoded but you can change this via :encode
:
class User < ActiveRecord::Base
include HasChecksum
has_checksum :settings, :updated_at, :encode => "base64" # or "binary" or "bubblebabble"
end
has_signature
Calculates a hash-based message authentication code (HMAC).
This (mostly) works the same as has_checksum
but requires a :key
argument that will be used as the HMAC's key:
class User < ActiveRecord::Base
include HasChecksum
has_signature :id, :created_at, :last_login_at, :key => :some_salt_column, :method => "session_id"
end
If :key
is a Symbol
it will treated as a method name. If it's a String
is will be used literally, as the key.
It can also be a Proc
that returns the key.
Skye Shaw (skye.shaw -AT- gmail)
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that has_checksum demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.