00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Licensed to the Apache Software Foundation (ASF) under one 00005 * or more contributor license agreements. See the NOTICE file 00006 * distributed with this work for additional information 00007 * regarding copyright ownership. The ASF licenses this file 00008 * to you under the Apache License, Version 2.0 (the 00009 * "License"); you may not use this file except in compliance 00010 * with the License. You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, 00015 * software distributed under the License is distributed on an 00016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00017 * KIND, either express or implied. See the License for the 00018 * specific language governing permissions and limitations 00019 * under the License. 00020 * ==================================================================== 00021 * @endcopyright 00022 * 00023 * @file svn_checksum.h 00024 * @brief Subversion checksum routines 00025 */ 00026 00027 #ifndef SVN_CHECKSUM_H 00028 #define SVN_CHECKSUM_H 00029 00030 #include <apr.h> /* for apr_size_t */ 00031 #include <apr_pools.h> /* for apr_pool_t */ 00032 00033 #include "svn_types.h" /* for svn_boolean_t, svn_error_t */ 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif /* __cplusplus */ 00038 00039 00040 /** 00041 * Various types of checksums. 00042 * 00043 * @since New in 1.6. 00044 */ 00045 typedef enum svn_checksum_kind_t 00046 { 00047 /** The checksum is (or should be set to) an MD5 checksum. */ 00048 svn_checksum_md5, 00049 00050 /** The checksum is (or should be set to) a SHA1 checksum. */ 00051 svn_checksum_sha1, 00052 00053 /** The checksum is (or should be set to) a FNV-1a 32 bit checksum, 00054 * in big endian byte order. 00055 * @since New in 1.9. */ 00056 svn_checksum_fnv1a_32, 00057 00058 /** The checksum is (or should be set to) a modified FNV-1a 32 bit, 00059 * in big endian byte order. 00060 * @since New in 1.9. */ 00061 svn_checksum_fnv1a_32x4 00062 } svn_checksum_kind_t; 00063 00064 /** 00065 * A generic checksum representation. 00066 * 00067 * @since New in 1.6. 00068 */ 00069 typedef struct svn_checksum_t 00070 { 00071 /** The bytes of the checksum. */ 00072 const unsigned char *digest; 00073 00074 /** The type of the checksum. This should never be changed by consumers 00075 of the APIs. */ 00076 svn_checksum_kind_t kind; 00077 } svn_checksum_t; 00078 00079 /** 00080 * Opaque type for creating checksums of data. 00081 */ 00082 typedef struct svn_checksum_ctx_t svn_checksum_ctx_t; 00083 00084 /** Return a new checksum structure of type @a kind, initialized to the all- 00085 * zeros value, allocated in @a pool. 00086 * 00087 * @since New in 1.6. 00088 */ 00089 svn_checksum_t * 00090 svn_checksum_create(svn_checksum_kind_t kind, 00091 apr_pool_t *pool); 00092 00093 /** Set @a checksum->digest to all zeros, which, by convention, matches 00094 * all other checksums. 00095 * 00096 * @since New in 1.6. 00097 */ 00098 svn_error_t * 00099 svn_checksum_clear(svn_checksum_t *checksum); 00100 00101 /** Compare checksums @a checksum1 and @a checksum2. If their kinds do not 00102 * match or if neither is all zeros, and their content does not match, then 00103 * return FALSE; else return TRUE. 00104 * 00105 * @since New in 1.6. 00106 */ 00107 svn_boolean_t 00108 svn_checksum_match(const svn_checksum_t *checksum1, 00109 const svn_checksum_t *checksum2); 00110 00111 00112 /** 00113 * Return a deep copy of @a checksum, allocated in @a pool. If @a 00114 * checksum is NULL then NULL is returned. 00115 * 00116 * @since New in 1.6. 00117 */ 00118 svn_checksum_t * 00119 svn_checksum_dup(const svn_checksum_t *checksum, 00120 apr_pool_t *pool); 00121 00122 00123 /** Return the hex representation of @a checksum, allocating the string 00124 * in @a pool. 00125 * 00126 * @since New in 1.6. 00127 */ 00128 const char * 00129 svn_checksum_to_cstring_display(const svn_checksum_t *checksum, 00130 apr_pool_t *pool); 00131 00132 00133 /** Return the hex representation of @a checksum, allocating the 00134 * string in @a pool. If @a checksum->digest is all zeros (that is, 00135 * 0, not '0') then return NULL. In 1.7+, @a checksum may be NULL 00136 * and NULL will be returned in that case. 00137 * 00138 * @since New in 1.6. 00139 * @note Passing NULL for @a checksum in 1.6 will cause a segfault. 00140 */ 00141 const char * 00142 svn_checksum_to_cstring(const svn_checksum_t *checksum, 00143 apr_pool_t *pool); 00144 00145 00146 /** Return a serialized representation of @a checksum, allocated in 00147 * @a result_pool. Temporary allocations are performed in @a scratch_pool. 00148 * 00149 * Note that @a checksum may not be NULL. 00150 * 00151 * @since New in 1.7. 00152 */ 00153 const char * 00154 svn_checksum_serialize(const svn_checksum_t *checksum, 00155 apr_pool_t *result_pool, 00156 apr_pool_t *scratch_pool); 00157 00158 00159 /** Return @a checksum from the serialized format at @a data. The checksum 00160 * will be allocated in @a result_pool, with any temporary allocations 00161 * performed in @a scratch_pool. 00162 * 00163 * @since New in 1.7. 00164 */ 00165 svn_error_t * 00166 svn_checksum_deserialize(const svn_checksum_t **checksum, 00167 const char *data, 00168 apr_pool_t *result_pool, 00169 apr_pool_t *scratch_pool); 00170 00171 00172 /** Parse the hex representation @a hex of a checksum of kind @a kind and 00173 * set @a *checksum to the result, allocating in @a pool. 00174 * 00175 * If @a hex is @c NULL or is the all-zeros checksum, then set @a *checksum 00176 * to @c NULL. 00177 * 00178 * @since New in 1.6. 00179 */ 00180 svn_error_t * 00181 svn_checksum_parse_hex(svn_checksum_t **checksum, 00182 svn_checksum_kind_t kind, 00183 const char *hex, 00184 apr_pool_t *pool); 00185 00186 /** 00187 * Return in @a *checksum the checksum of type @a kind for the bytes beginning 00188 * at @a data, and going for @a len. @a *checksum is allocated in @a pool. 00189 * 00190 * @since New in 1.6. 00191 */ 00192 svn_error_t * 00193 svn_checksum(svn_checksum_t **checksum, 00194 svn_checksum_kind_t kind, 00195 const void *data, 00196 apr_size_t len, 00197 apr_pool_t *pool); 00198 00199 00200 /** 00201 * Return in @a pool a newly allocated checksum populated with the checksum 00202 * of type @a kind for the empty string. 00203 * 00204 * @since New in 1.6. 00205 */ 00206 svn_checksum_t * 00207 svn_checksum_empty_checksum(svn_checksum_kind_t kind, 00208 apr_pool_t *pool); 00209 00210 00211 /** 00212 * Create a new @c svn_checksum_ctx_t structure, allocated from @a pool for 00213 * calculating checksums of type @a kind. @see svn_checksum_final() 00214 * 00215 * @since New in 1.6. 00216 */ 00217 svn_checksum_ctx_t * 00218 svn_checksum_ctx_create(svn_checksum_kind_t kind, 00219 apr_pool_t *pool); 00220 00221 /** 00222 * Update the checksum represented by @a ctx, with @a len bytes starting at 00223 * @a data. 00224 * 00225 * @since New in 1.6. 00226 */ 00227 svn_error_t * 00228 svn_checksum_update(svn_checksum_ctx_t *ctx, 00229 const void *data, 00230 apr_size_t len); 00231 00232 00233 /** 00234 * Finalize the checksum used when creating @a ctx, and put the resultant 00235 * checksum in @a *checksum, allocated in @a pool. 00236 * 00237 * @since New in 1.6. 00238 */ 00239 svn_error_t * 00240 svn_checksum_final(svn_checksum_t **checksum, 00241 const svn_checksum_ctx_t *ctx, 00242 apr_pool_t *pool); 00243 00244 00245 /** 00246 * Return the digest size of @a checksum. 00247 * 00248 * @since New in 1.6. 00249 */ 00250 apr_size_t 00251 svn_checksum_size(const svn_checksum_t *checksum); 00252 00253 /** 00254 * Return @c TRUE iff @a checksum matches the checksum for the empty 00255 * string. 00256 * 00257 * @since New in 1.8. 00258 */ 00259 svn_boolean_t 00260 svn_checksum_is_empty_checksum(svn_checksum_t *checksum); 00261 00262 00263 /** 00264 * Return an error of type #SVN_ERR_CHECKSUM_MISMATCH for @a actual and 00265 * @a expected checksums which do not match. Use @a fmt, and the following 00266 * parameters to populate the error message. 00267 * 00268 * @note This function does not actually check for the mismatch, it just 00269 * constructs the error. 00270 * 00271 * @a scratch_pool is used for temporary allocations; the returned error 00272 * will be allocated in its own pool (as is typical). 00273 * 00274 * @since New in 1.7. 00275 */ 00276 svn_error_t * 00277 svn_checksum_mismatch_err(const svn_checksum_t *expected, 00278 const svn_checksum_t *actual, 00279 apr_pool_t *scratch_pool, 00280 const char *fmt, 00281 ...) 00282 __attribute__ ((format(printf, 4, 5))); 00283 00284 #ifdef __cplusplus 00285 } 00286 #endif /* __cplusplus */ 00287 00288 #endif /* SVN_CHECKSUM_H */
1.6.1