class Mihari::TypeChecker
Public Class Methods
detailed_type(data)
click to toggle source
@return [String, nil]
# File lib/mihari/type_checker.rb, line 80 def self.detailed_type(data) new(data).detailed_type end
new(*args, **kwargs)
click to toggle source
Calls superclass method
# File lib/mihari/type_checker.rb, line 15 def initialize(*args, **kwargs) super raise ArgumentError if data.is_a?(Hash) end
type(data)
click to toggle source
@return [String, nil]
# File lib/mihari/type_checker.rb, line 75 def self.type(data) new(data).type end
Public Instance Methods
detailed_type()
click to toggle source
@return [String, nil]
# File lib/mihari/type_checker.rb, line 65 def detailed_type return "md5" if md5? return "sha1" if sha1? return "sha256" if sha256? return "sha512" if sha512? type end
domain?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 35 def domain? uri = Addressable::URI.parse("http://#{data}") uri.host == data && PublicSuffix.valid?(uri.host) rescue Addressable::URI::InvalidURIError => _e false end
hash?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 22 def hash? md5? || sha1? || sha256? || sha512? end
ip?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 27 def ip? IPAddr.new data true rescue IPAddr::InvalidAddressError => _e false end
mail?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 51 def mail? EmailAddress.valid? data, host_validation: :syntax end
type()
click to toggle source
@return [String, nil]
# File lib/mihari/type_checker.rb, line 56 def type return "hash" if hash? return "ip" if ip? return "domain" if domain? return "url" if url? return "mail" if mail? end
url?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 43 def url? uri = Addressable::URI.parse(data) uri.scheme && uri.host && uri.path && PublicSuffix.valid?(uri.host) rescue Addressable::URI::InvalidURIError => _e false end
Private Instance Methods
md5?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 87 def md5? data.match?(/^[A-Fa-f0-9]{32}$/) end
sha1?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 92 def sha1? data.match?(/^[A-Fa-f0-9]{40}$/) end
sha256?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 97 def sha256? data.match?(/^[A-Fa-f0-9]{64}$/) end
sha512?()
click to toggle source
@return [Boolean]
# File lib/mihari/type_checker.rb, line 102 def sha512? data.match?(/^[A-Fa-f0-9]{128}$/) end