Module: WebriskHash::Prefixes
Instance Method Summary collapse
-
#get_prefix_map(url, size = 32 * 8) ⇒ Array<Array>
Get hash prefix map for a URL.
-
#get_prefixes(url, size = 32 * 8) ⇒ Set<String>
Get hash prefixes for a URL.
Instance Method Details
#get_prefix_map(url, size = 32 * 8) ⇒ Array<Array>
Get hash prefix map for a URL
Returns an array of [expression, hash_prefix] pairs for all suffix/prefix expressions of the URL
24 25 26 27 28 29 |
# File 'lib/webrisk_hash/prefixes.rb', line 24 def get_prefix_map(url, size = 32 * 8) canonical = WebriskHash.canonicalize(url) return [] if canonical.nil? WebriskHash.suffix_postfix_expressions(canonical).to_a.map { |u| [u, WebriskHash::Hash.truncated_sha256_prefix(u, size)] } end |
#get_prefixes(url, size = 32 * 8) ⇒ Set<String>
Get hash prefixes for a URL
Returns a set of hash prefixes for all suffix/prefix expressions of the URL. This is the main method used to check URLs against Web Risk lists.
49 50 51 52 53 54 55 56 |
# File 'lib/webrisk_hash/prefixes.rb', line 49 def get_prefixes(url, size = 32 * 8) canonical = WebriskHash.canonicalize(url) return Set.new if canonical.nil? Set.new(WebriskHash.suffix_postfix_expressions(canonical).to_a.map do |u| WebriskHash::Hash.truncated_sha256_prefix(u, size) end) end |