[libvirt] [PATCH v4 1/3] tests: Add mock for virRandomBytes [NOT TO BE PUSHED]

John Ferlan jferlan at redhat.com
Tue May 17 16:36:07 UTC 2016


A different model will be posted soon...

Essentially this is way to test/show that a not so random key and iv
will generate a consistent value.

This version uses the setting of the key to the array index rather than
-1 for every entry. Thus a key/iv would be 0x000102030405... etc.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 tests/qemuxml2argvmock.c | 31 ++++++++++++++++++++++++++++++-
 tests/qemuxml2argvtest.c |  1 +
 2 files changed, 31 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
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (C) 2014-2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -30,6 +30,13 @@
 #include "virstring.h"
 #include "virtpm.h"
 #include "virutil.h"
+#include "virrandom.h"
+#ifdef WITH_GNUTLS
+# include <gnutls/gnutls.h>
+# if HAVE_GNUTLS_CRYPTO_H
+#  include <gnutls/crypto.h>
+# endif
+#endif
 #include <time.h>
 #include <unistd.h>
 
@@ -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
+}
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index db42f0b..25caca7 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -26,6 +26,7 @@
 # include "virstring.h"
 # include "storage/storage_driver.h"
 # include "virmock.h"
+# include "virrandom.h"
 
 # include "testutilsqemu.h"
 
-- 
2.5.5




More information about the libvir-list mailing list