31#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-hash-file", \
34#define LOG_STRERROR_FILE(kind, syscall, \
35 filename) GNUNET_log_from_strerror_file (kind, \
36 "util-crypto-hash-file", \
115 gcry_md_close (fhc->
md);
142 (
delta != (
size_t) sret))
151 gcry_md_write (fhc->
md,
183 fhc->
buffer = (
unsigned char *) &fhc[1];
185 if (GPG_ERR_NO_ERROR != gcry_md_open (&fhc->
md, GCRY_MD_SHA512, 0))
192 fhc->
bsize = blocksize;
232 gcry_md_close (fhc->
md);
static void file_hash_task(void *cls)
File hashing task.
static void file_hash_finish(struct GNUNET_CRYPTO_FileHashContext *fhc, const struct GNUNET_HashCode *res)
Report result of hash computation to callback and free associated resources.
#define LOG_STRERROR_FILE(kind, syscall, filename)
static char * res
Currently read line or NULL on EOF.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid(const struct GNUNET_DISK_FileHandle *h)
Checks whether a handle is invalid.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
struct GNUNET_CRYPTO_FileHashContext * GNUNET_CRYPTO_hash_file(enum GNUNET_SCHEDULER_Priority priority, const char *filename, size_t blocksize, GNUNET_CRYPTO_HashCompletedCallback callback, void *callback_cls)
Compute the hash of an entire file.
void(* GNUNET_CRYPTO_HashCompletedCallback)(void *cls, const struct GNUNET_HashCode *res)
Function called once the hash computation over the specified file has completed.
void GNUNET_CRYPTO_hash_file_cancel(struct GNUNET_CRYPTO_FileHashContext *fhc)
Cancel a file hashing operation.
GNUNET_SCHEDULER_Priority
Valid task priorities.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
static struct GNUNET_TIME_Relative delta
Context used when hashing a file.
uint64_t fsize
Size of the file.
gcry_md_hd_t md
Cumulated hash.
unsigned char * buffer
IO buffer.
GNUNET_CRYPTO_HashCompletedCallback callback
Function to call upon completion.
struct GNUNET_DISK_FileHandle * fh
File descriptor.
void * callback_cls
Closure for callback.
uint64_t offset
Current offset.
struct GNUNET_SCHEDULER_Task * task
Current task for hashing.
char * filename
Name of the file we are hashing.
enum GNUNET_SCHEDULER_Priority priority
Priority we use.
Handle used to access files (and pipes).
Entry in list of pending tasks.