2 * \file lzma/index_hash.h
3 * \brief Validates Index by using a hash function
5 * Instead of constructing complete Index while decoding Blocks, Index hash
6 * calculates a hash of the Block sizes and Index, and then compares the
7 * hashes. This way memory usage is constant even with large number of
8 * Blocks and huge Index.
10 * \author Copyright (C) 2008 Lasse Collin
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
23 #ifndef LZMA_H_INTERNAL
24 # error Never include this file directly. Use <lzma.h> instead.
28 * \brief Opaque data type to hold the Index hash
30 typedef struct lzma_index_hash_s lzma_index_hash;
34 * \brief Allocate and initialize a new lzma_index_hash structure
36 * If index_hash is NULL, a new lzma_index_hash structure is allocated,
37 * initialized, and a pointer to it returned. If allocation fails, NULL
40 * If index_hash is non-NULL, it is reinitialized and the same pointer
41 * returned. In this case, return value cannot be NULL or a different
42 * pointer than the index_hash given as argument.
44 extern lzma_index_hash *lzma_index_hash_init(
45 lzma_index_hash *index_hash, lzma_allocator *allocator);
49 * \brief Deallocate the Index hash
51 extern void lzma_index_hash_end(
52 lzma_index_hash *index_hash, lzma_allocator *allocator);
56 * \brief Add a new Record to an Index hash
58 * \param index Pointer to a lzma_index_hash structure
59 * \param total_size Total Size of a Block
60 * \param uncompressed_size Uncompressed Size of a Block
63 * - LZMA_DATA_ERROR: Compressed or uncompressed size of the
64 * Stream or size of the Index field would grow too big.
65 * - LZMA_PROG_ERROR: Invalid arguments or this function is being
66 * used when lzma_index_hash_decode() has already been used.
68 extern lzma_ret lzma_index_hash_append(lzma_index_hash *index_hash,
69 lzma_vli total_size, lzma_vli uncompressed_size);
73 * \brief Decode the Index field
75 * \return - LZMA_OK: So far good, but more input is needed.
76 * - LZMA_STREAM_END: Index decoded successfully and it matches
77 * the Records given with lzma_index_hash_append().
78 * - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
79 * information given with lzma_index_hash_append().
82 * \note Once decoding of the Index field has been started, no more
83 * Records can be added using lzma_index_hash_append().
85 extern lzma_ret lzma_index_hash_decode(lzma_index_hash *index_hash,
86 const uint8_t *in, size_t *in_pos, size_t in_size);
90 * \brief Get the size of the Index field as bytes
92 * This is needed to verify the Index Size field from the Stream Footer.
94 extern lzma_vli lzma_index_hash_size(const lzma_index_hash *index_hash);