2 * \file lzma/index_hash.h
3 * \brief Validate Index by using a hash function
5 * Hashing makes it possible to use constant amount of memory to validate
6 * Index of arbitrary size.
10 * Author: Lasse Collin
12 * This file has been put into the public domain.
13 * You can do whatever you want with this file.
15 * See ../lzma.h for information about liblzma as a whole.
18 #ifndef LZMA_H_INTERNAL
19 # error Never include this file directly. Use <lzma.h> instead.
23 * \brief Opaque data type to hold the Index hash
25 typedef struct lzma_index_hash_s lzma_index_hash;
29 * \brief Allocate and initialize a new lzma_index_hash structure
31 * If index_hash is NULL, a new lzma_index_hash structure is allocated,
32 * initialized, and a pointer to it returned. If allocation fails, NULL
35 * If index_hash is non-NULL, it is reinitialized and the same pointer
36 * returned. In this case, return value cannot be NULL or a different
37 * pointer than the index_hash that was given as an argument.
39 extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
40 lzma_index_hash *index_hash, const lzma_allocator *allocator)
41 lzma_nothrow lzma_attr_warn_unused_result;
45 * \brief Deallocate lzma_index_hash structure
47 extern LZMA_API(void) lzma_index_hash_end(
48 lzma_index_hash *index_hash, const lzma_allocator *allocator)
53 * \brief Add a new Record to an Index hash
55 * \param index Pointer to a lzma_index_hash structure
56 * \param unpadded_size Unpadded Size of a Block
57 * \param uncompressed_size Uncompressed Size of a Block
60 * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
61 * Stream or size of the Index field would grow too big.
62 * - LZMA_PROG_ERROR: Invalid arguments or this function is being
63 * used when lzma_index_hash_decode() has already been used.
65 extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
66 lzma_vli unpadded_size, lzma_vli uncompressed_size)
67 lzma_nothrow lzma_attr_warn_unused_result;
71 * \brief Decode and validate the Index field
73 * After telling the sizes of all Blocks with lzma_index_hash_append(),
74 * the actual Index field is decoded with this function. Specifically,
75 * once decoding of the Index field has been started, no more Records
76 * can be added using lzma_index_hash_append().
78 * This function doesn't use lzma_stream structure to pass the input data.
79 * Instead, the input buffer is specified using three arguments. This is
80 * because it matches better the internal APIs of liblzma.
82 * \param index_hash Pointer to a lzma_index_hash structure
83 * \param in Pointer to the beginning of the input buffer
84 * \param in_pos in[*in_pos] is the next byte to process
85 * \param in_size in[in_size] is the first byte not to process
87 * \return - LZMA_OK: So far good, but more input is needed.
88 * - LZMA_STREAM_END: Index decoded successfully and it matches
89 * the Records given with lzma_index_hash_append().
90 * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
91 * information given with lzma_index_hash_append().
92 * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
95 extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
96 const uint8_t *in, size_t *in_pos, size_t in_size)
97 lzma_nothrow lzma_attr_warn_unused_result;
101 * \brief Get the size of the Index field as bytes
103 * This is needed to verify the Backward Size field in the Stream Footer.
105 extern LZMA_API(lzma_vli) lzma_index_hash_size(
106 const lzma_index_hash *index_hash)
107 lzma_nothrow lzma_attr_pure;