uspoof.h 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  1. // Copyright (C) 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: US-ASCII
  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. #ifndef USPOOF_H
  19. #define USPOOF_H
  20. #include "unicode/utypes.h"
  21. #include "unicode/uset.h"
  22. #include "unicode/parseerr.h"
  23. #include "unicode/localpointer.h"
  24. #if !UCONFIG_NO_NORMALIZATION
  25. #if U_SHOW_CPLUSPLUS_API
  26. #include "unicode/unistr.h"
  27. #include "unicode/uniset.h"
  28. #endif
  29. /**
  30. * \file
  31. * \brief Unicode Security and Spoofing Detection, C API.
  32. *
  33. * <p>
  34. * This class, based on <a href="http://unicode.org/reports/tr36">Unicode Technical Report #36</a> and
  35. * <a href="http://unicode.org/reports/tr39">Unicode Technical Standard #39</a>, has two main functions:
  36. *
  37. * <ol>
  38. * <li>Checking whether two strings are visually <em>confusable</em> with each other, such as "Harvest" and
  39. * &quot;&Eta;arvest&quot;, where the second string starts with the Greek capital letter Eta.</li>
  40. * <li>Checking whether an individual string is likely to be an attempt at confusing the reader (<em>spoof
  41. * detection</em>), such as "paypal" with some Latin characters substituted with Cyrillic look-alikes.</li>
  42. * </ol>
  43. *
  44. * <p>
  45. * Although originally designed as a method for flagging suspicious identifier strings such as URLs,
  46. * <code>USpoofChecker</code> has a number of other practical use cases, such as preventing attempts to evade bad-word
  47. * content filters.
  48. *
  49. * <p>
  50. * The functions of this class are exposed as C API, with a handful of syntactical conveniences for C++.
  51. *
  52. * <h2>Confusables</h2>
  53. *
  54. * <p>
  55. * The following example shows how to use <code>USpoofChecker</code> to check for confusability between two strings:
  56. *
  57. * \code{.c}
  58. * UErrorCode status = U_ZERO_ERROR;
  59. * UChar* str1 = (UChar*) u"Harvest";
  60. * UChar* str2 = (UChar*) u"\u0397arvest"; // with U+0397 GREEK CAPITAL LETTER ETA
  61. *
  62. * USpoofChecker* sc = uspoof_open(&status);
  63. * uspoof_setChecks(sc, USPOOF_CONFUSABLE, &status);
  64. *
  65. * int32_t bitmask = uspoof_areConfusable(sc, str1, -1, str2, -1, &status);
  66. * UBool result = bitmask != 0;
  67. * // areConfusable: 1 (status: U_ZERO_ERROR)
  68. * printf("areConfusable: %d (status: %s)\n", result, u_errorName(status));
  69. * uspoof_close(sc);
  70. * \endcode
  71. *
  72. * <p>
  73. * The call to {@link uspoof_open} creates a <code>USpoofChecker</code> object; the call to {@link uspoof_setChecks}
  74. * enables confusable checking and disables all other checks; the call to {@link uspoof_areConfusable} performs the
  75. * confusability test; and the following line extracts the result out of the return value. For best performance,
  76. * the instance should be created once (e.g., upon application startup), and the efficient
  77. * {@link uspoof_areConfusable} method can be used at runtime.
  78. *
  79. * <p>
  80. * The type {@link LocalUSpoofCheckerPointer} is exposed for C++ programmers. It will automatically call
  81. * {@link uspoof_close} when the object goes out of scope:
  82. *
  83. * \code{.cpp}
  84. * UErrorCode status = U_ZERO_ERROR;
  85. * LocalUSpoofCheckerPointer sc(uspoof_open(&status));
  86. * uspoof_setChecks(sc.getAlias(), USPOOF_CONFUSABLE, &status);
  87. * // ...
  88. * \endcode
  89. *
  90. * <p>
  91. * UTS 39 defines two strings to be <em>confusable</em> if they map to the same <em>skeleton string</em>. A skeleton can
  92. * be thought of as a "hash code". {@link uspoof_getSkeleton} computes the skeleton for a particular string, so
  93. * the following snippet is equivalent to the example above:
  94. *
  95. * \code{.c}
  96. * UErrorCode status = U_ZERO_ERROR;
  97. * UChar* str1 = (UChar*) u"Harvest";
  98. * UChar* str2 = (UChar*) u"\u0397arvest"; // with U+0397 GREEK CAPITAL LETTER ETA
  99. *
  100. * USpoofChecker* sc = uspoof_open(&status);
  101. * uspoof_setChecks(sc, USPOOF_CONFUSABLE, &status);
  102. *
  103. * // Get skeleton 1
  104. * int32_t skel1Len = uspoof_getSkeleton(sc, 0, str1, -1, NULL, 0, &status);
  105. * UChar* skel1 = (UChar*) malloc(++skel1Len * sizeof(UChar));
  106. * status = U_ZERO_ERROR;
  107. * uspoof_getSkeleton(sc, 0, str1, -1, skel1, skel1Len, &status);
  108. *
  109. * // Get skeleton 2
  110. * int32_t skel2Len = uspoof_getSkeleton(sc, 0, str2, -1, NULL, 0, &status);
  111. * UChar* skel2 = (UChar*) malloc(++skel2Len * sizeof(UChar));
  112. * status = U_ZERO_ERROR;
  113. * uspoof_getSkeleton(sc, 0, str2, -1, skel2, skel2Len, &status);
  114. *
  115. * // Are the skeletons the same?
  116. * UBool result = u_strcmp(skel1, skel2) == 0;
  117. * // areConfusable: 1 (status: U_ZERO_ERROR)
  118. * printf("areConfusable: %d (status: %s)\n", result, u_errorName(status));
  119. * uspoof_close(sc);
  120. * free(skel1);
  121. * free(skel2);
  122. * \endcode
  123. *
  124. * <p>
  125. * If you need to check if a string is confusable with any string in a dictionary of many strings, rather than calling
  126. * {@link uspoof_areConfusable} many times in a loop, {@link uspoof_getSkeleton} can be used instead, as shown below:
  127. *
  128. * \code{.c}
  129. * UErrorCode status = U_ZERO_ERROR;
  130. * #define DICTIONARY_LENGTH 2
  131. * UChar* dictionary[DICTIONARY_LENGTH] = { (UChar*) u"lorem", (UChar*) u"ipsum" };
  132. * UChar* skeletons[DICTIONARY_LENGTH];
  133. * UChar* str = (UChar*) u"1orern";
  134. *
  135. * // Setup:
  136. * USpoofChecker* sc = uspoof_open(&status);
  137. * uspoof_setChecks(sc, USPOOF_CONFUSABLE, &status);
  138. * for (size_t i=0; i<DICTIONARY_LENGTH; i++) {
  139. * UChar* word = dictionary[i];
  140. * int32_t len = uspoof_getSkeleton(sc, 0, word, -1, NULL, 0, &status);
  141. * skeletons[i] = (UChar*) malloc(++len * sizeof(UChar));
  142. * status = U_ZERO_ERROR;
  143. * uspoof_getSkeleton(sc, 0, word, -1, skeletons[i], len, &status);
  144. * }
  145. *
  146. * // Live Check:
  147. * {
  148. * int32_t len = uspoof_getSkeleton(sc, 0, str, -1, NULL, 0, &status);
  149. * UChar* skel = (UChar*) malloc(++len * sizeof(UChar));
  150. * status = U_ZERO_ERROR;
  151. * uspoof_getSkeleton(sc, 0, str, -1, skel, len, &status);
  152. * UBool result = FALSE;
  153. * for (size_t i=0; i<DICTIONARY_LENGTH; i++) {
  154. * result = u_strcmp(skel, skeletons[i]) == 0;
  155. * if (result == TRUE) { break; }
  156. * }
  157. * // Has confusable in dictionary: 1 (status: U_ZERO_ERROR)
  158. * printf("Has confusable in dictionary: %d (status: %s)\n", result, u_errorName(status));
  159. * free(skel);
  160. * }
  161. *
  162. * for (size_t i=0; i<DICTIONARY_LENGTH; i++) {
  163. * free(skeletons[i]);
  164. * }
  165. * uspoof_close(sc);
  166. * \endcode
  167. *
  168. * <p>
  169. * <b>Note:</b> Since the Unicode confusables mapping table is frequently updated, confusable skeletons are <em>not</em>
  170. * guaranteed to be the same between ICU releases. We therefore recommend that you always compute confusable skeletons
  171. * at runtime and do not rely on creating a permanent, or difficult to update, database of skeletons.
  172. *
  173. * <h2>Spoof Detection</h2>
  174. *
  175. * <p>
  176. * The following snippet shows a minimal example of using <code>USpoofChecker</code> to perform spoof detection on a
  177. * string:
  178. *
  179. * \code{.c}
  180. * UErrorCode status = U_ZERO_ERROR;
  181. * UChar* str = (UChar*) u"p\u0430ypal"; // with U+0430 CYRILLIC SMALL LETTER A
  182. *
  183. * // Get the default set of allowable characters:
  184. * USet* allowed = uset_openEmpty();
  185. * uset_addAll(allowed, uspoof_getRecommendedSet(&status));
  186. * uset_addAll(allowed, uspoof_getInclusionSet(&status));
  187. *
  188. * USpoofChecker* sc = uspoof_open(&status);
  189. * uspoof_setAllowedChars(sc, allowed, &status);
  190. * uspoof_setRestrictionLevel(sc, USPOOF_MODERATELY_RESTRICTIVE);
  191. *
  192. * int32_t bitmask = uspoof_check(sc, str, -1, NULL, &status);
  193. * UBool result = bitmask != 0;
  194. * // fails checks: 1 (status: U_ZERO_ERROR)
  195. * printf("fails checks: %d (status: %s)\n", result, u_errorName(status));
  196. * uspoof_close(sc);
  197. * uset_close(allowed);
  198. * \endcode
  199. *
  200. * <p>
  201. * As in the case for confusability checking, it is good practice to create one <code>USpoofChecker</code> instance at
  202. * startup, and call the cheaper {@link uspoof_check} online. We specify the set of
  203. * allowed characters to be those with type RECOMMENDED or INCLUSION, according to the recommendation in UTS 39.
  204. *
  205. * <p>
  206. * In addition to {@link uspoof_check}, the function {@link uspoof_checkUTF8} is exposed for UTF8-encoded char* strings,
  207. * and {@link uspoof_checkUnicodeString} is exposed for C++ programmers.
  208. *
  209. * <p>
  210. * If the {@link USPOOF_AUX_INFO} check is enabled, a limited amount of information on why a string failed the checks
  211. * is available in the returned bitmask. For complete information, use the {@link uspoof_check2} class of functions
  212. * with a {@link USpoofCheckResult} parameter:
  213. *
  214. * \code{.c}
  215. * UErrorCode status = U_ZERO_ERROR;
  216. * UChar* str = (UChar*) u"p\u0430ypal"; // with U+0430 CYRILLIC SMALL LETTER A
  217. *
  218. * // Get the default set of allowable characters:
  219. * USet* allowed = uset_openEmpty();
  220. * uset_addAll(allowed, uspoof_getRecommendedSet(&status));
  221. * uset_addAll(allowed, uspoof_getInclusionSet(&status));
  222. *
  223. * USpoofChecker* sc = uspoof_open(&status);
  224. * uspoof_setAllowedChars(sc, allowed, &status);
  225. * uspoof_setRestrictionLevel(sc, USPOOF_MODERATELY_RESTRICTIVE);
  226. *
  227. * USpoofCheckResult* checkResult = uspoof_openCheckResult(&status);
  228. * int32_t bitmask = uspoof_check2(sc, str, -1, checkResult, &status);
  229. *
  230. * int32_t failures1 = bitmask;
  231. * int32_t failures2 = uspoof_getCheckResultChecks(checkResult, &status);
  232. * assert(failures1 == failures2);
  233. * // checks that failed: 0x00000010 (status: U_ZERO_ERROR)
  234. * printf("checks that failed: %#010x (status: %s)\n", failures1, u_errorName(status));
  235. *
  236. * // Cleanup:
  237. * uspoof_close(sc);
  238. * uset_close(allowed);
  239. * uspoof_closeCheckResult(checkResult);
  240. * \endcode
  241. *
  242. * C++ users can take advantage of a few syntactical conveniences. The following snippet is functionally
  243. * equivalent to the one above:
  244. *
  245. * \code{.cpp}
  246. * UErrorCode status = U_ZERO_ERROR;
  247. * UnicodeString str((UChar*) u"p\u0430ypal"); // with U+0430 CYRILLIC SMALL LETTER A
  248. *
  249. * // Get the default set of allowable characters:
  250. * UnicodeSet allowed;
  251. * allowed.addAll(*uspoof_getRecommendedUnicodeSet(&status));
  252. * allowed.addAll(*uspoof_getInclusionUnicodeSet(&status));
  253. *
  254. * LocalUSpoofCheckerPointer sc(uspoof_open(&status));
  255. * uspoof_setAllowedChars(sc.getAlias(), allowed.toUSet(), &status);
  256. * uspoof_setRestrictionLevel(sc.getAlias(), USPOOF_MODERATELY_RESTRICTIVE);
  257. *
  258. * LocalUSpoofCheckResultPointer checkResult(uspoof_openCheckResult(&status));
  259. * int32_t bitmask = uspoof_check2UnicodeString(sc.getAlias(), str, checkResult.getAlias(), &status);
  260. *
  261. * int32_t failures1 = bitmask;
  262. * int32_t failures2 = uspoof_getCheckResultChecks(checkResult.getAlias(), &status);
  263. * assert(failures1 == failures2);
  264. * // checks that failed: 0x00000010 (status: U_ZERO_ERROR)
  265. * printf("checks that failed: %#010x (status: %s)\n", failures1, u_errorName(status));
  266. *
  267. * // Explicit cleanup not necessary.
  268. * \endcode
  269. *
  270. * <p>
  271. * The return value is a bitmask of the checks that failed. In this case, there was one check that failed:
  272. * {@link USPOOF_RESTRICTION_LEVEL}, corresponding to the fifth bit (16). The possible checks are:
  273. *
  274. * <ul>
  275. * <li><code>RESTRICTION_LEVEL</code>: flags strings that violate the
  276. * <a href="http://unicode.org/reports/tr39/#Restriction_Level_Detection">Restriction Level</a> test as specified in UTS
  277. * 39; in most cases, this means flagging strings that contain characters from multiple different scripts.</li>
  278. * <li><code>INVISIBLE</code>: flags strings that contain invisible characters, such as zero-width spaces, or character
  279. * sequences that are likely not to display, such as multiple occurrences of the same non-spacing mark.</li>
  280. * <li><code>CHAR_LIMIT</code>: flags strings that contain characters outside of a specified set of acceptable
  281. * characters. See {@link uspoof_setAllowedChars} and {@link uspoof_setAllowedLocales}.</li>
  282. * <li><code>MIXED_NUMBERS</code>: flags strings that contain digits from multiple different numbering systems.</li>
  283. * </ul>
  284. *
  285. * <p>
  286. * These checks can be enabled independently of each other. For example, if you were interested in checking for only the
  287. * INVISIBLE and MIXED_NUMBERS conditions, you could do:
  288. *
  289. * \code{.c}
  290. * UErrorCode status = U_ZERO_ERROR;
  291. * UChar* str = (UChar*) u"8\u09EA"; // 8 mixed with U+09EA BENGALI DIGIT FOUR
  292. *
  293. * USpoofChecker* sc = uspoof_open(&status);
  294. * uspoof_setChecks(sc, USPOOF_INVISIBLE | USPOOF_MIXED_NUMBERS, &status);
  295. *
  296. * int32_t bitmask = uspoof_check2(sc, str, -1, NULL, &status);
  297. * UBool result = bitmask != 0;
  298. * // fails checks: 1 (status: U_ZERO_ERROR)
  299. * printf("fails checks: %d (status: %s)\n", result, u_errorName(status));
  300. * uspoof_close(sc);
  301. * \endcode
  302. *
  303. * <p>
  304. * Here is an example in C++ showing how to compute the restriction level of a string:
  305. *
  306. * \code{.cpp}
  307. * UErrorCode status = U_ZERO_ERROR;
  308. * UnicodeString str((UChar*) u"p\u0430ypal"); // with U+0430 CYRILLIC SMALL LETTER A
  309. *
  310. * // Get the default set of allowable characters:
  311. * UnicodeSet allowed;
  312. * allowed.addAll(*uspoof_getRecommendedUnicodeSet(&status));
  313. * allowed.addAll(*uspoof_getInclusionUnicodeSet(&status));
  314. *
  315. * LocalUSpoofCheckerPointer sc(uspoof_open(&status));
  316. * uspoof_setAllowedChars(sc.getAlias(), allowed.toUSet(), &status);
  317. * uspoof_setRestrictionLevel(sc.getAlias(), USPOOF_MODERATELY_RESTRICTIVE);
  318. * uspoof_setChecks(sc.getAlias(), USPOOF_RESTRICTION_LEVEL | USPOOF_AUX_INFO, &status);
  319. *
  320. * LocalUSpoofCheckResultPointer checkResult(uspoof_openCheckResult(&status));
  321. * int32_t bitmask = uspoof_check2UnicodeString(sc.getAlias(), str, checkResult.getAlias(), &status);
  322. *
  323. * URestrictionLevel restrictionLevel = uspoof_getCheckResultRestrictionLevel(checkResult.getAlias(), &status);
  324. * // Since USPOOF_AUX_INFO was enabled, the restriction level is also available in the upper bits of the bitmask:
  325. * assert((restrictionLevel & bitmask) == restrictionLevel);
  326. * // Restriction level: 0x50000000 (status: U_ZERO_ERROR)
  327. * printf("Restriction level: %#010x (status: %s)\n", restrictionLevel, u_errorName(status));
  328. * \endcode
  329. *
  330. * <p>
  331. * The code '0x50000000' corresponds to the restriction level USPOOF_MINIMALLY_RESTRICTIVE. Since
  332. * USPOOF_MINIMALLY_RESTRICTIVE is weaker than USPOOF_MODERATELY_RESTRICTIVE, the string fails the check.
  333. *
  334. * <p>
  335. * <b>Note:</b> The Restriction Level is the most powerful of the checks. The full logic is documented in
  336. * <a href="http://unicode.org/reports/tr39/#Restriction_Level_Detection">UTS 39</a>, but the basic idea is that strings
  337. * are restricted to contain characters from only a single script, <em>except</em> that most scripts are allowed to have
  338. * Latin characters interspersed. Although the default restriction level is <code>HIGHLY_RESTRICTIVE</code>, it is
  339. * recommended that users set their restriction level to <code>MODERATELY_RESTRICTIVE</code>, which allows Latin mixed
  340. * with all other scripts except Cyrillic, Greek, and Cherokee, with which it is often confusable. For more details on
  341. * the levels, see UTS 39 or {@link URestrictionLevel}. The Restriction Level test is aware of the set of
  342. * allowed characters set in {@link uspoof_setAllowedChars}. Note that characters which have script code
  343. * COMMON or INHERITED, such as numbers and punctuation, are ignored when computing whether a string has multiple
  344. * scripts.
  345. *
  346. * <h2>Additional Information</h2>
  347. *
  348. * <p>
  349. * A <code>USpoofChecker</code> instance may be used repeatedly to perform checks on any number of identifiers.
  350. *
  351. * <p>
  352. * <b>Thread Safety:</b> The test functions for checking a single identifier, or for testing whether
  353. * two identifiers are possible confusable, are thread safe. They may called concurrently, from multiple threads,
  354. * using the same USpoofChecker instance.
  355. *
  356. * <p>
  357. * More generally, the standard ICU thread safety rules apply: functions that take a const USpoofChecker parameter are
  358. * thread safe. Those that take a non-const USpoofChecker are not thread safe..
  359. *
  360. * @stable ICU 4.6
  361. */
  362. struct USpoofChecker;
  363. typedef struct USpoofChecker USpoofChecker; /**< typedef for C of USpoofChecker */
  364. #ifndef U_HIDE_DRAFT_API
  365. /**
  366. * @see uspoof_openCheckResult
  367. */
  368. struct USpoofCheckResult;
  369. /**
  370. * @see uspoof_openCheckResult
  371. */
  372. typedef struct USpoofCheckResult USpoofCheckResult;
  373. #endif /* U_HIDE_DRAFT_API */
  374. /**
  375. * Enum for the kinds of checks that USpoofChecker can perform.
  376. * These enum values are used both to select the set of checks that
  377. * will be performed, and to report results from the check function.
  378. *
  379. * @stable ICU 4.2
  380. */
  381. typedef enum USpoofChecks {
  382. /**
  383. * When performing the two-string {@link uspoof_areConfusable} test, this flag in the return value indicates
  384. * that the two strings are visually confusable and that they are from the same script, according to UTS 39 section
  385. * 4.
  386. *
  387. * @see uspoof_areConfusable
  388. * @stable ICU 4.2
  389. */
  390. USPOOF_SINGLE_SCRIPT_CONFUSABLE = 1,
  391. /**
  392. * When performing the two-string {@link uspoof_areConfusable} test, this flag in the return value indicates
  393. * that the two strings are visually confusable and that they are <b>not</b> from the same script, according to UTS
  394. * 39 section 4.
  395. *
  396. * @see uspoof_areConfusable
  397. * @stable ICU 4.2
  398. */
  399. USPOOF_MIXED_SCRIPT_CONFUSABLE = 2,
  400. /**
  401. * When performing the two-string {@link uspoof_areConfusable} test, this flag in the return value indicates
  402. * that the two strings are visually confusable and that they are not from the same script but both of them are
  403. * single-script strings, according to UTS 39 section 4.
  404. *
  405. * @see uspoof_areConfusable
  406. * @stable ICU 4.2
  407. */
  408. USPOOF_WHOLE_SCRIPT_CONFUSABLE = 4,
  409. #ifndef U_HIDE_DRAFT_API
  410. /**
  411. * Enable this flag in {@link uspoof_setChecks} to turn on all types of confusables. You may set
  412. * the checks to some subset of SINGLE_SCRIPT_CONFUSABLE, MIXED_SCRIPT_CONFUSABLE, or WHOLE_SCRIPT_CONFUSABLE to
  413. * make {@link uspoof_areConfusable} return only those types of confusables.
  414. *
  415. * @see uspoof_areConfusable
  416. * @see uspoof_getSkeleton
  417. * @draft ICU 58
  418. */
  419. USPOOF_CONFUSABLE = USPOOF_SINGLE_SCRIPT_CONFUSABLE | USPOOF_MIXED_SCRIPT_CONFUSABLE | USPOOF_WHOLE_SCRIPT_CONFUSABLE,
  420. #endif /* U_HIDE_DRAFT_API */
  421. #ifndef U_HIDE_DEPRECATED_API
  422. /**
  423. * This flag is deprecated and no longer affects the behavior of SpoofChecker.
  424. *
  425. * @deprecated ICU 58 Any case confusable mappings were removed from UTS 39; the corresponding ICU API was deprecated.
  426. */
  427. USPOOF_ANY_CASE = 8,
  428. #endif /* U_HIDE_DEPRECATED_API */
  429. /**
  430. * Check that an identifier is no looser than the specified RestrictionLevel.
  431. * The default if {@link uspoof_setRestrictionLevel} is not called is HIGHLY_RESTRICTIVE.
  432. *
  433. * If USPOOF_AUX_INFO is enabled the actual restriction level of the
  434. * identifier being tested will also be returned by uspoof_check().
  435. *
  436. * @see URestrictionLevel
  437. * @see uspoof_setRestrictionLevel
  438. * @see USPOOF_AUX_INFO
  439. *
  440. * @stable ICU 51
  441. */
  442. USPOOF_RESTRICTION_LEVEL = 16,
  443. #ifndef U_HIDE_DEPRECATED_API
  444. /** Check that an identifier contains only characters from a
  445. * single script (plus chars from the common and inherited scripts.)
  446. * Applies to checks of a single identifier check only.
  447. * @deprecated ICU 51 Use RESTRICTION_LEVEL instead.
  448. */
  449. USPOOF_SINGLE_SCRIPT = USPOOF_RESTRICTION_LEVEL,
  450. #endif /* U_HIDE_DEPRECATED_API */
  451. /** Check an identifier for the presence of invisible characters,
  452. * such as zero-width spaces, or character sequences that are
  453. * likely not to display, such as multiple occurrences of the same
  454. * non-spacing mark. This check does not test the input string as a whole
  455. * for conformance to any particular syntax for identifiers.
  456. */
  457. USPOOF_INVISIBLE = 32,
  458. /** Check that an identifier contains only characters from a specified set
  459. * of acceptable characters. See {@link uspoof_setAllowedChars} and
  460. * {@link uspoof_setAllowedLocales}. Note that a string that fails this check
  461. * will also fail the {@link USPOOF_RESTRICTION_LEVEL} check.
  462. */
  463. USPOOF_CHAR_LIMIT = 64,
  464. /**
  465. * Check that an identifier does not mix numbers from different numbering systems.
  466. * For more information, see UTS 39 section 5.3.
  467. *
  468. * @stable ICU 51
  469. */
  470. USPOOF_MIXED_NUMBERS = 128,
  471. /**
  472. * Enable all spoof checks.
  473. *
  474. * @stable ICU 4.6
  475. */
  476. USPOOF_ALL_CHECKS = 0xFFFF,
  477. /**
  478. * Enable the return of auxillary (non-error) information in the
  479. * upper bits of the check results value.
  480. *
  481. * If this "check" is not enabled, the results of {@link uspoof_check} will be
  482. * zero when an identifier passes all of the enabled checks.
  483. *
  484. * If this "check" is enabled, (uspoof_check() & {@link USPOOF_ALL_CHECKS}) will
  485. * be zero when an identifier passes all checks.
  486. *
  487. * @stable ICU 51
  488. */
  489. USPOOF_AUX_INFO = 0x40000000
  490. } USpoofChecks;
  491. /**
  492. * Constants from UAX #39 for use in {@link uspoof_setRestrictionLevel}, and
  493. * for returned identifier restriction levels in check results.
  494. *
  495. * @stable ICU 51
  496. *
  497. * @see uspoof_setRestrictionLevel
  498. * @see uspoof_check
  499. */
  500. typedef enum URestrictionLevel {
  501. /**
  502. * All characters in the string are in the identifier profile and all characters in the string are in the
  503. * ASCII range.
  504. *
  505. * @stable ICU 51
  506. */
  507. USPOOF_ASCII = 0x10000000,
  508. /**
  509. * The string classifies as ASCII-Only, or all characters in the string are in the identifier profile and
  510. * the string is single-script, according to the definition in UTS 39 section 5.1.
  511. *
  512. * @stable ICU 53
  513. */
  514. USPOOF_SINGLE_SCRIPT_RESTRICTIVE = 0x20000000,
  515. /**
  516. * The string classifies as Single Script, or all characters in the string are in the identifier profile and
  517. * the string is covered by any of the following sets of scripts, according to the definition in UTS 39
  518. * section 5.1:
  519. * <ul>
  520. * <li>Latin + Han + Bopomofo (or equivalently: Latn + Hanb)</li>
  521. * <li>Latin + Han + Hiragana + Katakana (or equivalently: Latn + Jpan)</li>
  522. * <li>Latin + Han + Hangul (or equivalently: Latn +Kore)</li>
  523. * </ul>
  524. * This is the default restriction in ICU.
  525. *
  526. * @stable ICU 51
  527. */
  528. USPOOF_HIGHLY_RESTRICTIVE = 0x30000000,
  529. /**
  530. * The string classifies as Highly Restrictive, or all characters in the string are in the identifier profile
  531. * and the string is covered by Latin and any one other Recommended or Aspirational script, except Cyrillic,
  532. * Greek, and Cherokee.
  533. *
  534. * @stable ICU 51
  535. */
  536. USPOOF_MODERATELY_RESTRICTIVE = 0x40000000,
  537. /**
  538. * All characters in the string are in the identifier profile. Allow arbitrary mixtures of scripts.
  539. *
  540. * @stable ICU 51
  541. */
  542. USPOOF_MINIMALLY_RESTRICTIVE = 0x50000000,
  543. /**
  544. * Any valid identifiers, including characters outside of the Identifier Profile.
  545. *
  546. * @stable ICU 51
  547. */
  548. USPOOF_UNRESTRICTIVE = 0x60000000,
  549. /**
  550. * Mask for selecting the Restriction Level bits from the return value of {@link uspoof_check}.
  551. *
  552. * @stable ICU 53
  553. */
  554. USPOOF_RESTRICTION_LEVEL_MASK = 0x7F000000,
  555. #ifndef U_HIDE_INTERNAL_API
  556. /**
  557. * An undefined restriction level.
  558. * @internal
  559. */
  560. USPOOF_UNDEFINED_RESTRICTIVE = -1
  561. #endif /* U_HIDE_INTERNAL_API */
  562. } URestrictionLevel;
  563. /**
  564. * Create a Unicode Spoof Checker, configured to perform all
  565. * checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT.
  566. * Note that additional checks may be added in the future,
  567. * resulting in the changes to the default checking behavior.
  568. *
  569. * @param status The error code, set if this function encounters a problem.
  570. * @return the newly created Spoof Checker
  571. * @stable ICU 4.2
  572. */
  573. U_STABLE USpoofChecker * U_EXPORT2
  574. uspoof_open(UErrorCode *status);
  575. /**
  576. * Open a Spoof checker from its serialized form, stored in 32-bit-aligned memory.
  577. * Inverse of uspoof_serialize().
  578. * The memory containing the serialized data must remain valid and unchanged
  579. * as long as the spoof checker, or any cloned copies of the spoof checker,
  580. * are in use. Ownership of the memory remains with the caller.
  581. * The spoof checker (and any clones) must be closed prior to deleting the
  582. * serialized data.
  583. *
  584. * @param data a pointer to 32-bit-aligned memory containing the serialized form of spoof data
  585. * @param length the number of bytes available at data;
  586. * can be more than necessary
  587. * @param pActualLength receives the actual number of bytes at data taken up by the data;
  588. * can be NULL
  589. * @param pErrorCode ICU error code
  590. * @return the spoof checker.
  591. *
  592. * @see uspoof_open
  593. * @see uspoof_serialize
  594. * @stable ICU 4.2
  595. */
  596. U_STABLE USpoofChecker * U_EXPORT2
  597. uspoof_openFromSerialized(const void *data, int32_t length, int32_t *pActualLength,
  598. UErrorCode *pErrorCode);
  599. /**
  600. * Open a Spoof Checker from the source form of the spoof data.
  601. * The input corresponds to the Unicode data file confusables.txt
  602. * as described in Unicode UAX #39. The syntax of the source data
  603. * is as described in UAX #39 for this file, and the content of
  604. * this file is acceptable input.
  605. *
  606. * The character encoding of the (char *) input text is UTF-8.
  607. *
  608. * @param confusables a pointer to the confusable characters definitions,
  609. * as found in file confusables.txt from unicode.org.
  610. * @param confusablesLen The length of the confusables text, or -1 if the
  611. * input string is zero terminated.
  612. * @param confusablesWholeScript
  613. * Deprecated in ICU 58. No longer used.
  614. * @param confusablesWholeScriptLen
  615. * Deprecated in ICU 58. No longer used.
  616. * @param errType In the event of an error in the input, indicates
  617. * which of the input files contains the error.
  618. * The value is one of USPOOF_SINGLE_SCRIPT_CONFUSABLE or
  619. * USPOOF_WHOLE_SCRIPT_CONFUSABLE, or
  620. * zero if no errors are found.
  621. * @param pe In the event of an error in the input, receives the position
  622. * in the input text (line, offset) of the error.
  623. * @param status an in/out ICU UErrorCode. Among the possible errors is
  624. * U_PARSE_ERROR, which is used to report syntax errors
  625. * in the input.
  626. * @return A spoof checker that uses the rules from the input files.
  627. * @stable ICU 4.2
  628. */
  629. U_STABLE USpoofChecker * U_EXPORT2
  630. uspoof_openFromSource(const char *confusables, int32_t confusablesLen,
  631. const char *confusablesWholeScript, int32_t confusablesWholeScriptLen,
  632. int32_t *errType, UParseError *pe, UErrorCode *status);
  633. /**
  634. * Close a Spoof Checker, freeing any memory that was being held by
  635. * its implementation.
  636. * @stable ICU 4.2
  637. */
  638. U_STABLE void U_EXPORT2
  639. uspoof_close(USpoofChecker *sc);
  640. #if U_SHOW_CPLUSPLUS_API
  641. U_NAMESPACE_BEGIN
  642. /**
  643. * \class LocalUSpoofCheckerPointer
  644. * "Smart pointer" class, closes a USpoofChecker via uspoof_close().
  645. * For most methods see the LocalPointerBase base class.
  646. *
  647. * @see LocalPointerBase
  648. * @see LocalPointer
  649. * @stable ICU 4.4
  650. */
  651. U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckerPointer, USpoofChecker, uspoof_close);
  652. U_NAMESPACE_END
  653. #endif
  654. /**
  655. * Clone a Spoof Checker. The clone will be set to perform the same checks
  656. * as the original source.
  657. *
  658. * @param sc The source USpoofChecker
  659. * @param status The error code, set if this function encounters a problem.
  660. * @return
  661. * @stable ICU 4.2
  662. */
  663. U_STABLE USpoofChecker * U_EXPORT2
  664. uspoof_clone(const USpoofChecker *sc, UErrorCode *status);
  665. /**
  666. * Specify the bitmask of checks that will be performed by {@link uspoof_check}. Calling this method
  667. * overwrites any checks that may have already been enabled. By default, all checks are enabled.
  668. *
  669. * To enable specific checks and disable all others, the "whitelisted" checks should be ORed together. For
  670. * example, to fail strings containing characters outside of the set specified by {@link uspoof_setAllowedChars} and
  671. * also strings that contain digits from mixed numbering systems:
  672. *
  673. * <pre>
  674. * {@code
  675. * uspoof_setChecks(USPOOF_CHAR_LIMIT | USPOOF_MIXED_NUMBERS);
  676. * }
  677. * </pre>
  678. *
  679. * To disable specific checks and enable all others, the "blacklisted" checks should be ANDed away from
  680. * ALL_CHECKS. For example, if you are not planning to use the {@link uspoof_areConfusable} functionality,
  681. * it is good practice to disable the CONFUSABLE check:
  682. *
  683. * <pre>
  684. * {@code
  685. * uspoof_setChecks(USPOOF_ALL_CHECKS & ~USPOOF_CONFUSABLE);
  686. * }
  687. * </pre>
  688. *
  689. * Note that methods such as {@link uspoof_setAllowedChars}, {@link uspoof_setAllowedLocales}, and
  690. * {@link uspoof_setRestrictionLevel} will enable certain checks when called. Those methods will OR the check they
  691. * enable onto the existing bitmask specified by this method. For more details, see the documentation of those
  692. * methods.
  693. *
  694. * @param sc The USpoofChecker
  695. * @param checks The set of checks that this spoof checker will perform.
  696. * The value is a bit set, obtained by OR-ing together
  697. * values from enum USpoofChecks.
  698. * @param status The error code, set if this function encounters a problem.
  699. * @stable ICU 4.2
  700. *
  701. */
  702. U_STABLE void U_EXPORT2
  703. uspoof_setChecks(USpoofChecker *sc, int32_t checks, UErrorCode *status);
  704. /**
  705. * Get the set of checks that this Spoof Checker has been configured to perform.
  706. *
  707. * @param sc The USpoofChecker
  708. * @param status The error code, set if this function encounters a problem.
  709. * @return The set of checks that this spoof checker will perform.
  710. * The value is a bit set, obtained by OR-ing together
  711. * values from enum USpoofChecks.
  712. * @stable ICU 4.2
  713. *
  714. */
  715. U_STABLE int32_t U_EXPORT2
  716. uspoof_getChecks(const USpoofChecker *sc, UErrorCode *status);
  717. /**
  718. * Set the loosest restriction level allowed for strings. The default if this is not called is
  719. * {@link USPOOF_HIGHLY_RESTRICTIVE}. Calling this method enables the {@link USPOOF_RESTRICTION_LEVEL} and
  720. * {@link USPOOF_MIXED_NUMBERS} checks, corresponding to Sections 5.1 and 5.2 of UTS 39. To customize which checks are
  721. * to be performed by {@link uspoof_check}, see {@link uspoof_setChecks}.
  722. *
  723. * @param sc The USpoofChecker
  724. * @param restrictionLevel The loosest restriction level allowed.
  725. * @see URestrictionLevel
  726. * @stable ICU 51
  727. */
  728. U_STABLE void U_EXPORT2
  729. uspoof_setRestrictionLevel(USpoofChecker *sc, URestrictionLevel restrictionLevel);
  730. /**
  731. * Get the Restriction Level that will be tested if the checks include {@link USPOOF_RESTRICTION_LEVEL}.
  732. *
  733. * @return The restriction level
  734. * @see URestrictionLevel
  735. * @stable ICU 51
  736. */
  737. U_STABLE URestrictionLevel U_EXPORT2
  738. uspoof_getRestrictionLevel(const USpoofChecker *sc);
  739. /**
  740. * Limit characters that are acceptable in identifiers being checked to those
  741. * normally used with the languages associated with the specified locales.
  742. * Any previously specified list of locales is replaced by the new settings.
  743. *
  744. * A set of languages is determined from the locale(s), and
  745. * from those a set of acceptable Unicode scripts is determined.
  746. * Characters from this set of scripts, along with characters from
  747. * the "common" and "inherited" Unicode Script categories
  748. * will be permitted.
  749. *
  750. * Supplying an empty string removes all restrictions;
  751. * characters from any script will be allowed.
  752. *
  753. * The {@link USPOOF_CHAR_LIMIT} test is automatically enabled for this
  754. * USpoofChecker when calling this function with a non-empty list
  755. * of locales.
  756. *
  757. * The Unicode Set of characters that will be allowed is accessible
  758. * via the uspoof_getAllowedChars() function. uspoof_setAllowedLocales()
  759. * will <i>replace</i> any previously applied set of allowed characters.
  760. *
  761. * Adjustments, such as additions or deletions of certain classes of characters,
  762. * can be made to the result of uspoof_setAllowedLocales() by
  763. * fetching the resulting set with uspoof_getAllowedChars(),
  764. * manipulating it with the Unicode Set API, then resetting the
  765. * spoof detectors limits with uspoof_setAllowedChars().
  766. *
  767. * @param sc The USpoofChecker
  768. * @param localesList A list list of locales, from which the language
  769. * and associated script are extracted. The locales
  770. * are comma-separated if there is more than one.
  771. * White space may not appear within an individual locale,
  772. * but is ignored otherwise.
  773. * The locales are syntactically like those from the
  774. * HTTP Accept-Language header.
  775. * If the localesList is empty, no restrictions will be placed on
  776. * the allowed characters.
  777. *
  778. * @param status The error code, set if this function encounters a problem.
  779. * @stable ICU 4.2
  780. */
  781. U_STABLE void U_EXPORT2
  782. uspoof_setAllowedLocales(USpoofChecker *sc, const char *localesList, UErrorCode *status);
  783. /**
  784. * Get a list of locales for the scripts that are acceptable in strings
  785. * to be checked. If no limitations on scripts have been specified,
  786. * an empty string will be returned.
  787. *
  788. * uspoof_setAllowedChars() will reset the list of allowed to be empty.
  789. *
  790. * The format of the returned list is the same as that supplied to
  791. * uspoof_setAllowedLocales(), but returned list may not be identical
  792. * to the originally specified string; the string may be reformatted,
  793. * and information other than languages from
  794. * the originally specified locales may be omitted.
  795. *
  796. * @param sc The USpoofChecker
  797. * @param status The error code, set if this function encounters a problem.
  798. * @return A string containing a list of locales corresponding
  799. * to the acceptable scripts, formatted like an
  800. * HTTP Accept Language value.
  801. *
  802. * @stable ICU 4.2
  803. */
  804. U_STABLE const char * U_EXPORT2
  805. uspoof_getAllowedLocales(USpoofChecker *sc, UErrorCode *status);
  806. /**
  807. * Limit the acceptable characters to those specified by a Unicode Set.
  808. * Any previously specified character limit is
  809. * is replaced by the new settings. This includes limits on
  810. * characters that were set with the uspoof_setAllowedLocales() function.
  811. *
  812. * The USPOOF_CHAR_LIMIT test is automatically enabled for this
  813. * USpoofChecker by this function.
  814. *
  815. * @param sc The USpoofChecker
  816. * @param chars A Unicode Set containing the list of
  817. * characters that are permitted. Ownership of the set
  818. * remains with the caller. The incoming set is cloned by
  819. * this function, so there are no restrictions on modifying
  820. * or deleting the USet after calling this function.
  821. * @param status The error code, set if this function encounters a problem.
  822. * @stable ICU 4.2
  823. */
  824. U_STABLE void U_EXPORT2
  825. uspoof_setAllowedChars(USpoofChecker *sc, const USet *chars, UErrorCode *status);
  826. /**
  827. * Get a USet for the characters permitted in an identifier.
  828. * This corresponds to the limits imposed by the Set Allowed Characters
  829. * functions. Limitations imposed by other checks will not be
  830. * reflected in the set returned by this function.
  831. *
  832. * The returned set will be frozen, meaning that it cannot be modified
  833. * by the caller.
  834. *
  835. * Ownership of the returned set remains with the Spoof Detector. The
  836. * returned set will become invalid if the spoof detector is closed,
  837. * or if a new set of allowed characters is specified.
  838. *
  839. *
  840. * @param sc The USpoofChecker
  841. * @param status The error code, set if this function encounters a problem.
  842. * @return A USet containing the characters that are permitted by
  843. * the USPOOF_CHAR_LIMIT test.
  844. * @stable ICU 4.2
  845. */
  846. U_STABLE const USet * U_EXPORT2
  847. uspoof_getAllowedChars(const USpoofChecker *sc, UErrorCode *status);
  848. #if U_SHOW_CPLUSPLUS_API
  849. /**
  850. * Limit the acceptable characters to those specified by a Unicode Set.
  851. * Any previously specified character limit is
  852. * is replaced by the new settings. This includes limits on
  853. * characters that were set with the uspoof_setAllowedLocales() function.
  854. *
  855. * The USPOOF_CHAR_LIMIT test is automatically enabled for this
  856. * USoofChecker by this function.
  857. *
  858. * @param sc The USpoofChecker
  859. * @param chars A Unicode Set containing the list of
  860. * characters that are permitted. Ownership of the set
  861. * remains with the caller. The incoming set is cloned by
  862. * this function, so there are no restrictions on modifying
  863. * or deleting the UnicodeSet after calling this function.
  864. * @param status The error code, set if this function encounters a problem.
  865. * @stable ICU 4.2
  866. */
  867. U_STABLE void U_EXPORT2
  868. uspoof_setAllowedUnicodeSet(USpoofChecker *sc, const icu::UnicodeSet *chars, UErrorCode *status);
  869. /**
  870. * Get a UnicodeSet for the characters permitted in an identifier.
  871. * This corresponds to the limits imposed by the Set Allowed Characters /
  872. * UnicodeSet functions. Limitations imposed by other checks will not be
  873. * reflected in the set returned by this function.
  874. *
  875. * The returned set will be frozen, meaning that it cannot be modified
  876. * by the caller.
  877. *
  878. * Ownership of the returned set remains with the Spoof Detector. The
  879. * returned set will become invalid if the spoof detector is closed,
  880. * or if a new set of allowed characters is specified.
  881. *
  882. *
  883. * @param sc The USpoofChecker
  884. * @param status The error code, set if this function encounters a problem.
  885. * @return A UnicodeSet containing the characters that are permitted by
  886. * the USPOOF_CHAR_LIMIT test.
  887. * @stable ICU 4.2
  888. */
  889. U_STABLE const icu::UnicodeSet * U_EXPORT2
  890. uspoof_getAllowedUnicodeSet(const USpoofChecker *sc, UErrorCode *status);
  891. #endif
  892. /**
  893. * Check the specified string for possible security issues.
  894. * The text to be checked will typically be an identifier of some sort.
  895. * The set of checks to be performed is specified with uspoof_setChecks().
  896. *
  897. * \note
  898. * Consider using the newer API, {@link uspoof_check2}, instead.
  899. * The newer API exposes additional information from the check procedure
  900. * and is otherwise identical to this method.
  901. *
  902. * @param sc The USpoofChecker
  903. * @param id The identifier to be checked for possible security issues,
  904. * in UTF-16 format.
  905. * @param length the length of the string to be checked, expressed in
  906. * 16 bit UTF-16 code units, or -1 if the string is
  907. * zero terminated.
  908. * @param position Deprecated in ICU 51. Always returns zero.
  909. * Originally, an out parameter for the index of the first
  910. * string position that failed a check.
  911. * This parameter may be NULL.
  912. * @param status The error code, set if an error occurred while attempting to
  913. * perform the check.
  914. * Spoofing or security issues detected with the input string are
  915. * not reported here, but through the function's return value.
  916. * @return An integer value with bits set for any potential security
  917. * or spoofing issues detected. The bits are defined by
  918. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  919. * will be zero if the input string passes all of the
  920. * enabled checks.
  921. * @see uspoof_check2
  922. * @stable ICU 4.2
  923. */
  924. U_STABLE int32_t U_EXPORT2
  925. uspoof_check(const USpoofChecker *sc,
  926. const UChar *id, int32_t length,
  927. int32_t *position,
  928. UErrorCode *status);
  929. /**
  930. * Check the specified string for possible security issues.
  931. * The text to be checked will typically be an identifier of some sort.
  932. * The set of checks to be performed is specified with uspoof_setChecks().
  933. *
  934. * \note
  935. * Consider using the newer API, {@link uspoof_check2UTF8}, instead.
  936. * The newer API exposes additional information from the check procedure
  937. * and is otherwise identical to this method.
  938. *
  939. * @param sc The USpoofChecker
  940. * @param id A identifier to be checked for possible security issues, in UTF8 format.
  941. * @param length the length of the string to be checked, or -1 if the string is
  942. * zero terminated.
  943. * @param position Deprecated in ICU 51. Always returns zero.
  944. * Originally, an out parameter for the index of the first
  945. * string position that failed a check.
  946. * This parameter may be NULL.
  947. * @param status The error code, set if an error occurred while attempting to
  948. * perform the check.
  949. * Spoofing or security issues detected with the input string are
  950. * not reported here, but through the function's return value.
  951. * If the input contains invalid UTF-8 sequences,
  952. * a status of U_INVALID_CHAR_FOUND will be returned.
  953. * @return An integer value with bits set for any potential security
  954. * or spoofing issues detected. The bits are defined by
  955. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  956. * will be zero if the input string passes all of the
  957. * enabled checks.
  958. * @see uspoof_check2UTF8
  959. * @stable ICU 4.2
  960. */
  961. U_STABLE int32_t U_EXPORT2
  962. uspoof_checkUTF8(const USpoofChecker *sc,
  963. const char *id, int32_t length,
  964. int32_t *position,
  965. UErrorCode *status);
  966. #if U_SHOW_CPLUSPLUS_API
  967. /**
  968. * Check the specified string for possible security issues.
  969. * The text to be checked will typically be an identifier of some sort.
  970. * The set of checks to be performed is specified with uspoof_setChecks().
  971. *
  972. * \note
  973. * Consider using the newer API, {@link uspoof_check2UnicodeString}, instead.
  974. * The newer API exposes additional information from the check procedure
  975. * and is otherwise identical to this method.
  976. *
  977. * @param sc The USpoofChecker
  978. * @param id A identifier to be checked for possible security issues.
  979. * @param position Deprecated in ICU 51. Always returns zero.
  980. * Originally, an out parameter for the index of the first
  981. * string position that failed a check.
  982. * This parameter may be NULL.
  983. * @param status The error code, set if an error occurred while attempting to
  984. * perform the check.
  985. * Spoofing or security issues detected with the input string are
  986. * not reported here, but through the function's return value.
  987. * @return An integer value with bits set for any potential security
  988. * or spoofing issues detected. The bits are defined by
  989. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  990. * will be zero if the input string passes all of the
  991. * enabled checks.
  992. * @see uspoof_check2UnicodeString
  993. * @stable ICU 4.2
  994. */
  995. U_STABLE int32_t U_EXPORT2
  996. uspoof_checkUnicodeString(const USpoofChecker *sc,
  997. const icu::UnicodeString &id,
  998. int32_t *position,
  999. UErrorCode *status);
  1000. #endif
  1001. #ifndef U_HIDE_DRAFT_API
  1002. /**
  1003. * Check the specified string for possible security issues.
  1004. * The text to be checked will typically be an identifier of some sort.
  1005. * The set of checks to be performed is specified with uspoof_setChecks().
  1006. *
  1007. * @param sc The USpoofChecker
  1008. * @param id The identifier to be checked for possible security issues,
  1009. * in UTF-16 format.
  1010. * @param length the length of the string to be checked, or -1 if the string is
  1011. * zero terminated.
  1012. * @param checkResult An instance of USpoofCheckResult to be filled with
  1013. * details about the identifier. Can be NULL.
  1014. * @param status The error code, set if an error occurred while attempting to
  1015. * perform the check.
  1016. * Spoofing or security issues detected with the input string are
  1017. * not reported here, but through the function's return value.
  1018. * @return An integer value with bits set for any potential security
  1019. * or spoofing issues detected. The bits are defined by
  1020. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  1021. * will be zero if the input string passes all of the
  1022. * enabled checks. Any information in this bitmask will be
  1023. * consistent with the information saved in the optional
  1024. * checkResult parameter.
  1025. * @see uspoof_openCheckResult
  1026. * @see uspoof_check2UTF8
  1027. * @see uspoof_check2UnicodeString
  1028. * @draft ICU 58
  1029. */
  1030. U_DRAFT int32_t U_EXPORT2
  1031. uspoof_check2(const USpoofChecker *sc,
  1032. const UChar* id, int32_t length,
  1033. USpoofCheckResult* checkResult,
  1034. UErrorCode *status);
  1035. /**
  1036. * Check the specified string for possible security issues.
  1037. * The text to be checked will typically be an identifier of some sort.
  1038. * The set of checks to be performed is specified with uspoof_setChecks().
  1039. *
  1040. * This version of {@link uspoof_check} accepts a USpoofCheckResult, which
  1041. * returns additional information about the identifier. For more
  1042. * information, see {@link uspoof_openCheckResult}.
  1043. *
  1044. * @param sc The USpoofChecker
  1045. * @param id A identifier to be checked for possible security issues, in UTF8 format.
  1046. * @param length the length of the string to be checked, or -1 if the string is
  1047. * zero terminated.
  1048. * @param checkResult An instance of USpoofCheckResult to be filled with
  1049. * details about the identifier. Can be NULL.
  1050. * @param status The error code, set if an error occurred while attempting to
  1051. * perform the check.
  1052. * Spoofing or security issues detected with the input string are
  1053. * not reported here, but through the function's return value.
  1054. * @return An integer value with bits set for any potential security
  1055. * or spoofing issues detected. The bits are defined by
  1056. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  1057. * will be zero if the input string passes all of the
  1058. * enabled checks. Any information in this bitmask will be
  1059. * consistent with the information saved in the optional
  1060. * checkResult parameter.
  1061. * @see uspoof_openCheckResult
  1062. * @see uspoof_check2
  1063. * @see uspoof_check2UnicodeString
  1064. * @draft ICU 58
  1065. */
  1066. U_DRAFT int32_t U_EXPORT2
  1067. uspoof_check2UTF8(const USpoofChecker *sc,
  1068. const char *id, int32_t length,
  1069. USpoofCheckResult* checkResult,
  1070. UErrorCode *status);
  1071. #if U_SHOW_CPLUSPLUS_API
  1072. /**
  1073. * Check the specified string for possible security issues.
  1074. * The text to be checked will typically be an identifier of some sort.
  1075. * The set of checks to be performed is specified with uspoof_setChecks().
  1076. *
  1077. * @param sc The USpoofChecker
  1078. * @param id A identifier to be checked for possible security issues.
  1079. * @param checkResult An instance of USpoofCheckResult to be filled with
  1080. * details about the identifier. Can be NULL.
  1081. * @param status The error code, set if an error occurred while attempting to
  1082. * perform the check.
  1083. * Spoofing or security issues detected with the input string are
  1084. * not reported here, but through the function's return value.
  1085. * @return An integer value with bits set for any potential security
  1086. * or spoofing issues detected. The bits are defined by
  1087. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  1088. * will be zero if the input string passes all of the
  1089. * enabled checks. Any information in this bitmask will be
  1090. * consistent with the information saved in the optional
  1091. * checkResult parameter.
  1092. * @see uspoof_openCheckResult
  1093. * @see uspoof_check2
  1094. * @see uspoof_check2UTF8
  1095. * @draft ICU 58
  1096. */
  1097. U_DRAFT int32_t U_EXPORT2
  1098. uspoof_check2UnicodeString(const USpoofChecker *sc,
  1099. const icu::UnicodeString &id,
  1100. USpoofCheckResult* checkResult,
  1101. UErrorCode *status);
  1102. #endif
  1103. /**
  1104. * Create a USpoofCheckResult, used by the {@link uspoof_check2} class of functions to return
  1105. * information about the identifier. Information includes:
  1106. * <ul>
  1107. * <li>A bitmask of the checks that failed</li>
  1108. * <li>The identifier's restriction level (UTS 39 section 5.2)</li>
  1109. * <li>The set of numerics in the string (UTS 39 section 5.3)</li>
  1110. * </ul>
  1111. * The data held in a USpoofCheckResult is cleared whenever it is passed into a new call
  1112. * of {@link uspoof_check2}.
  1113. *
  1114. * @param status The error code, set if this function encounters a problem.
  1115. * @return the newly created USpoofCheckResult
  1116. * @see uspoof_check2
  1117. * @see uspoof_check2UTF8
  1118. * @see uspoof_check2UnicodeString
  1119. * @draft ICU 58
  1120. */
  1121. U_DRAFT USpoofCheckResult* U_EXPORT2
  1122. uspoof_openCheckResult(UErrorCode *status);
  1123. /**
  1124. * Close a USpoofCheckResult, freeing any memory that was being held by
  1125. * its implementation.
  1126. *
  1127. * @param checkResult The instance of USpoofCheckResult to close
  1128. * @draft ICU 58
  1129. */
  1130. U_DRAFT void U_EXPORT2
  1131. uspoof_closeCheckResult(USpoofCheckResult *checkResult);
  1132. #if U_SHOW_CPLUSPLUS_API
  1133. U_NAMESPACE_BEGIN
  1134. /**
  1135. * \class LocalUSpoofCheckResultPointer
  1136. * "Smart pointer" class, closes a USpoofCheckResult via {@link uspoof_closeCheckResult}.
  1137. * For most methods see the LocalPointerBase base class.
  1138. *
  1139. * @see LocalPointerBase
  1140. * @see LocalPointer
  1141. * @draft ICU 58
  1142. */
  1143. U_DEFINE_LOCAL_OPEN_POINTER(LocalUSpoofCheckResultPointer, USpoofCheckResult, uspoof_closeCheckResult);
  1144. U_NAMESPACE_END
  1145. #endif
  1146. /**
  1147. * Indicates which of the spoof check(s) have failed. The value is a bitwise OR of the constants for the tests
  1148. * in question: USPOOF_RESTRICTION_LEVEL, USPOOF_CHAR_LIMIT, and so on.
  1149. *
  1150. * @param checkResult The instance of USpoofCheckResult created by {@link uspoof_openCheckResult}
  1151. * @param status The error code, set if an error occurred.
  1152. * @return An integer value with bits set for any potential security
  1153. * or spoofing issues detected. The bits are defined by
  1154. * enum USpoofChecks. (returned_value & USPOOF_ALL_CHECKS)
  1155. * will be zero if the input string passes all of the
  1156. * enabled checks.
  1157. * @see uspoof_setChecks
  1158. * @draft ICU 58
  1159. */
  1160. U_DRAFT int32_t U_EXPORT2
  1161. uspoof_getCheckResultChecks(const USpoofCheckResult *checkResult, UErrorCode *status);
  1162. /**
  1163. * Gets the restriction level that the text meets, if the USPOOF_RESTRICTION_LEVEL check
  1164. * was enabled; otherwise, undefined.
  1165. *
  1166. * @param checkResult The instance of USpoofCheckResult created by {@link uspoof_openCheckResult}
  1167. * @param status The error code, set if an error occurred.
  1168. * @return The restriction level contained in the USpoofCheckResult
  1169. * @see uspoof_setRestrictionLevel
  1170. * @draft ICU 58
  1171. */
  1172. U_DRAFT URestrictionLevel U_EXPORT2
  1173. uspoof_getCheckResultRestrictionLevel(const USpoofCheckResult *checkResult, UErrorCode *status);
  1174. /**
  1175. * Gets the set of numerics found in the string, if the USPOOF_MIXED_NUMBERS check was enabled;
  1176. * otherwise, undefined. The set will contain the zero digit from each decimal number system found
  1177. * in the input string. Ownership of the returned USet remains with the USpoofCheckResult.
  1178. * The USet will be free'd when {@link uspoof_closeCheckResult} is called.
  1179. *
  1180. * @param checkResult The instance of USpoofCheckResult created by {@link uspoof_openCheckResult}
  1181. * @return The set of numerics contained in the USpoofCheckResult
  1182. * @param status The error code, set if an error occurred.
  1183. * @draft ICU 58
  1184. */
  1185. U_DRAFT const USet* U_EXPORT2
  1186. uspoof_getCheckResultNumerics(const USpoofCheckResult *checkResult, UErrorCode *status);
  1187. #endif /* U_HIDE_DRAFT_API */
  1188. /**
  1189. * Check the whether two specified strings are visually confusable.
  1190. *
  1191. * If the strings are confusable, the return value will be nonzero, as long as
  1192. * {@link USPOOF_CONFUSABLE} was enabled in uspoof_setChecks().
  1193. *
  1194. * The bits in the return value correspond to flags for each of the classes of
  1195. * confusables applicable to the two input strings. According to UTS 39
  1196. * section 4, the possible flags are:
  1197. *
  1198. * <ul>
  1199. * <li>{@link USPOOF_SINGLE_SCRIPT_CONFUSABLE}</li>
  1200. * <li>{@link USPOOF_MIXED_SCRIPT_CONFUSABLE}</li>
  1201. * <li>{@link USPOOF_WHOLE_SCRIPT_CONFUSABLE}</li>
  1202. * </ul>
  1203. *
  1204. * If one or more of the above flags were not listed in uspoof_setChecks(), this
  1205. * function will never report that class of confusable. The check
  1206. * {@link USPOOF_CONFUSABLE} enables all three flags.
  1207. *
  1208. *
  1209. * @param sc The USpoofChecker
  1210. * @param id1 The first of the two identifiers to be compared for
  1211. * confusability. The strings are in UTF-16 format.
  1212. * @param length1 the length of the first identifer, expressed in
  1213. * 16 bit UTF-16 code units, or -1 if the string is
  1214. * nul terminated.
  1215. * @param id2 The second of the two identifiers to be compared for
  1216. * confusability. The identifiers are in UTF-16 format.
  1217. * @param length2 The length of the second identifiers, expressed in
  1218. * 16 bit UTF-16 code units, or -1 if the string is
  1219. * nul terminated.
  1220. * @param status The error code, set if an error occurred while attempting to
  1221. * perform the check.
  1222. * Confusability of the identifiers is not reported here,
  1223. * but through this function's return value.
  1224. * @return An integer value with bit(s) set corresponding to
  1225. * the type of confusability found, as defined by
  1226. * enum USpoofChecks. Zero is returned if the identifiers
  1227. * are not confusable.
  1228. *
  1229. * @stable ICU 4.2
  1230. */
  1231. U_STABLE int32_t U_EXPORT2
  1232. uspoof_areConfusable(const USpoofChecker *sc,
  1233. const UChar *id1, int32_t length1,
  1234. const UChar *id2, int32_t length2,
  1235. UErrorCode *status);
  1236. /**
  1237. * A version of {@link uspoof_areConfusable} accepting strings in UTF-8 format.
  1238. *
  1239. * @param sc The USpoofChecker
  1240. * @param id1 The first of the two identifiers to be compared for
  1241. * confusability. The strings are in UTF-8 format.
  1242. * @param length1 the length of the first identifiers, in bytes, or -1
  1243. * if the string is nul terminated.
  1244. * @param id2 The second of the two identifiers to be compared for
  1245. * confusability. The strings are in UTF-8 format.
  1246. * @param length2 The length of the second string in bytes, or -1
  1247. * if the string is nul terminated.
  1248. * @param status The error code, set if an error occurred while attempting to
  1249. * perform the check.
  1250. * Confusability of the strings is not reported here,
  1251. * but through this function's return value.
  1252. * @return An integer value with bit(s) set corresponding to
  1253. * the type of confusability found, as defined by
  1254. * enum USpoofChecks. Zero is returned if the strings
  1255. * are not confusable.
  1256. *
  1257. * @stable ICU 4.2
  1258. *
  1259. * @see uspoof_areConfusable
  1260. */
  1261. U_STABLE int32_t U_EXPORT2
  1262. uspoof_areConfusableUTF8(const USpoofChecker *sc,
  1263. const char *id1, int32_t length1,
  1264. const char *id2, int32_t length2,
  1265. UErrorCode *status);
  1266. #if U_SHOW_CPLUSPLUS_API
  1267. /**
  1268. * A version of {@link uspoof_areConfusable} accepting UnicodeStrings.
  1269. *
  1270. * @param sc The USpoofChecker
  1271. * @param s1 The first of the two identifiers to be compared for
  1272. * confusability. The strings are in UTF-8 format.
  1273. * @param s2 The second of the two identifiers to be compared for
  1274. * confusability. The strings are in UTF-8 format.
  1275. * @param status The error code, set if an error occurred while attempting to
  1276. * perform the check.
  1277. * Confusability of the identifiers is not reported here,
  1278. * but through this function's return value.
  1279. * @return An integer value with bit(s) set corresponding to
  1280. * the type of confusability found, as defined by
  1281. * enum USpoofChecks. Zero is returned if the identifiers
  1282. * are not confusable.
  1283. *
  1284. * @stable ICU 4.2
  1285. *
  1286. * @see uspoof_areConfusable
  1287. */
  1288. U_STABLE int32_t U_EXPORT2
  1289. uspoof_areConfusableUnicodeString(const USpoofChecker *sc,
  1290. const icu::UnicodeString &s1,
  1291. const icu::UnicodeString &s2,
  1292. UErrorCode *status);
  1293. #endif
  1294. /**
  1295. * Get the "skeleton" for an identifier.
  1296. * Skeletons are a transformation of the input identifier;
  1297. * Two identifiers are confusable if their skeletons are identical.
  1298. * See Unicode UAX #39 for additional information.
  1299. *
  1300. * Using skeletons directly makes it possible to quickly check
  1301. * whether an identifier is confusable with any of some large
  1302. * set of existing identifiers, by creating an efficiently
  1303. * searchable collection of the skeletons.
  1304. *
  1305. * @param sc The USpoofChecker
  1306. * @param type Deprecated in ICU 58. You may pass any number.
  1307. * Originally, controlled which of the Unicode confusable data
  1308. * tables to use.
  1309. * @param id The input identifier whose skeleton will be computed.
  1310. * @param length The length of the input identifier, expressed in 16 bit
  1311. * UTF-16 code units, or -1 if the string is zero terminated.
  1312. * @param dest The output buffer, to receive the skeleton string.
  1313. * @param destCapacity The length of the output buffer, in 16 bit units.
  1314. * The destCapacity may be zero, in which case the function will
  1315. * return the actual length of the skeleton.
  1316. * @param status The error code, set if an error occurred while attempting to
  1317. * perform the check.
  1318. * @return The length of the skeleton string. The returned length
  1319. * is always that of the complete skeleton, even when the
  1320. * supplied buffer is too small (or of zero length)
  1321. *
  1322. * @stable ICU 4.2
  1323. * @see uspoof_areConfusable
  1324. */
  1325. U_STABLE int32_t U_EXPORT2
  1326. uspoof_getSkeleton(const USpoofChecker *sc,
  1327. uint32_t type,
  1328. const UChar *id, int32_t length,
  1329. UChar *dest, int32_t destCapacity,
  1330. UErrorCode *status);
  1331. /**
  1332. * Get the "skeleton" for an identifier.
  1333. * Skeletons are a transformation of the input identifier;
  1334. * Two identifiers are confusable if their skeletons are identical.
  1335. * See Unicode UAX #39 for additional information.
  1336. *
  1337. * Using skeletons directly makes it possible to quickly check
  1338. * whether an identifier is confusable with any of some large
  1339. * set of existing identifiers, by creating an efficiently
  1340. * searchable collection of the skeletons.
  1341. *
  1342. * @param sc The USpoofChecker
  1343. * @param type Deprecated in ICU 58. You may pass any number.
  1344. * Originally, controlled which of the Unicode confusable data
  1345. * tables to use.
  1346. * @param id The UTF-8 format identifier whose skeleton will be computed.
  1347. * @param length The length of the input string, in bytes,
  1348. * or -1 if the string is zero terminated.
  1349. * @param dest The output buffer, to receive the skeleton string.
  1350. * @param destCapacity The length of the output buffer, in bytes.
  1351. * The destCapacity may be zero, in which case the function will
  1352. * return the actual length of the skeleton.
  1353. * @param status The error code, set if an error occurred while attempting to
  1354. * perform the check. Possible Errors include U_INVALID_CHAR_FOUND
  1355. * for invalid UTF-8 sequences, and
  1356. * U_BUFFER_OVERFLOW_ERROR if the destination buffer is too small
  1357. * to hold the complete skeleton.
  1358. * @return The length of the skeleton string, in bytes. The returned length
  1359. * is always that of the complete skeleton, even when the
  1360. * supplied buffer is too small (or of zero length)
  1361. *
  1362. * @stable ICU 4.2
  1363. */
  1364. U_STABLE int32_t U_EXPORT2
  1365. uspoof_getSkeletonUTF8(const USpoofChecker *sc,
  1366. uint32_t type,
  1367. const char *id, int32_t length,
  1368. char *dest, int32_t destCapacity,
  1369. UErrorCode *status);
  1370. #if U_SHOW_CPLUSPLUS_API
  1371. /**
  1372. * Get the "skeleton" for an identifier.
  1373. * Skeletons are a transformation of the input identifier;
  1374. * Two identifiers are confusable if their skeletons are identical.
  1375. * See Unicode UAX #39 for additional information.
  1376. *
  1377. * Using skeletons directly makes it possible to quickly check
  1378. * whether an identifier is confusable with any of some large
  1379. * set of existing identifiers, by creating an efficiently
  1380. * searchable collection of the skeletons.
  1381. *
  1382. * @param sc The USpoofChecker.
  1383. * @param type Deprecated in ICU 58. You may pass any number.
  1384. * Originally, controlled which of the Unicode confusable data
  1385. * tables to use.
  1386. * @param id The input identifier whose skeleton will be computed.
  1387. * @param dest The output identifier, to receive the skeleton string.
  1388. * @param status The error code, set if an error occurred while attempting to
  1389. * perform the check.
  1390. * @return A reference to the destination (skeleton) string.
  1391. *
  1392. * @stable ICU 4.2
  1393. */
  1394. U_I18N_API icu::UnicodeString & U_EXPORT2
  1395. uspoof_getSkeletonUnicodeString(const USpoofChecker *sc,
  1396. uint32_t type,
  1397. const icu::UnicodeString &id,
  1398. icu::UnicodeString &dest,
  1399. UErrorCode *status);
  1400. #endif /* U_SHOW_CPLUSPLUS_API */
  1401. /**
  1402. * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
  1403. * in http://unicode.org/Public/security/latest/xidmodifications.txt
  1404. * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
  1405. *
  1406. * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
  1407. * be deleted by the caller.
  1408. *
  1409. * @param status The error code, set if a problem occurs while creating the set.
  1410. *
  1411. * @stable ICU 51
  1412. */
  1413. U_STABLE const USet * U_EXPORT2
  1414. uspoof_getInclusionSet(UErrorCode *status);
  1415. /**
  1416. * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
  1417. * in http://unicode.org/Public/security/latest/xidmodifications.txt
  1418. * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
  1419. *
  1420. * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
  1421. * be deleted by the caller.
  1422. *
  1423. * @param status The error code, set if a problem occurs while creating the set.
  1424. *
  1425. * @stable ICU 51
  1426. */
  1427. U_STABLE const USet * U_EXPORT2
  1428. uspoof_getRecommendedSet(UErrorCode *status);
  1429. #if U_SHOW_CPLUSPLUS_API
  1430. /**
  1431. * Get the set of Candidate Characters for Inclusion in Identifiers, as defined
  1432. * in http://unicode.org/Public/security/latest/xidmodifications.txt
  1433. * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
  1434. *
  1435. * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
  1436. * be deleted by the caller.
  1437. *
  1438. * @param status The error code, set if a problem occurs while creating the set.
  1439. *
  1440. * @stable ICU 51
  1441. */
  1442. U_STABLE const icu::UnicodeSet * U_EXPORT2
  1443. uspoof_getInclusionUnicodeSet(UErrorCode *status);
  1444. /**
  1445. * Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined
  1446. * in http://unicode.org/Public/security/latest/xidmodifications.txt
  1447. * and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
  1448. *
  1449. * The returned set is frozen. Ownership of the set remains with the ICU library; it must not
  1450. * be deleted by the caller.
  1451. *
  1452. * @param status The error code, set if a problem occurs while creating the set.
  1453. *
  1454. * @stable ICU 51
  1455. */
  1456. U_STABLE const icu::UnicodeSet * U_EXPORT2
  1457. uspoof_getRecommendedUnicodeSet(UErrorCode *status);
  1458. #endif /* U_SHOW_CPLUSPLUS_API */
  1459. /**
  1460. * Serialize the data for a spoof detector into a chunk of memory.
  1461. * The flattened spoof detection tables can later be used to efficiently
  1462. * instantiate a new Spoof Detector.
  1463. *
  1464. * The serialized spoof checker includes only the data compiled from the
  1465. * Unicode data tables by uspoof_openFromSource(); it does not include
  1466. * include any other state or configuration that may have been set.
  1467. *
  1468. * @param sc the Spoof Detector whose data is to be serialized.
  1469. * @param data a pointer to 32-bit-aligned memory to be filled with the data,
  1470. * can be NULL if capacity==0
  1471. * @param capacity the number of bytes available at data,
  1472. * or 0 for preflighting
  1473. * @param status an in/out ICU UErrorCode; possible errors include:
  1474. * - U_BUFFER_OVERFLOW_ERROR if the data storage block is too small for serialization
  1475. * - U_ILLEGAL_ARGUMENT_ERROR the data or capacity parameters are bad
  1476. * @return the number of bytes written or needed for the spoof data
  1477. *
  1478. * @see utrie2_openFromSerialized()
  1479. * @stable ICU 4.2
  1480. */
  1481. U_STABLE int32_t U_EXPORT2
  1482. uspoof_serialize(USpoofChecker *sc,
  1483. void *data, int32_t capacity,
  1484. UErrorCode *status);
  1485. #endif
  1486. #endif /* USPOOF_H */