2 ***************************************************************************
3 * Copyright (C) 2008-2012, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 ***************************************************************************
8 * tab size: 8 (not used)
11 * created on: 2008Feb13
12 * created by: Andy Heninger
14 * Unicode Spoof Detection
20 #include "unicode/utypes.h"
21 #include "unicode/uset.h"
22 #include "unicode/parseerr.h"
23 #include "unicode/localpointer.h"
25 #if !UCONFIG_NO_NORMALIZATION
28 #if U_SHOW_CPLUSPLUS_API
29 #include "unicode/unistr.h"
30 #include "unicode/uniset.h"
36 * \brief Unicode Security and Spoofing Detection, C API.
38 * These functions are intended to check strings, typically
39 * identifiers of some type, such as URLs, for the presence of
40 * characters that are likely to be visually confusing -
41 * for cases where the displayed form of an identifier may
42 * not be what it appears to be.
44 * Unicode Technical Report #36, http://unicode.org/reports/tr36, and
45 * Unicode Technical Standard #39, http://unicode.org/reports/tr39
46 * "Unicode security considerations", give more background on
47 * security an spoofing issues with Unicode identifiers.
48 * The tests and checks provided by this module implement the recommendations
49 * from those Unicode documents.
51 * The tests available on identifiers fall into two general categories:
52 * -# Single identifier tests. Check whether an identifier is
53 * potentially confusable with any other string, or is suspicious
55 * -# Two identifier tests. Check whether two specific identifiers are confusable.
56 * This does not consider whether either of strings is potentially
57 * confusable with any string other than the exact one specified.
59 * The steps to perform confusability testing are
60 * -# Open a USpoofChecker.
61 * -# Configure the USPoofChecker for the desired set of tests. The tests that will
62 * be performed are specified by a set of USpoofChecks flags.
63 * -# Perform the checks using the pre-configured USpoofChecker. The results indicate
64 * which (if any) of the selected tests have identified possible problems with the identifier.
65 * Results are reported as a set of USpoofChecks flags; this mirrors the form in which
66 * the set of tests to perform was originally specified to the USpoofChecker.
68 * A USpoofChecker may be used repeatedly to perform checks on any number of identifiers.
70 * Thread Safety: The test functions for checking a single identifier, or for testing
71 * whether two identifiers are possible confusable, are thread safe.
72 * They may called concurrently, from multiple threads, using the same USpoofChecker instance.
74 * More generally, the standard ICU thread safety rules apply: functions that take a
75 * const USpoofChecker parameter are thread safe. Those that take a non-const
76 * USpoofChecier are not thread safe.
79 * Descriptions of the available checks.
81 * When testing whether pairs of identifiers are confusable, with the uspoof_areConfusable()
82 * family of functions, the relevant tests are
84 * -# USPOOF_SINGLE_SCRIPT_CONFUSABLE: All of the characters from the two identifiers are
85 * from a single script, and the two identifiers are visually confusable.
86 * -# USPOOF_MIXED_SCRIPT_CONFUSABLE: At least one of the identifiers contains characters
87 * from more than one script, and the two identifiers are visually confusable.
88 * -# USPOOF_WHOLE_SCRIPT_CONFUSABLE: Each of the two identifiers is of a single script, but
89 * the two identifiers are from different scripts, and they are visually confusable.
91 * The safest approach is to enable all three of these checks as a group.
93 * USPOOF_ANY_CASE is a modifier for the above tests. If the identifiers being checked can
94 * be of mixed case and are used in a case-sensitive manner, this option should be specified.
96 * If the identifiers being checked are used in a case-insensitive manner, and if they are
97 * displayed to users in lower-case form only, the USPOOF_ANY_CASE option should not be
98 * specified. Confusabality issues involving upper case letters will not be reported.
100 * When performing tests on a single identifier, with the uspoof_check() family of functions,
101 * the relevant tests are:
103 * -# USPOOF_MIXED_SCRIPT_CONFUSABLE: the identifier contains characters from multiple
104 * scripts, and there exists an identifier of a single script that is visually confusable.
105 * -# USPOOF_WHOLE_SCRIPT_CONFUSABLE: the identifier consists of characters from a single
106 * script, and there exists a visually confusable identifier.
107 * The visually confusable identifier also consists of characters from a single script.
108 * but not the same script as the identifier being checked.
109 * -# USPOOF_ANY_CASE: modifies the mixed script and whole script confusables tests. If
110 * specified, the checks will consider confusable characters of any case. If this flag is not
111 * set, the test is performed assuming case folded identifiers.
112 * -# USPOOF_SINGLE_SCRIPT: check that the identifier contains only characters from a
113 * single script. (Characters from the 'common' and 'inherited' scripts are ignored.)
114 * This is not a test for confusable identifiers
115 * -# USPOOF_INVISIBLE: check an identifier for the presence of invisible characters,
116 * such as zero-width spaces, or character sequences that are
117 * likely not to display, such as multiple occurrences of the same
118 * non-spacing mark. This check does not test the input string as a whole
119 * for conformance to any particular syntax for identifiers.
120 * -# USPOOF_CHAR_LIMIT: check that an identifier contains only characters from a specified set
121 * of acceptable characters. See uspoof_setAllowedChars() and
122 * uspoof_setAllowedLocales().
125 * Characters from the Unicode Scripts "Common" and "Inherited" are ignored when considering
126 * the script of an identifier. Common characters include digits and symbols that
127 * are normally used with text from more than one script.
129 * Identifier Skeletons: A skeleton is a transformation of an identifier, such that
130 * all identifiers that are confusable with each other have the same skeleton.
131 * Using skeletons, it is possible to build a dictionary data structure for
132 * a set of identifiers, and then quickly test whether a new identifier is
133 * confusable with an identifier already in the set. The uspoof_getSkeleton()
134 * family of functions will produce the skeleton from an identifier.
136 * Note that skeletons are not guaranteed to be stable between versions
137 * of Unicode or ICU, so an applications should not rely on creating a permanent,
138 * or difficult to update, database of skeletons. Instabilities result from
139 * identifying new pairs or sequences of characters that are visually
140 * confusable, and thus must be mapped to the same skeleton character(s).
144 struct USpoofChecker
;
145 typedef struct USpoofChecker USpoofChecker
; /**< typedef for C of USpoofChecker */
148 * Enum for the kinds of checks that USpoofChecker can perform.
149 * These enum values are used both to select the set of checks that
150 * will be performed, and to report results from the check function.
154 typedef enum USpoofChecks
{
155 /** Single script confusable test.
156 * When testing whether two identifiers are confusable, report that they are if
157 * both are from the same script and they are visually confusable.
158 * Note: this test is not applicable to a check of a single identifier.
160 USPOOF_SINGLE_SCRIPT_CONFUSABLE
= 1,
162 /** Mixed script confusable test.
163 * When checking a single identifier, report a problem if
164 * the identifier contains multiple scripts, and
165 * is confusable with some other identifier in a single script
166 * When testing whether two identifiers are confusable, report that they are if
167 * the two IDs are visually confusable,
168 * and at least one contains characters from more than one script.
170 USPOOF_MIXED_SCRIPT_CONFUSABLE
= 2,
172 /** Whole script confusable test.
173 * When checking a single identifier, report a problem if
174 * The identifier is of a single script, and
175 * there exists a confusable identifier in another script.
176 * When testing whether two identifiers are confusable, report that they are if
177 * each is of a single script,
178 * the scripts of the two identifiers are different, and
179 * the identifiers are visually confusable.
181 USPOOF_WHOLE_SCRIPT_CONFUSABLE
= 4,
183 /** Any Case Modifier for confusable identifier tests.
184 If specified, consider all characters, of any case, when looking for confusables.
185 If USPOOF_ANY_CASE is not specified, identifiers being checked are assumed to have been
186 case folded. Upper case confusable characters will not be checked.
187 Selects between Lower Case Confusable and
188 Any Case Confusable. */
191 /** Check that an identifier contains only characters from a
192 * single script (plus chars from the common and inherited scripts.)
193 * Applies to checks of a single identifier check only.
195 USPOOF_SINGLE_SCRIPT
= 16,
197 /** Check an identifier for the presence of invisible characters,
198 * such as zero-width spaces, or character sequences that are
199 * likely not to display, such as multiple occurrences of the same
200 * non-spacing mark. This check does not test the input string as a whole
201 * for conformance to any particular syntax for identifiers.
203 USPOOF_INVISIBLE
= 32,
205 /** Check that an identifier contains only characters from a specified set
206 * of acceptable characters. See uspoof_setAllowedChars() and
207 * uspoof_setAllowedLocales().
209 USPOOF_CHAR_LIMIT
= 64,
211 USPOOF_ALL_CHECKS
= 0x7f
216 * Create a Unicode Spoof Checker, configured to perform all
217 * checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT.
218 * Note that additional checks may be added in the future,
219 * resulting in the changes to the default checking behavior.
221 * @param status The error code, set if this function encounters a problem.
222 * @return the newly created Spoof Checker
225 U_STABLE USpoofChecker
* U_EXPORT2
226 uspoof_open(UErrorCode
*status
);
230 * Open a Spoof checker from its serialized from, stored in 32-bit-aligned memory.
231 * Inverse of uspoof_serialize().
232 * The memory containing the serialized data must remain valid and unchanged
233 * as long as the spoof checker, or any cloned copies of the spoof checker,
234 * are in use. Ownership of the memory remains with the caller.
235 * The spoof checker (and any clones) must be closed prior to deleting the
238 * @param data a pointer to 32-bit-aligned memory containing the serialized form of spoof data
239 * @param length the number of bytes available at data;
240 * can be more than necessary
241 * @param pActualLength receives the actual number of bytes at data taken up by the data;
243 * @param pErrorCode ICU error code
244 * @return the spoof checker.
247 * @see uspoof_serialize
250 U_STABLE USpoofChecker
* U_EXPORT2
251 uspoof_openFromSerialized(const void *data
, int32_t length
, int32_t *pActualLength
,
252 UErrorCode
*pErrorCode
);
255 * Open a Spoof Checker from the source form of the spoof data.
256 * The Three inputs correspond to the Unicode data files confusables.txt
257 * confusablesWholeScript.txt and xidmdifications.txt as described in
258 * Unicode UAX 39. The syntax of the source data is as described in UAX 39 for
259 * these files, and the content of these files is acceptable input.
261 * The character encoding of the (char *) input text is UTF-8.
263 * @param confusables a pointer to the confusable characters definitions,
264 * as found in file confusables.txt from unicode.org.
265 * @param confusablesLen The length of the confusables text, or -1 if the
266 * input string is zero terminated.
267 * @param confusablesWholeScript
268 * a pointer to the whole script confusables definitions,
269 * as found in the file confusablesWholeScript.txt from unicode.org.
270 * @param confusablesWholeScriptLen The length of the whole script confusables text, or
271 * -1 if the input string is zero terminated.
272 * @param errType In the event of an error in the input, indicates
273 * which of the input files contains the error.
274 * The value is one of USPOOF_SINGLE_SCRIPT_CONFUSABLE or
275 * USPOOF_WHOLE_SCRIPT_CONFUSABLE, or
276 * zero if no errors are found.
277 * @param pe In the event of an error in the input, receives the position
278 * in the input text (line, offset) of the error.
279 * @param status an in/out ICU UErrorCode. Among the possible errors is
280 * U_PARSE_ERROR, which is used to report syntax errors
282 * @return A spoof checker that uses the rules from the input files.
285 U_STABLE USpoofChecker
* U_EXPORT2
286 uspoof_openFromSource(const char *confusables
, int32_t confusablesLen
,
287 const char *confusablesWholeScript
, int32_t confusablesWholeScriptLen
,
288 int32_t *errType
, UParseError
*pe
, UErrorCode
*status
);
292 * Close a Spoof Checker, freeing any memory that was being held by
293 * its implementation.
296 U_STABLE
void U_EXPORT2
297 uspoof_close(USpoofChecker
*sc
);
299 #if U_SHOW_CPLUSPLUS_API
304 * \class LocalUSpoofCheckerPointer
305 * "Smart pointer" class, closes a USpoofChecker via uspoof_close().
306 * For most methods see the LocalPointerBase base class.
308 * @see LocalPointerBase
312 U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckerPointer
, USpoofChecker
, uspoof_close
);
319 * Clone a Spoof Checker. The clone will be set to perform the same checks
320 * as the original source.
322 * @param sc The source USpoofChecker
323 * @param status The error code, set if this function encounters a problem.
327 U_STABLE USpoofChecker
* U_EXPORT2
328 uspoof_clone(const USpoofChecker
*sc
, UErrorCode
*status
);
332 * Specify the set of checks that will be performed by the check
333 * functions of this Spoof Checker.
335 * @param sc The USpoofChecker
336 * @param checks The set of checks that this spoof checker will perform.
337 * The value is a bit set, obtained by OR-ing together
338 * values from enum USpoofChecks.
339 * @param status The error code, set if this function encounters a problem.
343 U_STABLE
void U_EXPORT2
344 uspoof_setChecks(USpoofChecker
*sc
, int32_t checks
, UErrorCode
*status
);
347 * Get the set of checks that this Spoof Checker has been configured to perform.
349 * @param sc The USpoofChecker
350 * @param status The error code, set if this function encounters a problem.
351 * @return The set of checks that this spoof checker will perform.
352 * The value is a bit set, obtained by OR-ing together
353 * values from enum USpoofChecks.
357 U_STABLE
int32_t U_EXPORT2
358 uspoof_getChecks(const USpoofChecker
*sc
, UErrorCode
*status
);
361 * Limit characters that are acceptable in identifiers being checked to those
362 * normally used with the languages associated with the specified locales.
363 * Any previously specified list of locales is replaced by the new settings.
365 * A set of languages is determined from the locale(s), and
366 * from those a set of acceptable Unicode scripts is determined.
367 * Characters from this set of scripts, along with characters from
368 * the "common" and "inherited" Unicode Script categories
371 * Supplying an empty string removes all restrictions;
372 * characters from any script will be allowed.
374 * The USPOOF_CHAR_LIMIT test is automatically enabled for this
375 * USpoofChecker when calling this function with a non-empty list
378 * The Unicode Set of characters that will be allowed is accessible
379 * via the uspoof_getAllowedChars() function. uspoof_setAllowedLocales()
380 * will <i>replace</i> any previously applied set of allowed characters.
382 * Adjustments, such as additions or deletions of certain classes of characters,
383 * can be made to the result of uspoof_setAllowedLocales() by
384 * fetching the resulting set with uspoof_getAllowedChars(),
385 * manipulating it with the Unicode Set API, then resetting the
386 * spoof detectors limits with uspoof_setAllowedChars()
388 * @param sc The USpoofChecker
389 * @param localesList A list list of locales, from which the language
390 * and associated script are extracted. The locales
391 * are comma-separated if there is more than one.
392 * White space may not appear within an individual locale,
393 * but is ignored otherwise.
394 * The locales are syntactically like those from the
395 * HTTP Accept-Language header.
396 * If the localesList is empty, no restrictions will be placed on
397 * the allowed characters.
399 * @param status The error code, set if this function encounters a problem.
402 U_STABLE
void U_EXPORT2
403 uspoof_setAllowedLocales(USpoofChecker
*sc
, const char *localesList
, UErrorCode
*status
);
406 * Get a list of locales for the scripts that are acceptable in strings
407 * to be checked. If no limitations on scripts have been specified,
408 * an empty string will be returned.
410 * uspoof_setAllowedChars() will reset the list of allowed to be empty.
412 * The format of the returned list is the same as that supplied to
413 * uspoof_setAllowedLocales(), but returned list may not be identical
414 * to the originally specified string; the string may be reformatted,
415 * and information other than languages from
416 * the originally specified locales may be omitted.
418 * @param sc The USpoofChecker
419 * @param status The error code, set if this function encounters a problem.
420 * @return A string containing a list of locales corresponding
421 * to the acceptable scripts, formatted like an
422 * HTTP Accept Language value.
426 U_STABLE
const char * U_EXPORT2
427 uspoof_getAllowedLocales(USpoofChecker
*sc
, UErrorCode
*status
);
431 * Limit the acceptable characters to those specified by a Unicode Set.
432 * Any previously specified character limit is
433 * is replaced by the new settings. This includes limits on
434 * characters that were set with the uspoof_setAllowedLocales() function.
436 * The USPOOF_CHAR_LIMIT test is automatically enabled for this
437 * USpoofChecker by this function.
439 * @param sc The USpoofChecker
440 * @param chars A Unicode Set containing the list of
441 * characters that are permitted. Ownership of the set
442 * remains with the caller. The incoming set is cloned by
443 * this function, so there are no restrictions on modifying
444 * or deleting the USet after calling this function.
445 * @param status The error code, set if this function encounters a problem.
448 U_STABLE
void U_EXPORT2
449 uspoof_setAllowedChars(USpoofChecker
*sc
, const USet
*chars
, UErrorCode
*status
);
453 * Get a USet for the characters permitted in an identifier.
454 * This corresponds to the limits imposed by the Set Allowed Characters
455 * functions. Limitations imposed by other checks will not be
456 * reflected in the set returned by this function.
458 * The returned set will be frozen, meaning that it cannot be modified
461 * Ownership of the returned set remains with the Spoof Detector. The
462 * returned set will become invalid if the spoof detector is closed,
463 * or if a new set of allowed characters is specified.
466 * @param sc The USpoofChecker
467 * @param status The error code, set if this function encounters a problem.
468 * @return A USet containing the characters that are permitted by
469 * the USPOOF_CHAR_LIMIT test.
472 U_STABLE
const USet
* U_EXPORT2
473 uspoof_getAllowedChars(const USpoofChecker
*sc
, UErrorCode
*status
);
476 #if U_SHOW_CPLUSPLUS_API
478 * Limit the acceptable characters to those specified by a Unicode Set.
479 * Any previously specified character limit is
480 * is replaced by the new settings. This includes limits on
481 * characters that were set with the uspoof_setAllowedLocales() function.
483 * The USPOOF_CHAR_LIMIT test is automatically enabled for this
484 * USoofChecker by this function.
486 * @param sc The USpoofChecker
487 * @param chars A Unicode Set containing the list of
488 * characters that are permitted. Ownership of the set
489 * remains with the caller. The incoming set is cloned by
490 * this function, so there are no restrictions on modifying
491 * or deleting the USet after calling this function.
492 * @param status The error code, set if this function encounters a problem.
495 U_STABLE
void U_EXPORT2
496 uspoof_setAllowedUnicodeSet(USpoofChecker
*sc
, const icu::UnicodeSet
*chars
, UErrorCode
*status
);
500 * Get a UnicodeSet for the characters permitted in an identifier.
501 * This corresponds to the limits imposed by the Set Allowed Characters /
502 * UnicodeSet functions. Limitations imposed by other checks will not be
503 * reflected in the set returned by this function.
505 * The returned set will be frozen, meaning that it cannot be modified
508 * Ownership of the returned set remains with the Spoof Detector. The
509 * returned set will become invalid if the spoof detector is closed,
510 * or if a new set of allowed characters is specified.
513 * @param sc The USpoofChecker
514 * @param status The error code, set if this function encounters a problem.
515 * @return A UnicodeSet containing the characters that are permitted by
516 * the USPOOF_CHAR_LIMIT test.
519 U_STABLE
const icu::UnicodeSet
* U_EXPORT2
520 uspoof_getAllowedUnicodeSet(const USpoofChecker
*sc
, UErrorCode
*status
);
525 * Check the specified string for possible security issues.
526 * The text to be checked will typically be an identifier of some sort.
527 * The set of checks to be performed is specified with uspoof_setChecks().
529 * @param sc The USpoofChecker
530 * @param text The string to be checked for possible security issues,
532 * @param length the length of the string to be checked, expressed in
533 * 16 bit UTF-16 code units, or -1 if the string is
535 * @param position An out parameter that receives the index of the
536 * first string position that fails the allowed character
538 * This parameter may be null if the position information
540 * If the string passes the requested checks the
541 * parameter value will not be set.
542 * @param status The error code, set if an error occurred while attempting to
544 * Spoofing or security issues detected with the input string are
545 * not reported here, but through the function's return value.
546 * @return An integer value with bits set for any potential security
547 * or spoofing issues detected. The bits are defined by
548 * enum USpoofChecks. Zero is returned if no issues
549 * are found with the input string.
552 U_STABLE
int32_t U_EXPORT2
553 uspoof_check(const USpoofChecker
*sc
,
554 const UChar
*text
, int32_t length
,
560 * Check the specified string for possible security issues.
561 * The text to be checked will typically be an identifier of some sort.
562 * The set of checks to be performed is specified with uspoof_setChecks().
564 * @param sc The USpoofChecker
565 * @param text A UTF-8 string to be checked for possible security issues.
566 * @param length the length of the string to be checked, or -1 if the string is
568 * @param position An out parameter that receives the index of the
569 * first string position that fails the allowed character
571 * This parameter may be null if the position information
573 * If the string passes the requested checks the
574 * parameter value will not be set.
575 * @param status The error code, set if an error occurred while attempting to
577 * Spoofing or security issues detected with the input string are
578 * not reported here, but through the function's return value.
579 * If the input contains invalid UTF-8 sequences,
580 * a status of U_INVALID_CHAR_FOUND will be returned.
581 * @return An integer value with bits set for any potential security
582 * or spoofing issues detected. The bits are defined by
583 * enum USpoofChecks. Zero is returned if no issues
584 * are found with the input string.
587 U_STABLE
int32_t U_EXPORT2
588 uspoof_checkUTF8(const USpoofChecker
*sc
,
589 const char *text
, int32_t length
,
594 #if U_SHOW_CPLUSPLUS_API
596 * Check the specified string for possible security issues.
597 * The text to be checked will typically be an identifier of some sort.
598 * The set of checks to be performed is specified with uspoof_setChecks().
600 * @param sc The USpoofChecker
601 * @param text A UnicodeString to be checked for possible security issues.
602 * @position An out parameter that receives the index of the
603 * first string position that fails the allowed character
605 * This parameter may be null if the position information
607 * If the string passes the requested checks the
608 * parameter value will not be set.
609 * @param status The error code, set if an error occurred while attempting to
611 * Spoofing or security issues detected with the input string are
612 * not reported here, but through the function's return value.
614 * @return An integer value with bits set for any potential security
615 * or spoofing issues detected. The bits are defined by
616 * enum USpoofChecks. Zero is returned if no issues
617 * are found with the input string.
620 U_STABLE
int32_t U_EXPORT2
621 uspoof_checkUnicodeString(const USpoofChecker
*sc
,
622 const icu::UnicodeString
&text
,
630 * Check the whether two specified strings are visually confusable.
631 * The types of confusability to be tested - single script, mixed script,
632 * or whole script - are determined by the check options set for the
635 * The tests to be performed are controlled by the flags
636 * USPOOF_SINGLE_SCRIPT_CONFUSABLE
637 * USPOOF_MIXED_SCRIPT_CONFUSABLE
638 * USPOOF_WHOLE_SCRIPT_CONFUSABLE
639 * At least one of these tests must be selected.
641 * USPOOF_ANY_CASE is a modifier for the tests. Select it if the identifiers
642 * may be of mixed case.
643 * If identifiers are case folded for comparison and
644 * display to the user, do not select the USPOOF_ANY_CASE option.
647 * @param sc The USpoofChecker
648 * @param s1 The first of the two strings to be compared for
649 * confusability. The strings are in UTF-16 format.
650 * @param length1 the length of the first string, expressed in
651 * 16 bit UTF-16 code units, or -1 if the string is
653 * @param s2 The second of the two strings to be compared for
654 * confusability. The strings are in UTF-16 format.
655 * @param length2 The length of the second string, expressed in
656 * 16 bit UTF-16 code units, or -1 if the string is
658 * @param status The error code, set if an error occurred while attempting to
660 * Confusability of the strings is not reported here,
661 * but through this function's return value.
662 * @return An integer value with bit(s) set corresponding to
663 * the type of confusability found, as defined by
664 * enum USpoofChecks. Zero is returned if the strings
665 * are not confusable.
668 U_STABLE
int32_t U_EXPORT2
669 uspoof_areConfusable(const USpoofChecker
*sc
,
670 const UChar
*s1
, int32_t length1
,
671 const UChar
*s2
, int32_t length2
,
677 * Check the whether two specified strings are visually confusable.
678 * The types of confusability to be tested - single script, mixed script,
679 * or whole script - are determined by the check options set for the
682 * @param sc The USpoofChecker
683 * @param s1 The first of the two strings to be compared for
684 * confusability. The strings are in UTF-8 format.
685 * @param length1 the length of the first string, in bytes, or -1
686 * if the string is zero terminated.
687 * @param s2 The second of the two strings to be compared for
688 * confusability. The strings are in UTF-18 format.
689 * @param length2 The length of the second string in bytes, or -1
690 * if the string is zero terminated.
691 * @param status The error code, set if an error occurred while attempting to
693 * Confusability of the strings is not reported here,
694 * but through this function's return value.
695 * @return An integer value with bit(s) set corresponding to
696 * the type of confusability found, as defined by
697 * enum USpoofChecks. Zero is returned if the strings
698 * are not confusable.
701 U_STABLE
int32_t U_EXPORT2
702 uspoof_areConfusableUTF8(const USpoofChecker
*sc
,
703 const char *s1
, int32_t length1
,
704 const char *s2
, int32_t length2
,
710 #if U_SHOW_CPLUSPLUS_API
712 * Check the whether two specified strings are visually confusable.
713 * The types of confusability to be tested - single script, mixed script,
714 * or whole script - are determined by the check options set for the
717 * @param sc The USpoofChecker
718 * @param s1 The first of the two strings to be compared for
719 * confusability. The strings are in UTF-8 format.
720 * @param s2 The second of the two strings to be compared for
721 * confusability. The strings are in UTF-18 format.
722 * @param status The error code, set if an error occurred while attempting to
724 * Confusability of the strings is not reported here,
725 * but through this function's return value.
726 * @return An integer value with bit(s) set corresponding to
727 * the type of confusability found, as defined by
728 * enum USpoofChecks. Zero is returned if the strings
729 * are not confusable.
732 U_STABLE
int32_t U_EXPORT2
733 uspoof_areConfusableUnicodeString(const USpoofChecker
*sc
,
734 const icu::UnicodeString
&s1
,
735 const icu::UnicodeString
&s2
,
741 * Get the "skeleton" for an identifier string.
742 * Skeletons are a transformation of the input string;
743 * Two strings are confusable if their skeletons are identical.
744 * See Unicode UAX 39 for additional information.
746 * Using skeletons directly makes it possible to quickly check
747 * whether an identifier is confusable with any of some large
748 * set of existing identifiers, by creating an efficiently
749 * searchable collection of the skeletons.
751 * @param sc The USpoofChecker
752 * @param type The type of skeleton, corresponding to which
753 * of the Unicode confusable data tables to use.
754 * The default is Mixed-Script, Lowercase.
755 * Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
756 * USPOOF_ANY_CASE_CONFUSABLE. The two flags may be ORed.
757 * @param s The input string whose skeleton will be computed.
758 * @param length The length of the input string, expressed in 16 bit
759 * UTF-16 code units, or -1 if the string is zero terminated.
760 * @param dest The output buffer, to receive the skeleton string.
761 * @param destCapacity The length of the output buffer, in 16 bit units.
762 * The destCapacity may be zero, in which case the function will
763 * return the actual length of the skeleton.
764 * @param status The error code, set if an error occurred while attempting to
766 * @return The length of the skeleton string. The returned length
767 * is always that of the complete skeleton, even when the
768 * supplied buffer is too small (or of zero length)
772 U_STABLE
int32_t U_EXPORT2
773 uspoof_getSkeleton(const USpoofChecker
*sc
,
775 const UChar
*s
, int32_t length
,
776 UChar
*dest
, int32_t destCapacity
,
780 * Get the "skeleton" for an identifier string.
781 * Skeletons are a transformation of the input string;
782 * Two strings are confusable if their skeletons are identical.
783 * See Unicode UAX 39 for additional information.
785 * Using skeletons directly makes it possible to quickly check
786 * whether an identifier is confusable with any of some large
787 * set of existing identifiers, by creating an efficiently
788 * searchable collection of the skeletons.
790 * @param sc The USpoofChecker
791 * @param type The type of skeleton, corresponding to which
792 * of the Unicode confusable data tables to use.
793 * The default is Mixed-Script, Lowercase.
794 * Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
795 * USPOOF_ANY_CASE. The two flags may be ORed.
796 * @param s The UTF-8 format input string whose skeleton will be computed.
797 * @param length The length of the input string, in bytes,
798 * or -1 if the string is zero terminated.
799 * @param dest The output buffer, to receive the skeleton string.
800 * @param destCapacity The length of the output buffer, in bytes.
801 * The destCapacity may be zero, in which case the function will
802 * return the actual length of the skeleton.
803 * @param status The error code, set if an error occurred while attempting to
804 * perform the check. Possible Errors include U_INVALID_CHAR_FOUND
805 * for invalid UTF-8 sequences, and
806 * U_BUFFER_OVERFLOW_ERROR if the destination buffer is too small
807 * to hold the complete skeleton.
808 * @return The length of the skeleton string, in bytes. The returned length
809 * is always that of the complete skeleton, even when the
810 * supplied buffer is too small (or of zero length)
814 U_STABLE
int32_t U_EXPORT2
815 uspoof_getSkeletonUTF8(const USpoofChecker
*sc
,
817 const char *s
, int32_t length
,
818 char *dest
, int32_t destCapacity
,
821 #if U_SHOW_CPLUSPLUS_API
823 * Get the "skeleton" for an identifier string.
824 * Skeletons are a transformation of the input string;
825 * Two strings are confusable if their skeletons are identical.
826 * See Unicode UAX 39 for additional information.
828 * Using skeletons directly makes it possible to quickly check
829 * whether an identifier is confusable with any of some large
830 * set of existing identifiers, by creating an efficiently
831 * searchable collection of the skeletons.
833 * @param sc The USpoofChecker.
834 * @param type The type of skeleton, corresponding to which
835 * of the Unicode confusable data tables to use.
836 * The default is Mixed-Script, Lowercase.
837 * Allowed options are USPOOF_SINGLE_SCRIPT_CONFUSABLE and
838 * USPOOF_ANY_CASE_CONFUSABLE. The two flags may be ORed.
839 * @param s The input string whose skeleton will be computed.
840 * @param dest The output string, to receive the skeleton string.
841 * @param destCapacity The length of the output buffer, in bytes.
842 * The destCapacity may be zero, in which case the function will
843 * return the actual length of the skeleton.
844 * @param status The error code, set if an error occurred while attempting to
846 * @return A reference to the destination (skeleton) string.
850 U_STABLE
icu::UnicodeString
& U_EXPORT2
851 uspoof_getSkeletonUnicodeString(const USpoofChecker
*sc
,
853 const icu::UnicodeString
&s
,
854 icu::UnicodeString
&dest
,
856 #endif /* U_SHOW_CPLUSPLUS_API */
860 * Serialize the data for a spoof detector into a chunk of memory.
861 * The flattened spoof detection tables can later be used to efficiently
862 * instantiate a new Spoof Detector.
864 * @param sc the Spoof Detector whose data is to be serialized.
865 * @param data a pointer to 32-bit-aligned memory to be filled with the data,
866 * can be NULL if capacity==0
867 * @param capacity the number of bytes available at data,
868 * or 0 for preflighting
869 * @param status an in/out ICU UErrorCode; possible errors include:
870 * - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
871 * - U_ILLEGAL_ARGUMENT_ERROR the data or capacity parameters are bad
872 * @return the number of bytes written or needed for the spoof data
874 * @see utrie2_openFromSerialized()
877 U_STABLE
int32_t U_EXPORT2
878 uspoof_serialize(USpoofChecker
*sc
,
879 void *data
, int32_t capacity
,
885 #endif /* USPOOF_H */