1207753Smm/** 2207753Smm * \file lzma/index_hash.h 3215187Smm * \brief Validate Index by using a hash function 4207753Smm * 5207753Smm * Hashing makes it possible to use constant amount of memory to validate 6207753Smm * Index of arbitrary size. 7207753Smm */ 8207753Smm 9207753Smm/* 10207753Smm * Author: Lasse Collin 11207753Smm * 12207753Smm * This file has been put into the public domain. 13207753Smm * You can do whatever you want with this file. 14207753Smm * 15207753Smm * See ../lzma.h for information about liblzma as a whole. 16207753Smm */ 17207753Smm 18207753Smm#ifndef LZMA_H_INTERNAL 19207753Smm# error Never include this file directly. Use <lzma.h> instead. 20207753Smm#endif 21207753Smm 22207753Smm/** 23207753Smm * \brief Opaque data type to hold the Index hash 24207753Smm */ 25207753Smmtypedef struct lzma_index_hash_s lzma_index_hash; 26207753Smm 27207753Smm 28207753Smm/** 29207753Smm * \brief Allocate and initialize a new lzma_index_hash structure 30207753Smm * 31207753Smm * If index_hash is NULL, a new lzma_index_hash structure is allocated, 32207753Smm * initialized, and a pointer to it returned. If allocation fails, NULL 33207753Smm * is returned. 34207753Smm * 35207753Smm * If index_hash is non-NULL, it is reinitialized and the same pointer 36207753Smm * returned. In this case, return value cannot be NULL or a different 37207753Smm * pointer than the index_hash that was given as an argument. 38207753Smm */ 39207753Smmextern LZMA_API(lzma_index_hash *) lzma_index_hash_init( 40292588Sdelphij lzma_index_hash *index_hash, const lzma_allocator *allocator) 41207753Smm lzma_nothrow lzma_attr_warn_unused_result; 42207753Smm 43207753Smm 44207753Smm/** 45207753Smm * \brief Deallocate lzma_index_hash structure 46207753Smm */ 47207753Smmextern LZMA_API(void) lzma_index_hash_end( 48292588Sdelphij lzma_index_hash *index_hash, const lzma_allocator *allocator) 49207753Smm lzma_nothrow; 50207753Smm 51207753Smm 52207753Smm/** 53207753Smm * \brief Add a new Record to an Index hash 54207753Smm * 55207753Smm * \param index Pointer to a lzma_index_hash structure 56207753Smm * \param unpadded_size Unpadded Size of a Block 57207753Smm * \param uncompressed_size Uncompressed Size of a Block 58207753Smm * 59207753Smm * \return - LZMA_OK 60207753Smm * - LZMA_DATA_ERROR: Compressed or uncompressed size of the 61207753Smm * Stream or size of the Index field would grow too big. 62207753Smm * - LZMA_PROG_ERROR: Invalid arguments or this function is being 63207753Smm * used when lzma_index_hash_decode() has already been used. 64207753Smm */ 65207753Smmextern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash, 66207753Smm lzma_vli unpadded_size, lzma_vli uncompressed_size) 67207753Smm lzma_nothrow lzma_attr_warn_unused_result; 68207753Smm 69207753Smm 70207753Smm/** 71207753Smm * \brief Decode and validate the Index field 72207753Smm * 73207753Smm * After telling the sizes of all Blocks with lzma_index_hash_append(), 74207753Smm * the actual Index field is decoded with this function. Specifically, 75207753Smm * once decoding of the Index field has been started, no more Records 76207753Smm * can be added using lzma_index_hash_append(). 77207753Smm * 78207753Smm * This function doesn't use lzma_stream structure to pass the input data. 79207753Smm * Instead, the input buffer is specified using three arguments. This is 80207753Smm * because it matches better the internal APIs of liblzma. 81207753Smm * 82207753Smm * \param index_hash Pointer to a lzma_index_hash structure 83207753Smm * \param in Pointer to the beginning of the input buffer 84207753Smm * \param in_pos in[*in_pos] is the next byte to process 85207753Smm * \param in_size in[in_size] is the first byte not to process 86207753Smm * 87207753Smm * \return - LZMA_OK: So far good, but more input is needed. 88207753Smm * - LZMA_STREAM_END: Index decoded successfully and it matches 89207753Smm * the Records given with lzma_index_hash_append(). 90207753Smm * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the 91207753Smm * information given with lzma_index_hash_append(). 92207753Smm * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size. 93207753Smm * - LZMA_PROG_ERROR 94207753Smm */ 95207753Smmextern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash, 96207753Smm const uint8_t *in, size_t *in_pos, size_t in_size) 97207753Smm lzma_nothrow lzma_attr_warn_unused_result; 98207753Smm 99207753Smm 100207753Smm/** 101207753Smm * \brief Get the size of the Index field as bytes 102207753Smm * 103207753Smm * This is needed to verify the Backward Size field in the Stream Footer. 104207753Smm */ 105207753Smmextern LZMA_API(lzma_vli) lzma_index_hash_size( 106207753Smm const lzma_index_hash *index_hash) 107207753Smm lzma_nothrow lzma_attr_pure; 108