tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

transform.h (3180B)


      1 /* transforms is a part of ABI, but not API.
      2 
      3   It means that there are some functions that are supposed to be in "common"
      4   library, but header itself is not placed into include/brotli. This way,
      5   aforementioned functions will be available only to brotli internals.
      6 */
      7 
      8 #ifndef BROTLI_COMMON_TRANSFORM_H_
      9 #define BROTLI_COMMON_TRANSFORM_H_
     10 
     11 #include "platform.h"
     12 
     13 #if defined(__cplusplus) || defined(c_plusplus)
     14 extern "C" {
     15 #endif
     16 
     17 enum BrotliWordTransformType {
     18  BROTLI_TRANSFORM_IDENTITY = 0,
     19  BROTLI_TRANSFORM_OMIT_LAST_1 = 1,
     20  BROTLI_TRANSFORM_OMIT_LAST_2 = 2,
     21  BROTLI_TRANSFORM_OMIT_LAST_3 = 3,
     22  BROTLI_TRANSFORM_OMIT_LAST_4 = 4,
     23  BROTLI_TRANSFORM_OMIT_LAST_5 = 5,
     24  BROTLI_TRANSFORM_OMIT_LAST_6 = 6,
     25  BROTLI_TRANSFORM_OMIT_LAST_7 = 7,
     26  BROTLI_TRANSFORM_OMIT_LAST_8 = 8,
     27  BROTLI_TRANSFORM_OMIT_LAST_9 = 9,
     28  BROTLI_TRANSFORM_UPPERCASE_FIRST = 10,
     29  BROTLI_TRANSFORM_UPPERCASE_ALL = 11,
     30  BROTLI_TRANSFORM_OMIT_FIRST_1 = 12,
     31  BROTLI_TRANSFORM_OMIT_FIRST_2 = 13,
     32  BROTLI_TRANSFORM_OMIT_FIRST_3 = 14,
     33  BROTLI_TRANSFORM_OMIT_FIRST_4 = 15,
     34  BROTLI_TRANSFORM_OMIT_FIRST_5 = 16,
     35  BROTLI_TRANSFORM_OMIT_FIRST_6 = 17,
     36  BROTLI_TRANSFORM_OMIT_FIRST_7 = 18,
     37  BROTLI_TRANSFORM_OMIT_FIRST_8 = 19,
     38  BROTLI_TRANSFORM_OMIT_FIRST_9 = 20,
     39  BROTLI_TRANSFORM_SHIFT_FIRST = 21,
     40  BROTLI_TRANSFORM_SHIFT_ALL = 22,
     41  BROTLI_NUM_TRANSFORM_TYPES  /* Counts transforms, not a transform itself. */
     42 };
     43 
     44 #define BROTLI_TRANSFORMS_MAX_CUT_OFF BROTLI_TRANSFORM_OMIT_LAST_9
     45 
     46 typedef struct BrotliTransforms {
     47  uint16_t prefix_suffix_size;
     48  /* Last character must be null, so prefix_suffix_size must be at least 1. */
     49  const uint8_t* prefix_suffix;
     50  const uint16_t* prefix_suffix_map;
     51  uint32_t num_transforms;
     52  /* Each entry is a [prefix_id, transform, suffix_id] triplet. */
     53  const uint8_t* transforms;
     54  /* Shift for BROTLI_TRANSFORM_SHIFT_FIRST and BROTLI_TRANSFORM_SHIFT_ALL,
     55     must be NULL if and only if no such transforms are present. */
     56  const uint8_t* params;
     57  /* Indices of transforms like ["", BROTLI_TRANSFORM_OMIT_LAST_#, ""].
     58     0-th element corresponds to ["", BROTLI_TRANSFORM_IDENTITY, ""].
     59     -1, if cut-off transform does not exist. */
     60  int16_t cutOffTransforms[BROTLI_TRANSFORMS_MAX_CUT_OFF + 1];
     61 } BrotliTransforms;
     62 
     63 /* T is BrotliTransforms*; result is uint8_t. */
     64 #define BROTLI_TRANSFORM_PREFIX_ID(T, I) ((T)->transforms[((I) * 3) + 0])
     65 #define BROTLI_TRANSFORM_TYPE(T, I)      ((T)->transforms[((I) * 3) + 1])
     66 #define BROTLI_TRANSFORM_SUFFIX_ID(T, I) ((T)->transforms[((I) * 3) + 2])
     67 
     68 /* T is BrotliTransforms*; result is const uint8_t*. */
     69 #define BROTLI_TRANSFORM_PREFIX(T, I) (&(T)->prefix_suffix[ \
     70    (T)->prefix_suffix_map[BROTLI_TRANSFORM_PREFIX_ID(T, I)]])
     71 #define BROTLI_TRANSFORM_SUFFIX(T, I) (&(T)->prefix_suffix[ \
     72    (T)->prefix_suffix_map[BROTLI_TRANSFORM_SUFFIX_ID(T, I)]])
     73 
     74 BROTLI_COMMON_API const BrotliTransforms* BrotliGetTransforms(void);
     75 
     76 BROTLI_COMMON_API int BrotliTransformDictionaryWord(
     77    uint8_t* dst, const uint8_t* word, int len,
     78    const BrotliTransforms* transforms, int transform_idx);
     79 
     80 #if defined(__cplusplus) || defined(c_plusplus)
     81 }  /* extern "C" */
     82 #endif
     83 
     84 #endif  /* BROTLI_COMMON_TRANSFORM_H_ */