49 return "internal error";
57 return "invalid hash syntax";
59 return "invalid or unsupported hash algorithm";
61 return "invalid hash value";
63 return "hash does not match";
65 return "unknown error";
118 size_t expected_size,
121 assert (validator_out);
123 static GRegex *hex_regex = NULL;
124 gchar **parts = NULL;
125 const char *algo_str = NULL;
126 const char *hex_str = NULL;
128 unsigned int expected_hex_len;
129 gcry_md_hd_t gcrypt_md_hd;
130 gboolean size_enforced = FALSE;
131 size_t final_expected_size = 0;
133 if (expected_hash_str == NULL)
136 if (hex_regex == NULL)
137 hex_regex = g_regex_new (
"^(?:[0-9A-Fa-f][0-9A-Fa-f])+$", 0, 0, NULL);
139 *validator_out = NULL;
141 parts = g_strsplit (expected_hash_str,
":", 2);
142 guint n = g_strv_length (parts);
153 final_expected_size = expected_size;
154 size_enforced = TRUE;
158 final_expected_size = 0;
159 size_enforced = FALSE;
162 algo = gcry_md_map_name (algo_str);
163 if (algo == GCRY_MD_NONE || gcry_md_test_algo (algo))
169 expected_hex_len = gcry_md_get_algo_dlen (algo) * 2;
170 if (strlen (hex_str) != expected_hex_len
171 || g_regex_match (hex_regex, hex_str, 0, NULL) == FALSE)
178 if (gcry_md_open (&gcrypt_md_hd, algo, 0))
185 (*validator_out)->algorithm = algo;
186 (*validator_out)->expected_size = final_expected_size;
187 (*validator_out)->size_enforced = size_enforced;
188 (*validator_out)->expected_hash_str = g_strdup (expected_hash_str);
189 (*validator_out)->expected_hash_hex = g_strdup (hex_str);
190 (*validator_out)->gcrypt_md_hd = gcrypt_md_hd;
191 (*validator_out)->current_size = 0;
262 unsigned char *actual_hash_bin;
263 gchar *actual_hash_hex;
279 g_free (actual_hash_hex);
282 g_free (actual_hash_hex);
gchar * digest_hex(int gcrypt_algorithm, const guchar *digest)
Generate a hexadecimal representation of a message digest.
Authentication mechanism(s).
void gvm_stream_validator_rewind(gvm_stream_validator_t validator)
Rewind the validation state of a stream validator while keeping the expected hash and data size.
void gvm_stream_validator_free(gvm_stream_validator_t validator)
Free a stream validator and all of its fields.
gvm_stream_validator_return_t gvm_stream_validator_new(const char *expected_hash_str, gvm_stream_validator_t *validator_out)
Allocate and initialize a checksum-only stream validator.
const char * gvm_stream_validator_return_str(gvm_stream_validator_return_t value)
Gets a string representation of a gvm_stream_validator_return_t.
gvm_stream_validator_return_t gvm_stream_validator_with_size_new(const char *expected_hash_str, size_t expected_size, gvm_stream_validator_t *validator_out)
Allocate and initialize a new data stream validator.
gvm_stream_validator_return_t gvm_stream_validator_write(gvm_stream_validator_t validator, const char *data, size_t length)
Write data to a validator, updating the hash state and current size.
gvm_stream_validator_return_t gvm_stream_validator_end(gvm_stream_validator_t validator)
Signal the end of data input into a validator and produce the result of the validation.
Data stream validation headers.
#define GVM_STREAM_VALIDATOR_NO_SIZE
struct gvm_stream_validator * gvm_stream_validator_t
Pointer to an opaque stream validator data structure.
gvm_stream_validator_return_t
@ GVM_STREAM_VALIDATOR_INVALID_HASH_ALGORITHM
@ GVM_STREAM_VALIDATOR_HASH_MISMATCH
@ GVM_STREAM_VALIDATOR_DATA_TOO_SHORT
@ GVM_STREAM_VALIDATOR_DATA_TOO_LONG
@ GVM_STREAM_VALIDATOR_INTERNAL_ERROR
@ GVM_STREAM_VALIDATOR_OK
@ GVM_STREAM_VALIDATOR_INVALID_HASH_SYNTAX
@ GVM_STREAM_VALIDATOR_INVALID_HASH_VALUE
Data stream validator structure.
int algorithm
The hash algorithm used.
gchar * expected_hash_hex
Expected hash value as hexadecimal string.
size_t current_size
Current total amount of data received.
gcry_md_hd_t gcrypt_md_hd
gcrypt message digest handle.
gboolean size_enforced
TRUE enforce size checks; FALSE hash-only.
gchar * expected_hash_str
Expected hash algorithm and hex string.
size_t expected_size
Expected amount of data to validate.