8 /* A SHA1-protected file */
20 unsigned char *buffer
;
21 unsigned char *check_buffer
;
25 struct hashfile_checkpoint
{
30 void hashfile_checkpoint(struct hashfile
*, struct hashfile_checkpoint
*);
31 int hashfile_truncate(struct hashfile
*, struct hashfile_checkpoint
*);
33 /* finalize_hashfile flags */
36 #define CSUM_HASH_IN_STREAM 4
38 struct hashfile
*hashfd(int fd
, const char *name
);
39 struct hashfile
*hashfd_check(const char *name
);
40 struct hashfile
*hashfd_throughput(int fd
, const char *name
, struct progress
*tp
);
41 int finalize_hashfile(struct hashfile
*, unsigned char *, unsigned int);
42 void hashwrite(struct hashfile
*, const void *, unsigned int);
43 void hashflush(struct hashfile
*f
);
44 void crc32_begin(struct hashfile
*);
45 uint32_t crc32_end(struct hashfile
*);
47 /* Verify checksum validity while reading. Returns non-zero on success. */
48 int hashfile_checksum_valid(const unsigned char *data
, size_t len
);
51 * Returns the total number of bytes fed to the hashfile so far (including ones
52 * that have not been written out to the descriptor yet).
54 static inline off_t
hashfile_total(struct hashfile
*f
)
56 return f
->total
+ f
->offset
;
59 static inline void hashwrite_u8(struct hashfile
*f
, uint8_t data
)
61 hashwrite(f
, &data
, sizeof(data
));
64 static inline void hashwrite_be32(struct hashfile
*f
, uint32_t data
)
67 hashwrite(f
, &data
, sizeof(data
));
70 static inline size_t hashwrite_be64(struct hashfile
*f
, uint64_t data
)
73 hashwrite(f
, &data
, sizeof(data
));