Path: blob/master/Utilities/cmliblzma/liblzma/api/lzma/index_hash.h
3158 views
/* SPDX-License-Identifier: 0BSD */12/**3* \file lzma/index_hash.h4* \brief Validate Index by using a hash function5* \note Never include this file directly. Use <lzma.h> instead.6*7* Hashing makes it possible to use constant amount of memory to validate8* Index of arbitrary size.9*/1011/*12* Author: Lasse Collin13*/1415#ifndef LZMA_H_INTERNAL16# error Never include this file directly. Use <lzma.h> instead.17#endif1819/**20* \brief Opaque data type to hold the Index hash21*/22typedef struct lzma_index_hash_s lzma_index_hash;232425/**26* \brief Allocate and initialize a new lzma_index_hash structure27*28* If index_hash is NULL, this function allocates and initializes a new29* lzma_index_hash structure and returns a pointer to it. If allocation30* fails, NULL is returned.31*32* If index_hash is non-NULL, this function reinitializes the lzma_index_hash33* structure and returns the same pointer. In this case, return value cannot34* be NULL or a different pointer than the index_hash that was given as35* an argument.36*37* \param index_hash Pointer to a lzma_index_hash structure or NULL.38* \param allocator lzma_allocator for custom allocator functions.39* Set to NULL to use malloc() and free().40*41* \return Initialized lzma_index_hash structure on success or42* NULL on failure.43*/44extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(45lzma_index_hash *index_hash, const lzma_allocator *allocator)46lzma_nothrow lzma_attr_warn_unused_result;474849/**50* \brief Deallocate lzma_index_hash structure51*52* \param index_hash Pointer to a lzma_index_hash structure to free.53* \param allocator lzma_allocator for custom allocator functions.54* Set to NULL to use malloc() and free().55*/56extern LZMA_API(void) lzma_index_hash_end(57lzma_index_hash *index_hash, const lzma_allocator *allocator)58lzma_nothrow;596061/**62* \brief Add a new Record to an Index hash63*64* \param index_hash Pointer to a lzma_index_hash structure65* \param unpadded_size Unpadded Size of a Block66* \param uncompressed_size Uncompressed Size of a Block67*68* \return Possible lzma_ret values:69* - LZMA_OK70* - LZMA_DATA_ERROR: Compressed or uncompressed size of the71* Stream or size of the Index field would grow too big.72* - LZMA_PROG_ERROR: Invalid arguments or this function is being73* used when lzma_index_hash_decode() has already been used.74*/75extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,76lzma_vli unpadded_size, lzma_vli uncompressed_size)77lzma_nothrow lzma_attr_warn_unused_result;787980/**81* \brief Decode and validate the Index field82*83* After telling the sizes of all Blocks with lzma_index_hash_append(),84* the actual Index field is decoded with this function. Specifically,85* once decoding of the Index field has been started, no more Records86* can be added using lzma_index_hash_append().87*88* This function doesn't use lzma_stream structure to pass the input data.89* Instead, the input buffer is specified using three arguments. This is90* because it matches better the internal APIs of liblzma.91*92* \param index_hash Pointer to a lzma_index_hash structure93* \param in Pointer to the beginning of the input buffer94* \param[out] in_pos in[*in_pos] is the next byte to process95* \param in_size in[in_size] is the first byte not to process96*97* \return Possible lzma_ret values:98* - LZMA_OK: So far good, but more input is needed.99* - LZMA_STREAM_END: Index decoded successfully and it matches100* the Records given with lzma_index_hash_append().101* - LZMA_DATA_ERROR: Index is corrupt or doesn't match the102* information given with lzma_index_hash_append().103* - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.104* - LZMA_PROG_ERROR105*/106extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,107const uint8_t *in, size_t *in_pos, size_t in_size)108lzma_nothrow lzma_attr_warn_unused_result;109110111/**112* \brief Get the size of the Index field as bytes113*114* This is needed to verify the Backward Size field in the Stream Footer.115*116* \param index_hash Pointer to a lzma_index_hash structure117*118* \return Size of the Index field in bytes.119*/120extern LZMA_API(lzma_vli) lzma_index_hash_size(121const lzma_index_hash *index_hash)122lzma_nothrow lzma_attr_pure;123124125