2 * \file lzma/index_hash.h
3 * \brief Validate Index by using a hash function
4 * \note Never include this file directly. Use <lzma.h> instead.
6 * Hashing makes it possible to use constant amount of memory to validate
7 * Index of arbitrary size.
11 * Author: Lasse Collin
13 * This file has been put into the public domain.
14 * You can do whatever you want with this file.
17 #ifndef LZMA_H_INTERNAL
18 # error Never include this file directly. Use <lzma.h> instead.
22 * \brief Opaque data type to hold the Index hash
24 typedef struct lzma_index_hash_s lzma_index_hash
;
28 * \brief Allocate and initialize a new lzma_index_hash structure
30 * If index_hash is NULL, this function allocates and initializes a new
31 * lzma_index_hash structure and returns a pointer to it. If allocation
32 * fails, NULL is returned.
34 * If index_hash is non-NULL, this function reinitializes the lzma_index_hash
35 * structure and returns the same pointer. In this case, return value cannot
36 * be NULL or a different pointer than the index_hash that was given as
39 * \param index_hash Pointer to a lzma_index_hash structure or NULL.
40 * \param allocator lzma_allocator for custom allocator functions.
41 * Set to NULL to use malloc() and free().
43 * \return Initialized lzma_index_hash structure on success or
46 extern LZMA_API(lzma_index_hash
*) lzma_index_hash_init(
47 lzma_index_hash
*index_hash
, const lzma_allocator
*allocator
)
48 lzma_nothrow lzma_attr_warn_unused_result
;
52 * \brief Deallocate lzma_index_hash structure
54 * \param index_hash Pointer to a lzma_index_hash structure to free.
55 * \param allocator lzma_allocator for custom allocator functions.
56 * Set to NULL to use malloc() and free().
58 extern LZMA_API(void) lzma_index_hash_end(
59 lzma_index_hash
*index_hash
, const lzma_allocator
*allocator
)
64 * \brief Add a new Record to an Index hash
66 * \param index_hash Pointer to a lzma_index_hash structure
67 * \param unpadded_size Unpadded Size of a Block
68 * \param uncompressed_size Uncompressed Size of a Block
70 * \return Possible lzma_ret values:
72 * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
73 * Stream or size of the Index field would grow too big.
74 * - LZMA_PROG_ERROR: Invalid arguments or this function is being
75 * used when lzma_index_hash_decode() has already been used.
77 extern LZMA_API(lzma_ret
) lzma_index_hash_append(lzma_index_hash
*index_hash
,
78 lzma_vli unpadded_size
, lzma_vli uncompressed_size
)
79 lzma_nothrow lzma_attr_warn_unused_result
;
83 * \brief Decode and validate the Index field
85 * After telling the sizes of all Blocks with lzma_index_hash_append(),
86 * the actual Index field is decoded with this function. Specifically,
87 * once decoding of the Index field has been started, no more Records
88 * can be added using lzma_index_hash_append().
90 * This function doesn't use lzma_stream structure to pass the input data.
91 * Instead, the input buffer is specified using three arguments. This is
92 * because it matches better the internal APIs of liblzma.
94 * \param index_hash Pointer to a lzma_index_hash structure
95 * \param in Pointer to the beginning of the input buffer
96 * \param[out] in_pos in[*in_pos] is the next byte to process
97 * \param in_size in[in_size] is the first byte not to process
99 * \return Possible lzma_ret values:
100 * - LZMA_OK: So far good, but more input is needed.
101 * - LZMA_STREAM_END: Index decoded successfully and it matches
102 * the Records given with lzma_index_hash_append().
103 * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
104 * information given with lzma_index_hash_append().
105 * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
108 extern LZMA_API(lzma_ret
) lzma_index_hash_decode(lzma_index_hash
*index_hash
,
109 const uint8_t *in
, size_t *in_pos
, size_t in_size
)
110 lzma_nothrow lzma_attr_warn_unused_result
;
114 * \brief Get the size of the Index field as bytes
116 * This is needed to verify the Backward Size field in the Stream Footer.
118 * \param index_hash Pointer to a lzma_index_hash structure
120 * \return Size of the Index field in bytes.
122 extern LZMA_API(lzma_vli
) lzma_index_hash_size(
123 const lzma_index_hash
*index_hash
)
124 lzma_nothrow lzma_attr_pure
;