2008-06-18 18:02:10 +03:00
|
|
|
/**
|
|
|
|
* \file lzma/index_hash.h
|
2010-10-21 23:06:31 +03:00
|
|
|
* \brief Validate Index by using a hash function
|
2022-12-21 23:59:43 +08:00
|
|
|
* \note Never include this file directly. Use <lzma.h> instead.
|
|
|
|
*
|
|
|
|
* See ../lzma.h for information about liblzma as a whole.
|
2009-08-27 10:13:46 +03:00
|
|
|
*
|
|
|
|
* Hashing makes it possible to use constant amount of memory to validate
|
|
|
|
* Index of arbitrary size.
|
2009-04-13 11:27:40 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Author: Lasse Collin
|
2008-06-18 18:02:10 +03:00
|
|
|
*
|
2009-04-13 11:27:40 +03:00
|
|
|
* This file has been put into the public domain.
|
|
|
|
* You can do whatever you want with this file.
|
2008-06-18 18:02:10 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LZMA_H_INTERNAL
|
|
|
|
# error Never include this file directly. Use <lzma.h> instead.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Opaque data type to hold the Index hash
|
|
|
|
*/
|
|
|
|
typedef struct lzma_index_hash_s lzma_index_hash;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Allocate and initialize a new lzma_index_hash structure
|
|
|
|
*
|
2023-02-10 21:35:23 +08:00
|
|
|
* If index_hash is NULL, this function allocates and initializes a new
|
|
|
|
* lzma_index_hash structure and returns a pointer to it. If allocation
|
|
|
|
* fails, NULL is returned.
|
2008-06-18 18:02:10 +03:00
|
|
|
*
|
2023-02-10 21:35:23 +08:00
|
|
|
* If index_hash is non-NULL, this function reinitializes the lzma_index_hash
|
|
|
|
* structure and returns the same pointer. In this case, return value cannot
|
|
|
|
* be NULL or a different pointer than the index_hash that was given as
|
|
|
|
* an argument.
|
|
|
|
*
|
|
|
|
* \param index_hash Pointer to a lzma_index_hash structure or NULL.
|
|
|
|
* \param allocator lzma_allocator for custom allocator functions.
|
|
|
|
* Set to NULL to use malloc() and free().
|
|
|
|
*
|
|
|
|
* \return Initialized lzma_index_hash structure on success or
|
|
|
|
* NULL on failure.
|
2008-06-18 18:02:10 +03:00
|
|
|
*/
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_index_hash *index_hash, const lzma_allocator *allocator)
|
2009-08-27 10:13:46 +03:00
|
|
|
lzma_nothrow lzma_attr_warn_unused_result;
|
2008-06-18 18:02:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 19:39:13 +02:00
|
|
|
* \brief Deallocate lzma_index_hash structure
|
2023-02-10 21:35:23 +08:00
|
|
|
*
|
|
|
|
* \param index_hash Pointer to a lzma_index_hash structure to free.
|
|
|
|
* \param allocator lzma_allocator for custom allocator functions.
|
|
|
|
* Set to NULL to use malloc() and free().
|
2008-06-18 18:02:10 +03:00
|
|
|
*/
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(void) lzma_index_hash_end(
|
2012-07-17 18:19:59 +03:00
|
|
|
lzma_index_hash *index_hash, const lzma_allocator *allocator)
|
2009-08-27 10:13:46 +03:00
|
|
|
lzma_nothrow;
|
2008-06-18 18:02:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Add a new Record to an Index hash
|
|
|
|
*
|
2022-11-21 13:02:33 +02:00
|
|
|
* \param index_hash Pointer to a lzma_index_hash structure
|
2008-11-19 20:46:52 +02:00
|
|
|
* \param unpadded_size Unpadded Size of a Block
|
2008-06-18 18:02:10 +03:00
|
|
|
* \param uncompressed_size Uncompressed Size of a Block
|
|
|
|
*
|
2023-02-10 21:35:23 +08:00
|
|
|
* \return Possible lzma_ret values:
|
|
|
|
* - LZMA_OK
|
2008-06-18 18:02:10 +03:00
|
|
|
* - LZMA_DATA_ERROR: Compressed or uncompressed size of the
|
|
|
|
* Stream or size of the Index field would grow too big.
|
|
|
|
* - LZMA_PROG_ERROR: Invalid arguments or this function is being
|
|
|
|
* used when lzma_index_hash_decode() has already been used.
|
|
|
|
*/
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
|
2008-11-19 20:46:52 +02:00
|
|
|
lzma_vli unpadded_size, lzma_vli uncompressed_size)
|
2009-08-27 10:13:46 +03:00
|
|
|
lzma_nothrow lzma_attr_warn_unused_result;
|
2008-06-18 18:02:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-15 19:39:13 +02:00
|
|
|
* \brief Decode and validate the Index field
|
|
|
|
*
|
|
|
|
* After telling the sizes of all Blocks with lzma_index_hash_append(),
|
|
|
|
* the actual Index field is decoded with this function. Specifically,
|
|
|
|
* once decoding of the Index field has been started, no more Records
|
|
|
|
* can be added using lzma_index_hash_append().
|
|
|
|
*
|
|
|
|
* This function doesn't use lzma_stream structure to pass the input data.
|
|
|
|
* Instead, the input buffer is specified using three arguments. This is
|
|
|
|
* because it matches better the internal APIs of liblzma.
|
|
|
|
*
|
|
|
|
* \param index_hash Pointer to a lzma_index_hash structure
|
|
|
|
* \param in Pointer to the beginning of the input buffer
|
2023-02-10 21:35:23 +08:00
|
|
|
* \param[out] in_pos in[*in_pos] is the next byte to process
|
2008-12-15 19:39:13 +02:00
|
|
|
* \param in_size in[in_size] is the first byte not to process
|
2008-06-18 18:02:10 +03:00
|
|
|
*
|
2023-02-10 21:35:23 +08:00
|
|
|
* \return Possible lzma_ret values:
|
|
|
|
* - LZMA_OK: So far good, but more input is needed.
|
2008-06-18 18:02:10 +03:00
|
|
|
* - LZMA_STREAM_END: Index decoded successfully and it matches
|
|
|
|
* the Records given with lzma_index_hash_append().
|
|
|
|
* - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
|
|
|
|
* information given with lzma_index_hash_append().
|
2008-12-15 19:39:13 +02:00
|
|
|
* - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
|
2008-06-18 18:02:10 +03:00
|
|
|
* - LZMA_PROG_ERROR
|
|
|
|
*/
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
|
2008-08-28 22:53:15 +03:00
|
|
|
const uint8_t *in, size_t *in_pos, size_t in_size)
|
2009-08-27 10:13:46 +03:00
|
|
|
lzma_nothrow lzma_attr_warn_unused_result;
|
2008-06-18 18:02:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the size of the Index field as bytes
|
|
|
|
*
|
2008-12-15 19:39:13 +02:00
|
|
|
* This is needed to verify the Backward Size field in the Stream Footer.
|
2023-02-10 21:35:23 +08:00
|
|
|
*
|
|
|
|
* \param index_hash Pointer to a lzma_index_hash structure
|
|
|
|
*
|
|
|
|
* \return Size of the Index field in bytes.
|
2008-06-18 18:02:10 +03:00
|
|
|
*/
|
2009-02-02 20:14:03 +02:00
|
|
|
extern LZMA_API(lzma_vli) lzma_index_hash_size(
|
2009-01-31 11:01:48 +02:00
|
|
|
const lzma_index_hash *index_hash)
|
2009-08-27 10:13:46 +03:00
|
|
|
lzma_nothrow lzma_attr_pure;
|