ICU 60.2  60.2
uspoof.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ***************************************************************************
5 * Copyright (C) 2008-2016, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ***************************************************************************
8 * file name: uspoof.h
9 * encoding: UTF-8
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2008Feb13
14 * created by: Andy Heninger
15 *
16 * Unicode Spoof Detection
17 */
18 
19 #ifndef USPOOF_H
20 #define USPOOF_H
21 
22 #include "unicode/utypes.h"
23 #include "unicode/uset.h"
24 #include "unicode/parseerr.h"
25 #include "unicode/localpointer.h"
26 
27 #if !UCONFIG_NO_NORMALIZATION
28 
29 
30 #if U_SHOW_CPLUSPLUS_API
31 #include "unicode/unistr.h"
32 #include "unicode/uniset.h"
33 #endif
34 
35 
370 struct USpoofChecker;
374 typedef struct USpoofChecker USpoofChecker;
376 struct USpoofCheckResult;
382 
390 typedef enum USpoofChecks {
400 
410 
420 
431 
432 #ifndef U_HIDE_DEPRECATED_API
433 
439 #endif /* U_HIDE_DEPRECATED_API */
440 
455 
456 #ifndef U_HIDE_DEPRECATED_API
457 
463 #endif /* U_HIDE_DEPRECATED_API */
464 
472 
479 
487 
494 
507  USPOOF_AUX_INFO = 0x40000000
508 
509  } USpoofChecks;
510 
511 
521  typedef enum URestrictionLevel {
528  USPOOF_ASCII = 0x10000000,
569  USPOOF_UNRESTRICTIVE = 0x60000000,
576 #ifndef U_HIDE_INTERNAL_API
577 
582 #endif /* U_HIDE_INTERNAL_API */
584 
595 U_STABLE USpoofChecker * U_EXPORT2
596 uspoof_open(UErrorCode *status);
597 
598 
620 U_STABLE USpoofChecker * U_EXPORT2
621 uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength,
622  UErrorCode *pErrorCode);
623 
654 U_STABLE USpoofChecker * U_EXPORT2
655 uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
656  const char *confusablesWholeScript, int32_t confusablesWholeScriptLen,
657  int32_t *errType, UParseError *pe, UErrorCode *status);
658 
659 
665 U_STABLE void U_EXPORT2
667 
668 #if U_SHOW_CPLUSPLUS_API
669 
671 
682 
684 
685 #endif
686 
696 U_STABLE USpoofChecker * U_EXPORT2
697 uspoof_clone(const USpoofChecker *sc, UErrorCode *status);
698 
699 
737 U_STABLE void U_EXPORT2
738 uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status);
739 
751 U_STABLE int32_t U_EXPORT2
752 uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status);
753 
765 U_STABLE void U_EXPORT2
767 
768 
776 U_STABLE URestrictionLevel U_EXPORT2
778 
821 U_STABLE void U_EXPORT2
822 uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status);
823 
845 U_STABLE const char * U_EXPORT2
847 
848 
867 U_STABLE void U_EXPORT2
868 uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status);
869 
870 
891 U_STABLE const USet * U_EXPORT2
893 
894 
895 #if U_SHOW_CPLUSPLUS_API
896 
914 U_STABLE void U_EXPORT2
916 
917 
938 U_STABLE const icu::UnicodeSet * U_EXPORT2
940 #endif
941 
942 
975 U_STABLE int32_t U_EXPORT2
976 uspoof_check(const USpoofChecker *sc,
977  const UChar *id, int32_t length,
978  int32_t *position,
979  UErrorCode *status);
980 
981 
1014 U_STABLE int32_t U_EXPORT2
1016  const char *id, int32_t length,
1017  int32_t *position,
1018  UErrorCode *status);
1019 
1020 
1021 #if U_SHOW_CPLUSPLUS_API
1022 
1050 U_STABLE int32_t U_EXPORT2
1052  const icu::UnicodeString &id,
1053  int32_t *position,
1054  UErrorCode *status);
1055 #endif
1056 
1057 
1086 U_STABLE int32_t U_EXPORT2
1087 uspoof_check2(const USpoofChecker *sc,
1088  const UChar* id, int32_t length,
1089  USpoofCheckResult* checkResult,
1090  UErrorCode *status);
1091 
1123 U_STABLE int32_t U_EXPORT2
1125  const char *id, int32_t length,
1126  USpoofCheckResult* checkResult,
1127  UErrorCode *status);
1128 
1129 #if U_SHOW_CPLUSPLUS_API
1130 
1155 U_STABLE int32_t U_EXPORT2
1157  const icu::UnicodeString &id,
1158  USpoofCheckResult* checkResult,
1159  UErrorCode *status);
1160 #endif
1161 
1180 U_STABLE USpoofCheckResult* U_EXPORT2
1182 
1190 U_STABLE void U_EXPORT2
1192 
1193 #if U_SHOW_CPLUSPLUS_API
1194 
1196 
1207 
1209 
1210 #endif
1211 
1226 U_STABLE int32_t U_EXPORT2
1227 uspoof_getCheckResultChecks(const USpoofCheckResult *checkResult, UErrorCode *status);
1228 
1239 U_STABLE URestrictionLevel U_EXPORT2
1241 
1253 U_STABLE const USet* U_EXPORT2
1254 uspoof_getCheckResultNumerics(const USpoofCheckResult *checkResult, UErrorCode *status);
1255 
1256 
1300 U_STABLE int32_t U_EXPORT2
1302  const UChar *id1, int32_t length1,
1303  const UChar *id2, int32_t length2,
1304  UErrorCode *status);
1305 
1306 
1307 
1333 U_STABLE int32_t U_EXPORT2
1335  const char *id1, int32_t length1,
1336  const char *id2, int32_t length2,
1337  UErrorCode *status);
1338 
1339 
1340 
1341 
1342 #if U_SHOW_CPLUSPLUS_API
1343 
1364 U_STABLE int32_t U_EXPORT2
1366  const icu::UnicodeString &s1,
1367  const icu::UnicodeString &s2,
1368  UErrorCode *status);
1369 #endif
1370 
1371 
1403 U_STABLE int32_t U_EXPORT2
1405  uint32_t type,
1406  const UChar *id, int32_t length,
1407  UChar *dest, int32_t destCapacity,
1408  UErrorCode *status);
1409 
1443 U_STABLE int32_t U_EXPORT2
1445  uint32_t type,
1446  const char *id, int32_t length,
1447  char *dest, int32_t destCapacity,
1448  UErrorCode *status);
1449 
1450 #if U_SHOW_CPLUSPLUS_API
1451 
1474 U_I18N_API icu::UnicodeString & U_EXPORT2
1476  uint32_t type,
1477  const icu::UnicodeString &id,
1478  icu::UnicodeString &dest,
1479  UErrorCode *status);
1480 #endif /* U_SHOW_CPLUSPLUS_API */
1481 
1494 U_STABLE const USet * U_EXPORT2
1496 
1509 U_STABLE const USet * U_EXPORT2
1511 
1512 #if U_SHOW_CPLUSPLUS_API
1513 
1526 U_STABLE const icu::UnicodeSet * U_EXPORT2
1528 
1541 U_STABLE const icu::UnicodeSet * U_EXPORT2
1543 
1544 #endif /* U_SHOW_CPLUSPLUS_API */
1545 
1568 U_STABLE int32_t U_EXPORT2
1570  void *data, int32_t capacity,
1571  UErrorCode *status);
1572 
1573 
1574 #endif
1575 
1576 #endif /* USPOOF_H */
void uspoof_close(USpoofChecker *sc)
Close a Spoof Checker, freeing any memory that was being held by its implementation.
U_STABLE const icu::UnicodeSet *U_EXPORT2 uspoof_getInclusionUnicodeSet(UErrorCode *status)
Get the set of Candidate Characters for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
URestrictionLevel
Constants from UAX #39 for use in uspoof_setRestrictionLevel, and for returned identifier restriction...
Definition: uspoof.h:521
Check an identifier for the presence of invisible characters, such as zero-width spaces, or character sequences that are likely not to display, such as multiple occurrences of the same non-spacing mark.
Definition: uspoof.h:471
Check that an identifier contains only characters from a single script (plus chars from the common an...
Definition: uspoof.h:462
U_STABLE int32_t U_EXPORT2 uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status)
Get the set of checks that this Spoof Checker has been configured to perform.
struct USpoofCheckResult USpoofCheckResult
Definition: uspoof.h:381
U_NAMESPACE_END U_STABLE int32_t U_EXPORT2 uspoof_getCheckResultChecks(const USpoofCheckResult *checkResult, UErrorCode *status)
Indicates which of the spoof check(s) have failed.
USpoofChecker * uspoof_clone(const USpoofChecker *sc, UErrorCode *status)
Clone a Spoof Checker.
All characters in the string are in the identifier profile and all characters in the string are in th...
Definition: uspoof.h:528
U_I18N_API icu::UnicodeString &U_EXPORT2 uspoof_getSkeletonUnicodeString(const USpoofChecker *sc, uint32_t type, const icu::UnicodeString &id, icu::UnicodeString &dest, UErrorCode *status)
Get the "skeleton" for an identifier.
Check that an identifier contains only characters from a specified set of acceptable characters...
Definition: uspoof.h:478
All characters in the string are in the identifier profile.
Definition: uspoof.h:563
USpoofChecks
Enum for the kinds of checks that USpoofChecker can perform.
Definition: uspoof.h:390
C++ API: Unicode String.
USpoofChecker * uspoof_open(UErrorCode *status)
Create a Unicode Spoof Checker, configured to perform all checks except for USPOOF_LOCALE_LIMIT and U...
U_STABLE int32_t U_EXPORT2 uspoof_check2UTF8(const USpoofChecker *sc, const char *id, int32_t length, USpoofCheckResult *checkResult, UErrorCode *status)
Check the specified string for possible security issues.
U_STABLE void U_EXPORT2 uspoof_closeCheckResult(USpoofCheckResult *checkResult)
Close a USpoofCheckResult, freeing any memory that was being held by its implementation.
Enable this flag in uspoof_setChecks to turn on all types of confusables.
Definition: uspoof.h:430
USpoofChecker * uspoof_openFromSource(const char *confusables, int32_t confusablesLen, const char *confusablesWholeScript, int32_t confusablesWholeScriptLen, int32_t *errType, UParseError *pe, UErrorCode *status)
Open a Spoof Checker from the source form of the spoof data.
U_STABLE const USet *U_EXPORT2 uspoof_getRecommendedSet(UErrorCode *status)
Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined in http:/...
C API: Unicode Set.
U_STABLE void U_EXPORT2 uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status)
Limit the acceptable characters to those specified by a Unicode Set.
Enable all spoof checks.
Definition: uspoof.h:493
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside...
Definition: utypes.h:360
U_STABLE URestrictionLevel U_EXPORT2 uspoof_getCheckResultRestrictionLevel(const USpoofCheckResult *checkResult, UErrorCode *status)
Gets the restriction level that the text meets, if the USPOOF_RESTRICTION_LEVEL check was enabled; ot...
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
U_STABLE const char *U_EXPORT2 uspoof_getAllowedLocales(USpoofChecker *sc, UErrorCode *status)
Get a list of locales for the scripts that are acceptable in strings to be checked.
This flag is deprecated and no longer affects the behavior of SpoofChecker.
Definition: uspoof.h:438
When performing the two-string uspoof_areConfusable test, this flag in the return value indicates tha...
Definition: uspoof.h:419
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
"Smart pointer" definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:487
C++ API: "Smart pointers" for use with and in ICU4C C++ code.
U_STABLE const icu::UnicodeSet *U_EXPORT2 uspoof_getRecommendedUnicodeSet(UErrorCode *status)
Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined in http:/...
U_STABLE void U_EXPORT2 uspoof_setRestrictionLevel(USpoofChecker *sc, URestrictionLevel restrictionLevel)
Set the loosest restriction level allowed for strings.
The string classifies as Highly Restrictive, or all characters in the string are in the identifier pr...
Definition: uspoof.h:557
Check that an identifier does not mix numbers from different numbering systems.
Definition: uspoof.h:486
The string classifies as ASCII-Only, or all characters in the string are in the identifier profile an...
Definition: uspoof.h:535
The string classifies as Single Script, or all characters in the string are in the identifier profile...
Definition: uspoof.h:549
U_STABLE int32_t U_EXPORT2 uspoof_getSkeleton(const USpoofChecker *sc, uint32_t type, const UChar *id, int32_t length, UChar *dest, int32_t destCapacity, UErrorCode *status)
Get the "skeleton" for an identifier.
U_STABLE int32_t U_EXPORT2 uspoof_areConfusableUTF8(const USpoofChecker *sc, const char *id1, int32_t length1, const char *id2, int32_t length2, UErrorCode *status)
A version of uspoof_areConfusable accepting strings in UTF-8 format.
USpoofChecker * uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength, UErrorCode *pErrorCode)
Open a Spoof checker from its serialized form, stored in 32-bit-aligned memory.
U_STABLE int32_t U_EXPORT2 uspoof_check2(const USpoofChecker *sc, const UChar *id, int32_t length, USpoofCheckResult *checkResult, UErrorCode *status)
Check the specified string for possible security issues.
U_STABLE void U_EXPORT2 uspoof_setAllowedUnicodeSet(USpoofChecker *sc, const icu::UnicodeSet *chars, UErrorCode *status)
Limit the acceptable characters to those specified by a Unicode Set.
U_STABLE void U_EXPORT2 uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status)
Limit characters that are acceptable in identifiers being checked to those normally used with the lan...
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:278
struct USpoofChecker USpoofChecker
typedef for C of USpoofChecker
Definition: uspoof.h:374
U_STABLE USpoofCheckResult *U_EXPORT2 uspoof_openCheckResult(UErrorCode *status)
Create a USpoofCheckResult, used by the uspoof_check2 class of functions to return information about ...
"Smart pointer" class, closes a USpoofChecker via uspoof_close().
U_STABLE const USet *U_EXPORT2 uspoof_getCheckResultNumerics(const USpoofCheckResult *checkResult, UErrorCode *status)
Gets the set of numerics found in the string, if the USPOOF_MIXED_NUMBERS check was enabled; otherwis...
When performing the two-string uspoof_areConfusable test, this flag in the return value indicates tha...
Definition: uspoof.h:399
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:349
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
struct USet USet
Definition: ucnv.h:69
C API: Parse Error Information.
U_STABLE const icu::UnicodeSet *U_EXPORT2 uspoof_getAllowedUnicodeSet(const USpoofChecker *sc, UErrorCode *status)
Get a UnicodeSet for the characters permitted in an identifier.
U_STABLE URestrictionLevel U_EXPORT2 uspoof_getRestrictionLevel(const USpoofChecker *sc)
Get the Restriction Level that will be tested if the checks include USPOOF_RESTRICTION_LEVEL.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
When performing the two-string uspoof_areConfusable test, this flag in the return value indicates tha...
Definition: uspoof.h:409
U_STABLE int32_t U_EXPORT2 uspoof_checkUTF8(const USpoofChecker *sc, const char *id, int32_t length, int32_t *position, UErrorCode *status)
Check the specified string for possible security issues.
U_STABLE void U_EXPORT2 uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status)
Specify the bitmask of checks that will be performed by uspoof_check.
U_STABLE int32_t U_EXPORT2 uspoof_check(const USpoofChecker *sc, const UChar *id, int32_t length, int32_t *position, UErrorCode *status)
Check the specified string for possible security issues.
Enable the return of auxillary (non-error) information in the upper bits of the check results value...
Definition: uspoof.h:507
U_STABLE int32_t U_EXPORT2 uspoof_check2UnicodeString(const USpoofChecker *sc, const icu::UnicodeString &id, USpoofCheckResult *checkResult, UErrorCode *status)
Check the specified string for possible security issues.
U_STABLE int32_t U_EXPORT2 uspoof_checkUnicodeString(const USpoofChecker *sc, const icu::UnicodeString &id, int32_t *position, UErrorCode *status)
Check the specified string for possible security issues.
Check that an identifier is no looser than the specified RestrictionLevel.
Definition: uspoof.h:454
A UParseError struct is used to returned detailed information about parsing errors.
Definition: parseerr.h:58
Basic definitions for ICU, for both C and C++ APIs.
U_STABLE const USet *U_EXPORT2 uspoof_getInclusionSet(UErrorCode *status)
Get the set of Candidate Characters for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
Mask for selecting the Restriction Level bits from the return value of uspoof_check.
Definition: uspoof.h:575
U_STABLE int32_t U_EXPORT2 uspoof_serialize(USpoofChecker *sc, void *data, int32_t capacity, UErrorCode *status)
Serialize the data for a spoof detector into a chunk of memory.
U_STABLE int32_t U_EXPORT2 uspoof_areConfusableUnicodeString(const USpoofChecker *sc, const icu::UnicodeString &s1, const icu::UnicodeString &s2, UErrorCode *status)
A version of uspoof_areConfusable accepting UnicodeStrings.
Any valid identifiers, including characters outside of the Identifier Profile.
Definition: uspoof.h:569
U_STABLE const USet *U_EXPORT2 uspoof_getAllowedChars(const USpoofChecker *sc, UErrorCode *status)
Get a USet for the characters permitted in an identifier.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:286
"Smart pointer" class, closes a USpoofCheckResult via uspoof_closeCheckResult.
U_STABLE int32_t U_EXPORT2 uspoof_areConfusable(const USpoofChecker *sc, const UChar *id1, int32_t length1, const UChar *id2, int32_t length2, UErrorCode *status)
Check the whether two specified strings are visually confusable.
U_STABLE int32_t U_EXPORT2 uspoof_getSkeletonUTF8(const USpoofChecker *sc, uint32_t type, const char *id, int32_t length, char *dest, int32_t destCapacity, UErrorCode *status)
Get the "skeleton" for an identifier.
An undefined restriction level.
Definition: uspoof.h:581
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
C++ API: Unicode Set.