class HashIdentifier
The global Hash Identifier class
Constants
- COMMONS
- PROTOTYPES
Attributes
hash[R]
@return [String] the hash (as provided) @example
'5f4dcc3b5aa765d61d8327deb882cf99'
type[R]
@return [Array<Chf>] list of {Chf} objects, representing the identified
hashes
Public Class Methods
new(hash)
click to toggle source
A new instance of hash identifier @param hash [String] the hash to identify
# File lib/haiti.rb, line 27 def initialize(hash) @hash = hash @type = identify(hash) sort_commons end
Private Instance Methods
identify(hash)
click to toggle source
Check which hash types are matching the provided hash @param hash [String] the hash to identify @return [Array<Chf>] list of {Chf} objects, representing the identified
hashes
# File lib/haiti.rb, line 39 def identify(hash) res = [] PROTOTYPES.each do |prototype| reg = Regexp.new prototype['regex'], Regexp::IGNORECASE next unless reg.match?(hash) prototype['modes'].each do |mode| res << Chf.new(mode) end end return res end
sort_commons()
click to toggle source
Sort common hash types first
# File lib/haiti.rb, line 53 def sort_commons @type.sort_by! { |e| COMMONS.include?(e.name) ? 0 : 1 } end