1 | /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
2 | // vim: expandtab:ts=8:sw=4:softtabstop=4: |
3 | /** |
4 | * \file lzma/index_hash.h |
5 | * \brief Validates Index by using a hash function |
6 | * |
7 | * Hashing makes it possible to use constant amount of memory to validate |
8 | * Index of arbitrary size. |
9 | */ |
10 | |
11 | /* |
12 | * Author: Lasse Collin |
13 | * |
14 | * This file has been put into the public domain. |
15 | * You can do whatever you want with this file. |
16 | * |
17 | * See ../lzma.h for information about liblzma as a whole. |
18 | */ |
19 | |
20 | #ifndef LZMA_H_INTERNAL |
21 | # error Never include this file directly. Use <lzma.h> instead. |
22 | #endif |
23 | |
24 | /** |
25 | * \brief Opaque data type to hold the Index hash |
26 | */ |
27 | typedef struct lzma_index_hash_s lzma_index_hash; |
28 | |
29 | |
30 | /** |
31 | * \brief Allocate and initialize a new lzma_index_hash structure |
32 | * |
33 | * If index_hash is NULL, a new lzma_index_hash structure is allocated, |
34 | * initialized, and a pointer to it returned. If allocation fails, NULL |
35 | * is returned. |
36 | * |
37 | * If index_hash is non-NULL, it is reinitialized and the same pointer |
38 | * returned. In this case, return value cannot be NULL or a different |
39 | * pointer than the index_hash that was given as an argument. |
40 | */ |
41 | extern LZMA_API(lzma_index_hash *) lzma_index_hash_init( |
42 | lzma_index_hash *index_hash, lzma_allocator *allocator) |
43 | lzma_nothrow lzma_attr_warn_unused_result; |
44 | |
45 | |
46 | /** |
47 | * \brief Deallocate lzma_index_hash structure |
48 | */ |
49 | extern LZMA_API(void) lzma_index_hash_end( |
50 | lzma_index_hash *index_hash, lzma_allocator *allocator) |
51 | lzma_nothrow; |
52 | |
53 | |
54 | /** |
55 | * \brief Add a new Record to an Index hash |
56 | * |
57 | * \param index Pointer to a lzma_index_hash structure |
58 | * \param unpadded_size Unpadded Size of a Block |
59 | * \param uncompressed_size Uncompressed Size of a Block |
60 | * |
61 | * \return - LZMA_OK |
62 | * - LZMA_DATA_ERROR: Compressed or uncompressed size of the |
63 | * Stream or size of the Index field would grow too big. |
64 | * - LZMA_PROG_ERROR: Invalid arguments or this function is being |
65 | * used when lzma_index_hash_decode() has already been used. |
66 | */ |
67 | extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash, |
68 | lzma_vli unpadded_size, lzma_vli uncompressed_size) |
69 | lzma_nothrow lzma_attr_warn_unused_result; |
70 | |
71 | |
72 | /** |
73 | * \brief Decode and validate the Index field |
74 | * |
75 | * After telling the sizes of all Blocks with lzma_index_hash_append(), |
76 | * the actual Index field is decoded with this function. Specifically, |
77 | * once decoding of the Index field has been started, no more Records |
78 | * can be added using lzma_index_hash_append(). |
79 | * |
80 | * This function doesn't use lzma_stream structure to pass the input data. |
81 | * Instead, the input buffer is specified using three arguments. This is |
82 | * because it matches better the internal APIs of liblzma. |
83 | * |
84 | * \param index_hash Pointer to a lzma_index_hash structure |
85 | * \param in Pointer to the beginning of the input buffer |
86 | * \param in_pos in[*in_pos] is the next byte to process |
87 | * \param in_size in[in_size] is the first byte not to process |
88 | * |
89 | * \return - LZMA_OK: So far good, but more input is needed. |
90 | * - LZMA_STREAM_END: Index decoded successfully and it matches |
91 | * the Records given with lzma_index_hash_append(). |
92 | * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the |
93 | * information given with lzma_index_hash_append(). |
94 | * - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size. |
95 | * - LZMA_PROG_ERROR |
96 | */ |
97 | extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash, |
98 | const uint8_t *in, size_t *in_pos, size_t in_size) |
99 | lzma_nothrow lzma_attr_warn_unused_result; |
100 | |
101 | |
102 | /** |
103 | * \brief Get the size of the Index field as bytes |
104 | * |
105 | * This is needed to verify the Backward Size field in the Stream Footer. |
106 | */ |
107 | extern LZMA_API(lzma_vli) lzma_index_hash_size( |
108 | const lzma_index_hash *index_hash) |
109 | lzma_nothrow lzma_attr_pure; |
110 | |