[libvirt] [PATCH 1/3] tests: Add mock for virRandomBytes
Peter Krempa
pkrempa at redhat.com
Thu May 19 07:32:37 UTC 2016
On Wed, May 18, 2016 at 19:52:30 -0400, John Ferlan wrote:
> Create a mock for virRandomBytes to generate a not so random value that
> can be used by the tests to ensure the generation of an encrypted secret
> by masterKey and random initialization vector can produce an expected
> result. The "random number" generated is based upon the size of the
> expected stream of bytes being returned where each byte in the result
> gets the index of the array - hence a 4 byte array returns 0x00010203.
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
> tests/qemuxml2argvmock.c | 31 ++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/tests/qemuxml2argvmock.c b/tests/qemuxml2argvmock.c
> index 1616eed..dade748 100644
> --- a/tests/qemuxml2argvmock.c
> +++ b/tests/qemuxml2argvmock.c
[...]
> @@ -145,3 +152,25 @@ virCommandPassFD(virCommandPtr cmd ATTRIBUTE_UNUSED,
> {
> /* nada */
> }
> +
> +int
> +virRandomBytes(unsigned char *buf,
> + size_t buflen)
> +{
> + size_t i;
> +
> + for (i = 0; i < buflen; i++)
> + buf[i] = i;
> +
> + return 0;
> +}
> +
> +#ifdef WITH_GNUTLS
> +int
> +gnutls_rnd(gnutls_rnd_level_t level ATTRIBUTE_UNUSED,
> + void *data,
> + size_t len)
> +{
> + return virRandomBytes(data, len);
> +#endif
As I've pointed out last time, this won't compile without gnutls.
> +}
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20160519/4b24ac45/attachment-0001.sig>
More information about the libvir-list
mailing list