xref: /dflybsd-src/contrib/xz/src/liblzma/api/lzma/index_hash.h (revision 4381ed9d7ee193d719c4e4a94a9d267d177981c1)
12940b44dSPeter Avalos /**
22940b44dSPeter Avalos  * \file        lzma/index_hash.h
32940b44dSPeter Avalos  * \brief       Validate Index by using a hash function
42940b44dSPeter Avalos  *
52940b44dSPeter Avalos  * Hashing makes it possible to use constant amount of memory to validate
62940b44dSPeter Avalos  * Index of arbitrary size.
72940b44dSPeter Avalos  */
82940b44dSPeter Avalos 
92940b44dSPeter Avalos /*
102940b44dSPeter Avalos  * Author: Lasse Collin
112940b44dSPeter Avalos  *
122940b44dSPeter Avalos  * This file has been put into the public domain.
132940b44dSPeter Avalos  * You can do whatever you want with this file.
142940b44dSPeter Avalos  *
152940b44dSPeter Avalos  * See ../lzma.h for information about liblzma as a whole.
162940b44dSPeter Avalos  */
172940b44dSPeter Avalos 
182940b44dSPeter Avalos #ifndef LZMA_H_INTERNAL
192940b44dSPeter Avalos #	error Never include this file directly. Use <lzma.h> instead.
202940b44dSPeter Avalos #endif
212940b44dSPeter Avalos 
222940b44dSPeter Avalos /**
232940b44dSPeter Avalos  * \brief       Opaque data type to hold the Index hash
242940b44dSPeter Avalos  */
252940b44dSPeter Avalos typedef struct lzma_index_hash_s lzma_index_hash;
262940b44dSPeter Avalos 
272940b44dSPeter Avalos 
282940b44dSPeter Avalos /**
292940b44dSPeter Avalos  * \brief       Allocate and initialize a new lzma_index_hash structure
302940b44dSPeter Avalos  *
312940b44dSPeter Avalos  * If index_hash is NULL, a new lzma_index_hash structure is allocated,
322940b44dSPeter Avalos  * initialized, and a pointer to it returned. If allocation fails, NULL
332940b44dSPeter Avalos  * is returned.
342940b44dSPeter Avalos  *
352940b44dSPeter Avalos  * If index_hash is non-NULL, it is reinitialized and the same pointer
362940b44dSPeter Avalos  * returned. In this case, return value cannot be NULL or a different
372940b44dSPeter Avalos  * pointer than the index_hash that was given as an argument.
382940b44dSPeter Avalos  */
392940b44dSPeter Avalos extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
40*15ab8c86SJohn Marino 		lzma_index_hash *index_hash, const lzma_allocator *allocator)
412940b44dSPeter Avalos 		lzma_nothrow lzma_attr_warn_unused_result;
422940b44dSPeter Avalos 
432940b44dSPeter Avalos 
442940b44dSPeter Avalos /**
452940b44dSPeter Avalos  * \brief       Deallocate lzma_index_hash structure
462940b44dSPeter Avalos  */
472940b44dSPeter Avalos extern LZMA_API(void) lzma_index_hash_end(
48*15ab8c86SJohn Marino 		lzma_index_hash *index_hash, const lzma_allocator *allocator)
492940b44dSPeter Avalos 		lzma_nothrow;
502940b44dSPeter Avalos 
512940b44dSPeter Avalos 
522940b44dSPeter Avalos /**
532940b44dSPeter Avalos  * \brief       Add a new Record to an Index hash
542940b44dSPeter Avalos  *
552940b44dSPeter Avalos  * \param       index             Pointer to a lzma_index_hash structure
562940b44dSPeter Avalos  * \param       unpadded_size     Unpadded Size of a Block
572940b44dSPeter Avalos  * \param       uncompressed_size Uncompressed Size of a Block
582940b44dSPeter Avalos  *
592940b44dSPeter Avalos  * \return      - LZMA_OK
602940b44dSPeter Avalos  *              - LZMA_DATA_ERROR: Compressed or uncompressed size of the
612940b44dSPeter Avalos  *                Stream or size of the Index field would grow too big.
622940b44dSPeter Avalos  *              - LZMA_PROG_ERROR: Invalid arguments or this function is being
632940b44dSPeter Avalos  *                used when lzma_index_hash_decode() has already been used.
642940b44dSPeter Avalos  */
652940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
662940b44dSPeter Avalos 		lzma_vli unpadded_size, lzma_vli uncompressed_size)
672940b44dSPeter Avalos 		lzma_nothrow lzma_attr_warn_unused_result;
682940b44dSPeter Avalos 
692940b44dSPeter Avalos 
702940b44dSPeter Avalos /**
712940b44dSPeter Avalos  * \brief       Decode and validate the Index field
722940b44dSPeter Avalos  *
732940b44dSPeter Avalos  * After telling the sizes of all Blocks with lzma_index_hash_append(),
742940b44dSPeter Avalos  * the actual Index field is decoded with this function. Specifically,
752940b44dSPeter Avalos  * once decoding of the Index field has been started, no more Records
762940b44dSPeter Avalos  * can be added using lzma_index_hash_append().
772940b44dSPeter Avalos  *
782940b44dSPeter Avalos  * This function doesn't use lzma_stream structure to pass the input data.
792940b44dSPeter Avalos  * Instead, the input buffer is specified using three arguments. This is
802940b44dSPeter Avalos  * because it matches better the internal APIs of liblzma.
812940b44dSPeter Avalos  *
822940b44dSPeter Avalos  * \param       index_hash      Pointer to a lzma_index_hash structure
832940b44dSPeter Avalos  * \param       in              Pointer to the beginning of the input buffer
842940b44dSPeter Avalos  * \param       in_pos          in[*in_pos] is the next byte to process
852940b44dSPeter Avalos  * \param       in_size         in[in_size] is the first byte not to process
862940b44dSPeter Avalos  *
872940b44dSPeter Avalos  * \return      - LZMA_OK: So far good, but more input is needed.
882940b44dSPeter Avalos  *              - LZMA_STREAM_END: Index decoded successfully and it matches
892940b44dSPeter Avalos  *                the Records given with lzma_index_hash_append().
902940b44dSPeter Avalos  *              - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
912940b44dSPeter Avalos  *                information given with lzma_index_hash_append().
922940b44dSPeter Avalos  *              - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
932940b44dSPeter Avalos  *              - LZMA_PROG_ERROR
942940b44dSPeter Avalos  */
952940b44dSPeter Avalos extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
962940b44dSPeter Avalos 		const uint8_t *in, size_t *in_pos, size_t in_size)
972940b44dSPeter Avalos 		lzma_nothrow lzma_attr_warn_unused_result;
982940b44dSPeter Avalos 
992940b44dSPeter Avalos 
1002940b44dSPeter Avalos /**
1012940b44dSPeter Avalos  * \brief       Get the size of the Index field as bytes
1022940b44dSPeter Avalos  *
1032940b44dSPeter Avalos  * This is needed to verify the Backward Size field in the Stream Footer.
1042940b44dSPeter Avalos  */
1052940b44dSPeter Avalos extern LZMA_API(lzma_vli) lzma_index_hash_size(
1062940b44dSPeter Avalos 		const lzma_index_hash *index_hash)
1072940b44dSPeter Avalos 		lzma_nothrow lzma_attr_pure;
108