other-licenses/snappy/src/snappy-c.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /*
michael@0 2 * Copyright 2011 Martin Gieseking <martin.gieseking@uos.de>.
michael@0 3 *
michael@0 4 * Redistribution and use in source and binary forms, with or without
michael@0 5 * modification, are permitted provided that the following conditions are
michael@0 6 * met:
michael@0 7 *
michael@0 8 * * Redistributions of source code must retain the above copyright
michael@0 9 * notice, this list of conditions and the following disclaimer.
michael@0 10 * * Redistributions in binary form must reproduce the above
michael@0 11 * copyright notice, this list of conditions and the following disclaimer
michael@0 12 * in the documentation and/or other materials provided with the
michael@0 13 * distribution.
michael@0 14 * * Neither the name of Google Inc. nor the names of its
michael@0 15 * contributors may be used to endorse or promote products derived from
michael@0 16 * this software without specific prior written permission.
michael@0 17 *
michael@0 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29 *
michael@0 30 * Plain C interface (a wrapper around the C++ implementation).
michael@0 31 */
michael@0 32
michael@0 33 #ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
michael@0 34 #define UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_
michael@0 35
michael@0 36 #ifdef __cplusplus
michael@0 37 extern "C" {
michael@0 38 #endif
michael@0 39
michael@0 40 #include <stddef.h>
michael@0 41
michael@0 42 /*
michael@0 43 * Return values; see the documentation for each function to know
michael@0 44 * what each can return.
michael@0 45 */
michael@0 46 typedef enum {
michael@0 47 SNAPPY_OK = 0,
michael@0 48 SNAPPY_INVALID_INPUT = 1,
michael@0 49 SNAPPY_BUFFER_TOO_SMALL = 2
michael@0 50 } snappy_status;
michael@0 51
michael@0 52 /*
michael@0 53 * Takes the data stored in "input[0..input_length-1]" and stores
michael@0 54 * it in the array pointed to by "compressed".
michael@0 55 *
michael@0 56 * <compressed_length> signals the space available in "compressed".
michael@0 57 * If it is not at least equal to "snappy_max_compressed_length(input_length)",
michael@0 58 * SNAPPY_BUFFER_TOO_SMALL is returned. After successful compression,
michael@0 59 * <compressed_length> contains the true length of the compressed output,
michael@0 60 * and SNAPPY_OK is returned.
michael@0 61 *
michael@0 62 * Example:
michael@0 63 * size_t output_length = snappy_max_compressed_length(input_length);
michael@0 64 * char* output = (char*)malloc(output_length);
michael@0 65 * if (snappy_compress(input, input_length, output, &output_length)
michael@0 66 * == SNAPPY_OK) {
michael@0 67 * ... Process(output, output_length) ...
michael@0 68 * }
michael@0 69 * free(output);
michael@0 70 */
michael@0 71 snappy_status snappy_compress(const char* input,
michael@0 72 size_t input_length,
michael@0 73 char* compressed,
michael@0 74 size_t* compressed_length);
michael@0 75
michael@0 76 /*
michael@0 77 * Given data in "compressed[0..compressed_length-1]" generated by
michael@0 78 * calling the snappy_compress routine, this routine stores
michael@0 79 * the uncompressed data to
michael@0 80 * uncompressed[0..uncompressed_length-1].
michael@0 81 * Returns failure (a value not equal to SNAPPY_OK) if the message
michael@0 82 * is corrupted and could not be decrypted.
michael@0 83 *
michael@0 84 * <uncompressed_length> signals the space available in "uncompressed".
michael@0 85 * If it is not at least equal to the value returned by
michael@0 86 * snappy_uncompressed_length for this stream, SNAPPY_BUFFER_TOO_SMALL
michael@0 87 * is returned. After successful decompression, <uncompressed_length>
michael@0 88 * contains the true length of the decompressed output.
michael@0 89 *
michael@0 90 * Example:
michael@0 91 * size_t output_length;
michael@0 92 * if (snappy_uncompressed_length(input, input_length, &output_length)
michael@0 93 * != SNAPPY_OK) {
michael@0 94 * ... fail ...
michael@0 95 * }
michael@0 96 * char* output = (char*)malloc(output_length);
michael@0 97 * if (snappy_uncompress(input, input_length, output, &output_length)
michael@0 98 * == SNAPPY_OK) {
michael@0 99 * ... Process(output, output_length) ...
michael@0 100 * }
michael@0 101 * free(output);
michael@0 102 */
michael@0 103 snappy_status snappy_uncompress(const char* compressed,
michael@0 104 size_t compressed_length,
michael@0 105 char* uncompressed,
michael@0 106 size_t* uncompressed_length);
michael@0 107
michael@0 108 /*
michael@0 109 * Returns the maximal size of the compressed representation of
michael@0 110 * input data that is "source_length" bytes in length.
michael@0 111 */
michael@0 112 size_t snappy_max_compressed_length(size_t source_length);
michael@0 113
michael@0 114 /*
michael@0 115 * REQUIRES: "compressed[]" was produced by snappy_compress()
michael@0 116 * Returns SNAPPY_OK and stores the length of the uncompressed data in
michael@0 117 * *result normally. Returns SNAPPY_INVALID_INPUT on parsing error.
michael@0 118 * This operation takes O(1) time.
michael@0 119 */
michael@0 120 snappy_status snappy_uncompressed_length(const char* compressed,
michael@0 121 size_t compressed_length,
michael@0 122 size_t* result);
michael@0 123
michael@0 124 /*
michael@0 125 * Check if the contents of "compressed[]" can be uncompressed successfully.
michael@0 126 * Does not return the uncompressed data; if so, returns SNAPPY_OK,
michael@0 127 * or if not, returns SNAPPY_INVALID_INPUT.
michael@0 128 * Takes time proportional to compressed_length, but is usually at least a
michael@0 129 * factor of four faster than actual decompression.
michael@0 130 */
michael@0 131 snappy_status snappy_validate_compressed_buffer(const char* compressed,
michael@0 132 size_t compressed_length);
michael@0 133
michael@0 134 #ifdef __cplusplus
michael@0 135 } // extern "C"
michael@0 136 #endif
michael@0 137
michael@0 138 #endif /* UTIL_SNAPPY_OPENSOURCE_SNAPPY_C_H_ */

mercurial