svn_checksum.h File Reference

Subversion checksum routines. More...

`#include <apr.h>`
`#include <apr_pools.h>`
`#include "svn_types.h"`

Go to the source code of this file.

## Data Structures

struct | svn_checksum_t
| A generic checksum representation. More...

## Typedefs

typedef enum svn_checksum_kind_t | svn_checksum_kind_t
| Various types of checksums. More...
typedef struct svn_checksum_t | svn_checksum_t
| A generic checksum representation. More...
typedef struct svn_checksum_ctx_t | svn_checksum_ctx_t
| Opaque type for creating checksums of data.

## Enumerations

enum | svn_checksum_kind_t { svn_checksum_md5 , svn_checksum_sha1 , svn_checksum_fnv1a_32 , svn_checksum_fnv1a_32x4 }
| Various types of checksums. More...

## Functions

svn_checksum_t * | svn_checksum_create (svn_checksum_kind_t kind, apr_pool_t *pool)
| Return a new checksum structure of type kind, initialized to the all- zeros value, allocated in pool. More...
svn_error_t * | svn_checksum_clear (svn_checksum_t *checksum)
| Set checksum->digest to all zeros, which, by convention, matches all other checksums. More...
svn_boolean_t | svn_checksum_match (const svn_checksum_t *checksum1, const svn_checksum_t *checksum2)
| Compare checksums checksum1 and checksum2. More...
svn_checksum_t * | svn_checksum_dup (const svn_checksum_t *checksum, apr_pool_t *pool)
| Return a deep copy of checksum, allocated in pool. More...
const char * | svn_checksum_to_cstring_display (const svn_checksum_t *checksum, apr_pool_t *pool)
| Return the hex representation of checksum, allocating the string in pool. More...
const char * | svn_checksum_to_cstring (const svn_checksum_t *checksum, apr_pool_t *pool)
| Return the hex representation of checksum, allocating the string in pool. More...
const char * | svn_checksum_serialize (const svn_checksum_t *checksum, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
| Return a serialized representation of checksum, allocated in result_pool. More...
svn_error_t * | svn_checksum_deserialize (const svn_checksum_t **checksum, const char *data, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
| Return checksum from the serialized format at data. More...
svn_error_t * | svn_checksum_parse_hex (svn_checksum_t **checksum, svn_checksum_kind_t kind, const char *hex, apr_pool_t *pool)
| Parse the hex representation hex of a checksum of kind kind and set *checksum to the result, allocating in pool. More...
svn_error_t * | svn_checksum (svn_checksum_t **checksum, svn_checksum_kind_t kind, const void *data, apr_size_t len, apr_pool_t *pool)
| Return in *checksum the checksum of type kind for the bytes beginning at data, and going for len. More...
svn_checksum_t * | svn_checksum_empty_checksum (svn_checksum_kind_t kind, apr_pool_t *pool)
| Return in pool a newly allocated checksum populated with the checksum of type kind for the empty string. More...
svn_checksum_ctx_t * | svn_checksum_ctx_create (svn_checksum_kind_t kind, apr_pool_t *pool)
| Create a new `svn_checksum_ctx_t` structure, allocated from pool for calculating checksums of type kind. More...
svn_error_t * | svn_checksum_ctx_reset (svn_checksum_ctx_t *ctx)
| Reset an existing checksum ctx to initial state. More...
svn_error_t * | svn_checksum_update (svn_checksum_ctx_t *ctx, const void *data, apr_size_t len)
| Update the checksum represented by ctx, with len bytes starting at data. More...
svn_error_t * | svn_checksum_final (svn_checksum_t **checksum, const svn_checksum_ctx_t *ctx, apr_pool_t *pool)
| Finalize the checksum used when creating ctx, and put the resultant checksum in *checksum, allocated in pool. More...
apr_size_t | svn_checksum_size (const svn_checksum_t *checksum)
| Return the digest size of checksum. More...
svn_boolean_t | svn_checksum_is_empty_checksum (svn_checksum_t *checksum)
| Return `TRUE` iff checksum matches the checksum for the empty string. More...
svn_error_t * | svn_checksum_mismatch_err (const svn_checksum_t *expected, const svn_checksum_t *actual, apr_pool_t *scratch_pool, const char *fmt,...)
| Return an error of type SVN_ERR_CHECKSUM_MISMATCH for actual and expected checksums which do not match. More...

## Detailed Description

Subversion checksum routines.

# @if copyrights

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations

# under the License.

Definition in file svn_checksum.h.

## Typedef Documentation

## svn_checksum_kind_t

typedef enum svn_checksum_kind_t svn_checksum_kind_t

Various types of checksums.

Since
  New in 1.6.

## svn_checksum_t

typedef struct svn_checksum_t svn_checksum_t

A generic checksum representation.

Since
  New in 1.6.

## Enumeration Type Documentation

## svn_checksum_kind_t

enum svn_checksum_kind_t

Various types of checksums.

Since
  New in 1.6.

Enumerator
svn_checksum_md5 | The checksum is (or should be set to) an MD5 checksum.
svn_checksum_sha1 | The checksum is (or should be set to) a SHA1 checksum.

svn_checksum_fnv1a_32

The checksum is (or should be set to) a FNV-1a 32 bit checksum, in big endian byte order.

Since
  New in 1.9.

svn_checksum_fnv1a_32x4

The checksum is (or should be set to) a modified FNV-1a 32 bit, in big endian byte order.

Since
  New in 1.9.

Definition at line 45 of file svn_checksum.h.

## Function Documentation

## svn_checksum()

svn_error_t* svn_checksum | ( | svn_checksum_t ** | checksum,
|  | svn_checksum_kind_t | kind,
|  | const void * | data,
|  | apr_size_t | len,
|  | apr_pool_t * | pool
| ) |  |

Return in *checksum the checksum of type kind for the bytes beginning at data, and going for len.

*checksum is allocated in pool.

Since
  New in 1.6.

## svn_checksum_clear()

svn_error_t* svn_checksum_clear | ( | svn_checksum_t * | checksum | ) |

Set checksum->digest to all zeros, which, by convention, matches all other checksums.

Since
  New in 1.6.

## svn_checksum_create()

svn_checksum_t* svn_checksum_create | ( | svn_checksum_kind_t | kind,
|  | apr_pool_t * | pool
| ) |  |

Return a new checksum structure of type kind, initialized to the all- zeros value, allocated in pool.

Since
  New in 1.6.

## svn_checksum_ctx_create()

svn_checksum_ctx_t* svn_checksum_ctx_create | ( | svn_checksum_kind_t | kind,
|  | apr_pool_t * | pool
| ) |  |

Create a new `svn_checksum_ctx_t` structure, allocated from pool for calculating checksums of type kind.

See also
  svn_checksum_final()

Since
  New in 1.6.

## svn_checksum_ctx_reset()

svn_error_t* svn_checksum_ctx_reset | ( | svn_checksum_ctx_t * | ctx | ) |

Reset an existing checksum ctx to initial state.

See also
  svn_checksum_ctx_create()

Since
  New in 1.10.

## svn_checksum_deserialize()

svn_error_t* svn_checksum_deserialize | ( | const svn_checksum_t ** | checksum,
|  | const char * | data,
|  | apr_pool_t * | result_pool,
|  | apr_pool_t * | scratch_pool
| ) |  |

Return checksum from the serialized format at data.

The checksum will be allocated in result_pool, with any temporary allocations performed in scratch_pool.

Since
  New in 1.7.

## svn_checksum_dup()

svn_checksum_t* svn_checksum_dup | ( | const svn_checksum_t * | checksum,
|  | apr_pool_t * | pool
| ) |  |

Return a deep copy of checksum, allocated in pool.

If checksum is NULL then NULL is returned.

Since
  New in 1.6.

## svn_checksum_empty_checksum()

svn_checksum_t* svn_checksum_empty_checksum | ( | svn_checksum_kind_t | kind,
|  | apr_pool_t * | pool
| ) |  |

Return in pool a newly allocated checksum populated with the checksum of type kind for the empty string.

Since
  New in 1.6.

## svn_checksum_final()

svn_error_t* svn_checksum_final | ( | svn_checksum_t ** | checksum,
|  | const svn_checksum_ctx_t * | ctx,
|  | apr_pool_t * | pool
| ) |  |

Finalize the checksum used when creating ctx, and put the resultant checksum in *checksum, allocated in pool.

Since
  New in 1.6.

## svn_checksum_is_empty_checksum()

svn_boolean_t svn_checksum_is_empty_checksum | ( | svn_checksum_t * | checksum | ) |

Return `TRUE` iff checksum matches the checksum for the empty string.

Since
  New in 1.8.

## svn_checksum_match()

svn_boolean_t svn_checksum_match | ( | const svn_checksum_t * | checksum1,
|  | const svn_checksum_t * | checksum2
| ) |  |

Compare checksums checksum1 and checksum2.

If their kinds do not match or if neither is all zeros, and their content does not match, then return FALSE; else return TRUE.

Since
  New in 1.6.

## svn_checksum_mismatch_err()

svn_error_t* svn_checksum_mismatch_err | ( | const svn_checksum_t * | expected,
|  | const svn_checksum_t * | actual,
|  | apr_pool_t * | scratch_pool,
|  | const char * | fmt,
|  |  | ...
| ) |  |

Return an error of type SVN_ERR_CHECKSUM_MISMATCH for actual and expected checksums which do not match.

Use fmt, and the following parameters to populate the error message.

Note
  This function does not actually check for the mismatch, it just constructs the error.

scratch_pool is used for temporary allocations; the returned error will be allocated in its own pool (as is typical).

Since
  New in 1.7.

## svn_checksum_parse_hex()

svn_error_t* svn_checksum_parse_hex | ( | svn_checksum_t ** | checksum,
|  | svn_checksum_kind_t | kind,
|  | const char * | hex,
|  | apr_pool_t * | pool
| ) |  |

Parse the hex representation hex of a checksum of kind kind and set *checksum to the result, allocating in pool.

If hex is `NULL` or is the all-zeros checksum, then set *checksum to `NULL`.

Since
  New in 1.6.

## svn_checksum_serialize()

const char* svn_checksum_serialize | ( | const svn_checksum_t * | checksum,
|  | apr_pool_t * | result_pool,
|  | apr_pool_t * | scratch_pool
| ) |  |

Return a serialized representation of checksum, allocated in result_pool.

Temporary allocations are performed in scratch_pool.

Note that checksum may not be NULL.

Since
  New in 1.7.

## svn_checksum_size()

apr_size_t svn_checksum_size | ( | const svn_checksum_t * | checksum | ) |

Return the digest size of checksum.

Since
  New in 1.6.

## svn_checksum_to_cstring()

const char* svn_checksum_to_cstring | ( | const svn_checksum_t * | checksum,
|  | apr_pool_t * | pool
| ) |  |

Return the hex representation of checksum, allocating the string in pool.

If checksum->digest is all zeros (that is, 0, not '0') then return NULL. In 1.7+, checksum may be NULL and NULL will be returned in that case.

Since
  New in 1.6.

Note
  Passing NULL for checksum in 1.6 will cause a segfault.

## svn_checksum_to_cstring_display()

const char* svn_checksum_to_cstring_display | ( | const svn_checksum_t * | checksum,
|  | apr_pool_t * | pool
| ) |  |

Return the hex representation of checksum, allocating the string in pool.

Since
  New in 1.6.

## svn_checksum_update()

svn_error_t* svn_checksum_update | ( | svn_checksum_ctx_t * | ctx,
|  | const void * | data,
|  | apr_size_t | len
| ) |  |

Update the checksum represented by ctx, with len bytes starting at data.

Since
  New in 1.6.