]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma/index_hash.h
Modify LZMA_API macro so that it works on Windows with
[icculus/xz.git] / src / liblzma / api / lzma / index_hash.h
1 /**
2  * \file        lzma/index_hash.h
3  * \brief       Validates Index by using a hash function
4  *
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.
9  *
10  * \author      Copyright (C) 2008 Lasse Collin
11  *
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.
16  *
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.
21  */
22
23 #ifndef LZMA_H_INTERNAL
24 #       error Never include this file directly. Use <lzma.h> instead.
25 #endif
26
27 /**
28  * \brief       Opaque data type to hold the Index hash
29  */
30 typedef struct lzma_index_hash_s lzma_index_hash;
31
32
33 /**
34  * \brief       Allocate and initialize a new lzma_index_hash structure
35  *
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
38  * is returned.
39  *
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 that was given as an argument.
43  */
44 extern LZMA_API(lzma_index_hash *) lzma_index_hash_init(
45                 lzma_index_hash *index_hash, lzma_allocator *allocator)
46                 lzma_attr_warn_unused_result;
47
48
49 /**
50  * \brief       Deallocate lzma_index_hash structure
51  */
52 extern LZMA_API(void) lzma_index_hash_end(
53                 lzma_index_hash *index_hash, lzma_allocator *allocator);
54
55
56 /**
57  * \brief       Add a new Record to an Index hash
58  *
59  * \param       index             Pointer to a lzma_index_hash structure
60  * \param       unpadded_size     Unpadded Size of a Block
61  * \param       uncompressed_size Uncompressed Size of a Block
62  *
63  * \return      - LZMA_OK
64  *              - LZMA_DATA_ERROR: Compressed or uncompressed size of the
65  *                Stream or size of the Index field would grow too big.
66  *              - LZMA_PROG_ERROR: Invalid arguments or this function is being
67  *                used when lzma_index_hash_decode() has already been used.
68  */
69 extern LZMA_API(lzma_ret) lzma_index_hash_append(lzma_index_hash *index_hash,
70                 lzma_vli unpadded_size, lzma_vli uncompressed_size)
71                 lzma_attr_warn_unused_result;
72
73
74 /**
75  * \brief       Decode and validate the Index field
76  *
77  * After telling the sizes of all Blocks with lzma_index_hash_append(),
78  * the actual Index field is decoded with this function. Specifically,
79  * once decoding of the Index field has been started, no more Records
80  * can be added using lzma_index_hash_append().
81  *
82  * This function doesn't use lzma_stream structure to pass the input data.
83  * Instead, the input buffer is specified using three arguments. This is
84  * because it matches better the internal APIs of liblzma.
85  *
86  * \param       index_hash      Pointer to a lzma_index_hash structure
87  * \param       in              Pointer to the beginning of the input buffer
88  * \param       in_pos          in[*in_pos] is the next byte to process
89  * \param       in_size         in[in_size] is the first byte not to process
90  *
91  * \return      - LZMA_OK: So far good, but more input is needed.
92  *              - LZMA_STREAM_END: Index decoded successfully and it matches
93  *                the Records given with lzma_index_hash_append().
94  *              - LZMA_DATA_ERROR: Index is corrupt or doesn't match the
95  *                information given with lzma_index_hash_append().
96  *              - LZMA_BUF_ERROR: Cannot progress because *in_pos >= in_size.
97  *              - LZMA_PROG_ERROR
98  */
99 extern LZMA_API(lzma_ret) lzma_index_hash_decode(lzma_index_hash *index_hash,
100                 const uint8_t *in, size_t *in_pos, size_t in_size)
101                 lzma_attr_warn_unused_result;
102
103
104 /**
105  * \brief       Get the size of the Index field as bytes
106  *
107  * This is needed to verify the Backward Size field in the Stream Footer.
108  */
109 extern LZMA_API(lzma_vli) lzma_index_hash_size(
110                 const lzma_index_hash *index_hash)
111                 lzma_attr_pure;