librsync  2.3.4
Data Structures | Macros | Typedefs | Functions
sumset.h File Reference

The rs_signature class implementation of a file signature. More...

Include dependency graph for sumset.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  rs_block_sig
 Signature of a single block. More...
 
struct  rs_signature
 Signature of a whole file. More...
 

Macros

#define rs_sig_args_check(magic, block_len, strong_len)
 Assert that rs_sig_args() args for rs_signature_init() are valid. More...
 
#define rs_signature_check(sig)
 Assert that a signature is valid. More...
 

Typedefs

typedef struct rs_block_sig rs_block_sig_t
 Signature of a single block. More...
 

Functions

rs_result rs_signature_init (rs_signature_t *sig, rs_magic_number magic, size_t block_len, size_t strong_len, rs_long_t sig_fsize)
 Initialize an rs_signature instance. More...
 
void rs_signature_done (rs_signature_t *sig)
 Destroy an rs_signature instance. More...
 
rs_block_sig_trs_signature_add_block (rs_signature_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum)
 Add a block to an rs_signature instance. More...
 
rs_long_t rs_signature_find_match (rs_signature_t *sig, rs_weak_sum_t weak_sum, void const *buf, size_t len)
 Find a matching block offset in a signature. More...
 
static weaksum_kind_t rs_signature_weaksum_kind (rs_signature_t const *sig)
 Get the weaksum kind for a signature. More...
 
static strongsum_kind_t rs_signature_strongsum_kind (rs_signature_t const *sig)
 Get the strongsum kind for a signature. More...
 
static rs_weak_sum_t rs_signature_calc_weak_sum (rs_signature_t const *sig, void const *buf, size_t len)
 Calculate the weak sum of a buffer. More...
 
static void rs_signature_calc_strong_sum (rs_signature_t const *sig, void const *buf, size_t len, rs_strong_sum_t *sum)
 Calculate the strong sum of a buffer. More...
 

Detailed Description

The rs_signature class implementation of a file signature.

Definition in file sumset.h.

Macro Definition Documentation

◆ rs_sig_args_check

#define rs_sig_args_check (   magic,
  block_len,
  strong_len 
)
Value:
do {\
assert(((magic) & ~0xff) == (RS_MD4_SIG_MAGIC & ~0xff));\
assert(((magic) & 0xf0) == 0x30 || ((magic) & 0xf0) == 0x40);\
assert((((magic) & 0x0f) == 0x06 &&\
(int)(strong_len) <= RS_MD4_SUM_LENGTH) ||\
(((magic) & 0x0f) == 0x07 &&\
(int)(strong_len) <= RS_BLAKE2_SUM_LENGTH));\
assert(0 < (block_len));\
assert(0 < (strong_len) && (strong_len) <= RS_MAX_STRONG_SUM_LENGTH);\
} while (0)
@ RS_MD4_SIG_MAGIC
A signature file with MD4 signatures.
Definition: librsync.h:82

Assert that rs_sig_args() args for rs_signature_init() are valid.

We don't use a static inline function here so that assert failure output points at where rs_sig_args_check() was called from.

Definition at line 92 of file sumset.h.

◆ rs_signature_check

#define rs_signature_check (   sig)
Value:
do {\
rs_sig_args_check((sig)->magic, (sig)->block_len, (sig)->strong_sum_len);\
assert(0 <= (sig)->count && (sig)->count <= (sig)->size);\
assert(!(sig)->hashtable || (sig)->hashtable->count <= (sig)->count);\
} while (0)
The hashtable type.
Definition: hashtable.h:128
int count
Number of entries in hashtable.
Definition: hashtable.h:130

Assert that a signature is valid.

We don't use a static inline function here so that assert failure output points at where rs_signature_check() was called from.

Definition at line 107 of file sumset.h.

Typedef Documentation

◆ rs_block_sig_t

typedef struct rs_block_sig rs_block_sig_t

Signature of a single block.

Function Documentation

◆ rs_signature_init()

rs_result rs_signature_init ( rs_signature_t sig,
rs_magic_number  magic,
size_t  block_len,
size_t  strong_len,
rs_long_t  sig_fsize 
)

Initialize an rs_signature instance.

Parameters
*sigthe signature to initialize.
magic- the magic type to use (0 for "recommended").
block_len- the block length to use (0 for "recommended").
strong_len- the strongsum length to use (0 for "maximum", -1 for "minimum"). Must be <= the max strongsum size for the strongsum type indicated by the magic value.
sig_fsize- the signature file size (-1 for "unknown"). Used to preallocate required storage.

Definition at line 183 of file sumset.c.

◆ rs_signature_done()

void rs_signature_done ( rs_signature_t sig)

Destroy an rs_signature instance.

Definition at line 215 of file sumset.c.

◆ rs_signature_add_block()

rs_block_sig_t * rs_signature_add_block ( rs_signature_t sig,
rs_weak_sum_t  weak_sum,
rs_strong_sum_t *  strong_sum 
)

Add a block to an rs_signature instance.

Definition at line 222 of file sumset.c.

◆ rs_signature_find_match()

rs_long_t rs_signature_find_match ( rs_signature_t sig,
rs_weak_sum_t  weak_sum,
void const *  buf,
size_t  len 
)

Find a matching block offset in a signature.

Definition at line 242 of file sumset.c.

◆ rs_signature_weaksum_kind()

static weaksum_kind_t rs_signature_weaksum_kind ( rs_signature_t const *  sig)
inlinestatic

Get the weaksum kind for a signature.

Definition at line 114 of file sumset.h.

◆ rs_signature_strongsum_kind()

static strongsum_kind_t rs_signature_strongsum_kind ( rs_signature_t const *  sig)
inlinestatic

Get the strongsum kind for a signature.

Definition at line 121 of file sumset.h.

◆ rs_signature_calc_weak_sum()

static rs_weak_sum_t rs_signature_calc_weak_sum ( rs_signature_t const *  sig,
void const *  buf,
size_t  len 
)
inlinestatic

Calculate the weak sum of a buffer.

Definition at line 128 of file sumset.h.

◆ rs_signature_calc_strong_sum()

static void rs_signature_calc_strong_sum ( rs_signature_t const *  sig,
void const *  buf,
size_t  len,
rs_strong_sum_t *  sum 
)
inlinestatic

Calculate the strong sum of a buffer.

Definition at line 136 of file sumset.h.