37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen#ifndef HASH_FORMAT_H
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen#define HASH_FORMAT_H
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenstruct hash_format;
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen/* Initialize formatting hash. Format can contain text with %{sha1} style
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen variables. Each hash hash can be also truncated by specifying the number
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen of bits to truncate to, such as %{sha1:80}. */
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenint hash_format_init(const char *format_string, struct hash_format **format_r,
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen const char **error_r);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen/* Add more data to hash. */
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenvoid hash_format_loop(struct hash_format *format,
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen const void *data, size_t size);
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainen/* Finish the hash and write it into given string. */
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainenvoid hash_format_write(struct hash_format *format, string_t *dest);
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainen/* Reset hash to initial state. */
ddd1adf19cacc6186fbc713d255e1e82086d7751Timo Sirainenvoid hash_format_reset(struct hash_format *format);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen/* Write the hash into given string and free used memory. */
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenvoid hash_format_deinit(struct hash_format **format, string_t *dest);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen/* Free used memory without writing to string. */
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainenvoid hash_format_deinit_free(struct hash_format **format);
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen
37bd98570b30513255a19cc52de16594bc4256e0Timo Sirainen#endif