On 03/05/2014 10:53 AM, Daniel P. Berrange wrote:
GNULIB provides APIs for calculating md5 and sha256 hashes,
but these APIs only return you raw byte arrays. Most users
in libvirt want the hash in printable string format. Add
some helper APIs in util/vircrypto.{c,h} for doing this.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
.gitignore | 1 +
include/libvirt/virterror.h | 1 +
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/libvirt_private.syms | 4 ++
src/util/vircrypto.c | 80 ++++++++++++++++++++++++++++++++++++++++
src/util/vircrypto.h | 40 ++++++++++++++++++++
src/util/virerror.c | 1 +
tests/Makefile.am | 5 +++
tests/vircryptotest.c | 90 +++++++++++++++++++++++++++++++++++++++++++++
10 files changed, 224 insertions(+)
create mode 100644 src/util/vircrypto.c
create mode 100644 src/util/vircrypto.h
create mode 100644 tests/vircryptotest.c
+#define VIR_FROM_THIS VIR_FROM_CRYPTO
+
+static const char hex[] = { '0', '1', '2', '3',
'4', '5', '6', '7',
+ '8', '9', 'a', 'b',
'c', 'd', 'e', 'f' };
Why not the more compact:
static const char hex[] = "0123456789abcdef";
virbuffer.c and virsystemd.c also have variants of this table.
+
+ for (i = 0; i < hashinfo[hash].hashlen; i++) {
+ (*output)[i*2] = hex[(buf[i] >> 4) & 0xf];
+ (*output)[(i*2)+1] = hex[buf[i] & 0xf];
Spaces around operators * and +
ACK.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library
http://libvirt.org