2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-17 02:58:03 +02:00
|
|
|
# A formula's checksum.
|
|
|
|
#
|
|
|
|
# @api private
|
2012-06-18 19:58:35 -05:00
|
|
|
class Checksum
|
2017-06-26 07:30:28 +02:00
|
|
|
extend Forwardable
|
|
|
|
|
2012-06-18 19:58:35 -05:00
|
|
|
attr_reader :hash_type, :hexdigest
|
|
|
|
|
2016-09-17 15:17:27 +01:00
|
|
|
TYPES = [:sha256].freeze
|
2012-06-18 19:58:35 -05:00
|
|
|
|
2013-04-07 00:49:56 -05:00
|
|
|
def initialize(hash_type, hexdigest)
|
|
|
|
@hash_type = hash_type
|
2020-11-19 18:12:16 +01:00
|
|
|
@hexdigest = hexdigest.downcase
|
2012-06-18 19:58:35 -05:00
|
|
|
end
|
|
|
|
|
2020-11-19 18:12:16 +01:00
|
|
|
delegate [:empty?, :to_s, :length, :[]] => :@hexdigest
|
2012-06-18 19:58:35 -05:00
|
|
|
|
2013-04-07 00:49:56 -05:00
|
|
|
def ==(other)
|
2020-11-19 18:12:16 +01:00
|
|
|
case other
|
|
|
|
when String
|
|
|
|
to_s == other.downcase
|
|
|
|
when Checksum
|
|
|
|
hash_type == other.hash_type && hexdigest == other.hexdigest
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2012-06-18 19:58:35 -05:00
|
|
|
end
|
|
|
|
end
|