Greenbone Vulnerability Management Libraries 22.26.0
streamvalidator.h File Reference

Data stream validation headers. More...

#include <stdio.h>

Go to the source code of this file.

Typedefs

typedef struct gvm_stream_validatorgvm_stream_validator_t
 Pointer to an opaque stream validator data structure.

Enumerations

enum  gvm_stream_validator_return_t {
  GVM_STREAM_VALIDATOR_INTERNAL_ERROR = -1 , GVM_STREAM_VALIDATOR_OK = 0 , GVM_STREAM_VALIDATOR_DATA_TOO_SHORT = 1 , GVM_STREAM_VALIDATOR_DATA_TOO_LONG ,
  GVM_STREAM_VALIDATOR_INVALID_HASH_SYNTAX , GVM_STREAM_VALIDATOR_INVALID_HASH_ALGORITHM , GVM_STREAM_VALIDATOR_INVALID_HASH_VALUE , GVM_STREAM_VALIDATOR_HASH_MISMATCH
}

Functions

const char * gvm_stream_validator_return_str (gvm_stream_validator_return_t)
 Gets a string representation of a gvm_stream_validator_return_t.
gvm_stream_validator_return_t gvm_stream_validator_new (const char *, size_t, gvm_stream_validator_t *)
 Allocate and initialize a new data stream validator.
void gvm_stream_validator_rewind (gvm_stream_validator_t)
 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)
 Free a stream validator and all of its fields.
gvm_stream_validator_return_t gvm_stream_validator_write (gvm_stream_validator_t, const char *, size_t)
 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)
 Signal the end of data input into a validator and produce the result of the validation.

Detailed Description

Data stream validation headers.

Typedef Documentation

◆ gvm_stream_validator_t

Pointer to an opaque stream validator data structure.

Enumeration Type Documentation

◆ gvm_stream_validator_return_t

Enumerator
GVM_STREAM_VALIDATOR_INTERNAL_ERROR 

An internal error ocurred.

GVM_STREAM_VALIDATOR_OK 

Action successful / data is valid.

GVM_STREAM_VALIDATOR_DATA_TOO_SHORT 

Not enough data received.

GVM_STREAM_VALIDATOR_DATA_TOO_LONG 

Too much data received.

GVM_STREAM_VALIDATOR_INVALID_HASH_SYNTAX 

Syntax error in hash string (not using "algo:hex" format).

GVM_STREAM_VALIDATOR_INVALID_HASH_ALGORITHM 

Invalid or unsupported hash algorithm.

GVM_STREAM_VALIDATOR_INVALID_HASH_VALUE 

Hash value is not valid. (e.g. not hexadecimal or length does not match algorithm)

GVM_STREAM_VALIDATOR_HASH_MISMATCH 

Hash of received data does not match the expected hash

Function Documentation

◆ gvm_stream_validator_end()

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.

Parameters
[in]validatorThe validator to signal the end of data input of.
Returns
The validation result.

◆ gvm_stream_validator_free()

void gvm_stream_validator_free ( gvm_stream_validator_t validator)

Free a stream validator and all of its fields.

Parameters
[in]validatorThe validator to free.

◆ gvm_stream_validator_new()

gvm_stream_validator_return_t gvm_stream_validator_new ( const char * expected_hash_str,
size_t expected_size,
gvm_stream_validator_t * validator_out )

Allocate and initialize a new data stream validator.

Parameters
[in]expected_hash_strExpected hash / checksum string consisting of an algorithm name or OID as recognized by gcrypt, followed by a colon and the hex-encoded hash, e.g. "md5:70165459812a0d38851a4a4c3e4124c9".
[in]expected_sizeThe number of bytes expected to be sent.
[out]validator_outPointer to output location of the newly allocated validator.
Returns
A validator return code, returning a failure if the expeced hash string is invalid or uses an unsupported algorithm.

◆ gvm_stream_validator_return_str()

const char * gvm_stream_validator_return_str ( gvm_stream_validator_return_t value)

Gets a string representation of a gvm_stream_validator_return_t.

Parameters
[in]valueThe value to get a string representation of.
Returns
Static string describing the return value or NULL if value is GVM_STREAM_VALIDATOR_OK.

◆ gvm_stream_validator_rewind()

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.

Parameters
[in]validatorThe validator to rewind.

◆ gvm_stream_validator_write()

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.

Will fail if the total data size exceeds the expected size.

Parameters
[in]validatorThe validator to handle the data
[in]dataThe data to write.
[in]lengthLength of the data.
Returns
Validator return code, either a "success" or "too long".