class HasUnpublishedPassword::ShaBloom
Constants
- BITS_PER_HEX_CHAR
Attributes
filter_count[RW]
filter_step[RW]
filter_window[RW]
hash_bits_per_filter[RW]
bitfields[R]
Public Class Methods
deserialize(pattern)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 72 def self.deserialize(pattern) filters = [] filter_count.times do |i| fn = "#{pattern}-p#{i}.bloom" filters << Bitfield.deserialize(fn, 2**hash_bits_per_filter) end new(filters) end
new(filters=nil)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 23 def initialize(filters=nil) unless filters filters = [] self.class.filter_count.times do |i| filters[i] ||= Bitfield.new(2**self.class.hash_bits_per_filter) end end @bitfields = filters end
Public Instance Methods
add_shahash(hash)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 50 def add_shahash(hash) walk_hash(hash) do |row, idx| row.set(idx) end end
add_value(value)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 42 def add_value(value) add_shahash Digest::SHA1.hexdigest value end
check_shahash(hash)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 56 def check_shahash(hash) walk_hash(hash) do |row, idx| return false unless row.get(idx) end return true end
check_value(value)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 46 def check_value(value) check_shahash Digest::SHA1.hexdigest value end
inspect()
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 34 def inspect to_s end
serialize(pattern, verbose=false)
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 63 def serialize(pattern, verbose=false) self.class.filter_count.times do |i| fn = "#{pattern}-p#{i}.bloom" bitfields[i].serialize(fn) puts "wrote #{fn}" if verbose puts `du -h #{fn}` if verbose end end
to_s()
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 38 def to_s "#{self.class} filter with #{self.class.filter_count} blocks of size #{2**self.class.hash_bits_per_filter / 8 / 1024}kb" end
Private Instance Methods
walk_hash(hash) { |bitfields, idx| ... }
click to toggle source
# File lib/has_unpublished_password/sha_bloom.rb, line 84 def walk_hash(hash) self.class.filter_count.times do |i| start = i * self.class.filter_step finish = i * self.class.filter_step + self.class.filter_window - 1 idx = hash[start..finish].to_i(16) yield bitfields[i], idx end end