class ICU::SpoofChecker
- ICU::SpoofChecker
- Reference
- Object
Overview
Identifier Spoofing & Confusability
ICU::SpoofChecker detects whether identifiers (usernames, domain names,
source code symbols, etc.) are visually confusable with one another, or
contain characters that could be used in spoofing attacks.
Two strings are confusable if a casual observer might mistake one for the other (e.g. the Cyrillic "а" vs the Latin "a"). The checker can also validate that an identifier is safe — drawn from a single script, using only recommended characters, etc.
Usage
sc = ICU::SpoofChecker.new
sc.confusable?("paypal", "рaypal") # => true (Cyrillic "р")
sc.safe?("hello") # => true
sc.safe?("ℋello") # => false (mixed script)
sc.skeleton("рaypal") == sc.skeleton("paypal") # => true
See also
Defined in:
icu/spoof_checker.crConstructors
Class Method Summary
-
.inclusion_set : Set(Char)
Returns the inclusion set: the set of characters that are explicitly allowed to appear in identifiers regardless of other restrictions.
-
.recommended_set : Set(Char)
Returns the recommended set: the set of characters recommended by Unicode TR#39 for use in identifiers.
Instance Method Summary
-
#allowed_locales : String
Returns the comma-separated list of allowed locales, or an empty string if no locale restriction is set.
-
#allowed_locales=(locales : String)
Restricts the set of allowed characters to those belonging to the given comma-separated list of locale script(s).
-
#bidi_confusable?(s1 : String, s2 : String, direction : Direction) : Bool
Returns
trueif s1 and s2 are BiDi-confusable in the given direction. -
#bidi_skeleton(text : String, direction : Direction) : String
Returns the BiDi skeleton of text for the given direction.
-
#check(text : String, result : CheckResult) : Int32
Runs all enabled spoof checks on text, populating result with detailed information, and returns the bitmask of failed checks.
-
#check(text : String) : Int32
Runs all enabled spoof checks on text and returns the bitmask of failed checks (0 means the text passed all checks).
-
#checks : Int32
Returns the bitmask of checks currently enabled on this checker.
-
#checks=(value : Int32)
Sets the checks to perform.
-
#confusable?(s1 : String, s2 : String) : Bool
Returns
trueif s1 and s2 are visually confusable with one another. - #finalize
-
#restriction_level : RestrictionLevel
Returns the restriction level currently configured on this checker.
-
#restriction_level=(level : RestrictionLevel)
Sets the restriction level.
-
#safe?(text : String) : Bool
Returns
trueif text passes all enabled spoof checks. -
#skeleton(text : String) : String
Returns the skeleton of text — a canonicalized form used to detect confusable pairs.
- #to_unsafe : LibICU::USpoofChecker
Constructor Detail
Class Method Detail
Returns the inclusion set: the set of characters that are explicitly allowed to appear in identifiers regardless of other restrictions.
The returned set is not owned by this checker.
Returns the recommended set: the set of characters recommended by Unicode TR#39 for use in identifiers.
The returned set is not owned by this checker.
Instance Method Detail
Returns the comma-separated list of allowed locales, or an empty string if no locale restriction is set.
Restricts the set of allowed characters to those belonging to the given comma-separated list of locale script(s).
sc.allowed_locales = "en, fr"
Returns true if s1 and s2 are BiDi-confusable in the given direction.
Returns the BiDi skeleton of text for the given direction.
Runs all enabled spoof checks on text, populating result with detailed information, and returns the bitmask of failed checks.
result = ICU::SpoofChecker::CheckResult.new
sc.check("hello", result)
result.restriction_level # => ICU::SpoofChecker::RestrictionLevel::Ascii
Runs all enabled spoof checks on text and returns the bitmask of failed checks (0 means the text passed all checks).
sc.check("hello") # => 0
sc.check("ℋello") # => non-zero
Sets the checks to perform. Pass a combination of Check flags.
sc.checks = ICU::SpoofChecker::Check::Invisible | ICU::SpoofChecker::Check::MixedNumbers
Returns true if s1 and s2 are visually confusable with one another.
sc.confusable?("paypal", "рaypal") # => true (Cyrillic "р")
sc.confusable?("hello", "world") # => false
Returns the restriction level currently configured on this checker.
Sets the restriction level.
sc.restriction_level = ICU::SpoofChecker::RestrictionLevel::HighlyRestrictive
Returns true if text passes all enabled spoof checks.
sc.safe?("hello") # => true
sc.safe?("ℋello") # => false
Returns the skeleton of text — a canonicalized form used to detect confusable pairs. Two strings are confusable if and only if their skeletons are equal.
sc.skeleton("рaypal") == sc.skeleton("paypal") # => true