|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +module Net |
| 4 | + class IMAP |
| 5 | + module StringPrep |
| 6 | + |
| 7 | + # Defined in RFC-4505[https://tools.ietf.org/html/rfc4505] §3, The +trace+ |
| 8 | + # profile of \StringPrep is used by the +ANONYMOUS+ \SASL mechanism. |
| 9 | + module Trace |
| 10 | + |
| 11 | + # Defined in RFC-4505[https://tools.ietf.org/html/rfc4505] §3. |
| 12 | + STRINGPREP_PROFILE = "trace" |
| 13 | + |
| 14 | + # >>> |
| 15 | + # The character repertoire of this profile is Unicode 3.2 [Unicode]. |
| 16 | + UNASSIGNED_TABLE = "A.1" |
| 17 | + |
| 18 | + # >>> |
| 19 | + # No mapping is required by this profile. |
| 20 | + MAPPING_TABLES = nil |
| 21 | + |
| 22 | + # >>> |
| 23 | + # No Unicode normalization is required by this profile. |
| 24 | + NORMALIZATION = nil |
| 25 | + |
| 26 | + # From RFC-4505[https://tools.ietf.org/html/rfc4505] §3, The "trace" |
| 27 | + # Profile of "Stringprep": |
| 28 | + # >>> |
| 29 | + # Characters from the following tables of [StringPrep] are prohibited: |
| 30 | + # |
| 31 | + # - C.2.1 (ASCII control characters) |
| 32 | + # - C.2.2 (Non-ASCII control characters) |
| 33 | + # - C.3 (Private use characters) |
| 34 | + # - C.4 (Non-character code points) |
| 35 | + # - C.5 (Surrogate codes) |
| 36 | + # - C.6 (Inappropriate for plain text) |
| 37 | + # - C.8 (Change display properties are deprecated) |
| 38 | + # - C.9 (Tagging characters) |
| 39 | + # |
| 40 | + # No additional characters are prohibited. |
| 41 | + PROHIBITED_TABLES = %w[C.2.1 C.2.2 C.3 C.4 C.5 C.6 C.8 C.9].freeze |
| 42 | + |
| 43 | + # >>> |
| 44 | + # This profile requires bidirectional character checking per Section 6 |
| 45 | + # of [StringPrep]. |
| 46 | + CHECK_BIDI = true |
| 47 | + |
| 48 | + module_function |
| 49 | + |
| 50 | + # From RFC-4505[https://tools.ietf.org/html/rfc4505] §3, The "trace" |
| 51 | + # Profile of "Stringprep": |
| 52 | + # >>> |
| 53 | + # The character repertoire of this profile is Unicode 3.2 [Unicode]. |
| 54 | + # |
| 55 | + # No mapping is required by this profile. |
| 56 | + # |
| 57 | + # No Unicode normalization is required by this profile. |
| 58 | + # |
| 59 | + # The list of unassigned code points for this profile is that provided |
| 60 | + # in Appendix A of [StringPrep]. Unassigned code points are not |
| 61 | + # prohibited. |
| 62 | + # |
| 63 | + # Characters from the following tables of [StringPrep] are prohibited: |
| 64 | + # (documented on PROHIBITED_TABLES) |
| 65 | + # |
| 66 | + # This profile requires bidirectional character checking per Section 6 |
| 67 | + # of [StringPrep]. |
| 68 | + def stringprep_trace(string, **opts) |
| 69 | + StringPrep.stringprep( |
| 70 | + string, |
| 71 | + unassigned: UNASSIGNED_TABLE, |
| 72 | + maps: MAPPING_TABLES, |
| 73 | + prohibited: PROHIBITED_TABLES, |
| 74 | + normalization: NORMALIZATION, |
| 75 | + bidi: CHECK_BIDI, |
| 76 | + profile: STRINGPREP_PROFILE, |
| 77 | + **opts, |
| 78 | + ) |
| 79 | + end |
| 80 | + |
| 81 | + end |
| 82 | + |
| 83 | + end |
| 84 | + end |
| 85 | +end |
0 commit comments