#ifndef SIGSUM_ASCII_H_INCLUDED
#define SIGSUM_ASCII_H_INCLUDED

#include <stdbool.h>
#include <stddef.h>

#include "crypto.h"

struct sigsum_buffer
{
  size_t size;
  const char *data;
};

/* All the decoding functions returns true on success, false on
   failure. */

/* Case-insensitive hex decoding. */
/* Decodes SIZE bytes, input must be 2*SIZE hex digits. */
bool
_sigsum_decode_hex (size_t size, uint8_t *dst, const char *src);

/* Input must be 64 hex digits. */
bool
_sigsum_decode_hex_key (struct sigsum_pubkey *dst, const char *src);

/* Input must be 64 hex digits. */
bool
_sigsum_decode_hex_hash (struct sigsum_hash *dst, const char *src);

/* Input must be 128 hex digits. */
bool
_sigsum_decode_hex_signature (struct sigsum_signature *dst, const char *src);

/* Valid range 0 <= x < 2^63. Digits only, no leading zeros (except
   for just "0"). */
bool
_sigsum_decode_decimal (sigsum_size_t *number, size_t size, const char *data);

/* Parse next line from BUFFER, store it (by reference, and without
   the terminating newline character) in VALUE. Requires terminating
   newline. */
bool
_sigsum_buffer_line_strict (struct sigsum_buffer *buffer, struct sigsum_buffer *value);

/* Parse next line from BUFFER, store it (by reference, and without
   any terminating newline character) in VALUE. Never fails: End of
   data is treated as a line terminator followed by all empty
   lines. */
void
_sigsum_buffer_line (struct sigsum_buffer *buffer, struct sigsum_buffer *value);

#endif /* SIGSUM_ASCII_H_INCLUDED */
