[PATCH 1/3] tests: Add mock for virRandomBytes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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
@@ -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
+}
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]