1/**
2 * \file lzma/index_hash.h
3 * \brief Validate Index by using a hash function
4 *
5 * Hashing makes it possible to use constant amount of memory to validate
6 * Index of arbitrary size.
7 */
8
9/*
10 * Author: Lasse Collin
11 *
12 * This file has been put into the public domain.
13 * You can do whatever you want with this file.
14 *
15 * See ../lzma.h for information about liblzma as a whole.
16 */
17
18#ifndef LZMA_H_INTERNAL
19# error Never include this file directly. Use <lzma.h> instead.
20#endif
21
22/**
23 * \brief Opaque data type to hold the Index hash
24 */
25typedef struct lzma_index_hash_s lzma_index_hash;
26
27
28/**
29 * \brief Allocate and initialize a new lzma_index_hash structure
30 *
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
33 * is returned.
34 *
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.
38 */
39extern 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;
42
43
44/**
45 * \brief Deallocate lzma_index_hash structure
46 */
47extern LZMA_API(void) lzma_index_hash_end(
48 lzma_index_hash *index_hash, const lzma_allocator *allocator)
49 lzma_nothrow;
50
51
52/**
53 * \brief Add a new Record to an Index hash
54 *
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
58 *
59 * \return - LZMA_OK
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.
64 */
65extern 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;
68
69
70/**
71 * \brief Decode and validate the Index field
72 *
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().
77 *
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.
81 *
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
86 *
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.
93 * - LZMA_PROG_ERROR
94 */
95extern 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;
98
99
100/**
101 * \brief Get the size of the Index field as bytes
102 *
103 * This is needed to verify the Backward Size field in the Stream Footer.
104 */
105extern LZMA_API(lzma_vli) lzma_index_hash_size(
106 const lzma_index_hash *index_hash)
107 lzma_nothrow lzma_attr_pure;
108

source code of include/lzma/index_hash.h