#include "sha256.h"
#include "sha512.h"
-static Lisp_Object
-make_digest_string (Lisp_Object digest, int digest_size)
+/* Store into HEXBUF an unterminated hexadecimal character string
+ representing DIGEST, which is binary data of size DIGEST_SIZE bytes.
+ HEXBUF might equal DIGEST. */
+void
+hexbuf_digest (char *hexbuf, void const *digest, int digest_size)
{
- unsigned char *p = SDATA (digest);
+ unsigned char const *p = digest;
for (int i = digest_size - 1; i >= 0; i--)
{
static char const hexdigit[16] = "0123456789abcdef";
int p_i = p[i];
- p[2 * i] = hexdigit[p_i >> 4];
- p[2 * i + 1] = hexdigit[p_i & 0xf];
+ hexbuf[2 * i] = hexdigit[p_i >> 4];
+ hexbuf[2 * i + 1] = hexdigit[p_i & 0xf];
}
+}
+
+static Lisp_Object
+make_digest_string (Lisp_Object digest, int digest_size)
+{
+ hexbuf_digest (SSDATA (digest), SDATA (digest), digest_size);
return digest;
}
extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST;
extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t);
extern bool sweep_weak_table (struct Lisp_Hash_Table *, bool);
+extern void hexbuf_digest (char *, void const *, int);
extern char *extract_data_from_object (Lisp_Object, ptrdiff_t *, ptrdiff_t *);
EMACS_UINT hash_string (char const *, ptrdiff_t);
EMACS_UINT sxhash (Lisp_Object, int);
}
static void
-dump_fingerprint (const char *label, unsigned char const *xfingerprint)
+dump_fingerprint (char const *label,
+ unsigned char const xfingerprint[sizeof fingerprint])
{
- fprintf (stderr, "%s: ", label);
- for (int i = 0; i < 32; ++i)
- fprintf (stderr, "%02x", (unsigned) xfingerprint[i]);
- putc ('\n', stderr);
+ enum { hexbuf_size = 2 * sizeof fingerprint };
+ char hexbuf[hexbuf_size];
+ hexbuf_digest (hexbuf, xfingerprint, sizeof fingerprint);
+ fprintf (stderr, "%s: %.*s\n", label, hexbuf_size, hexbuf);
}
/* Format of an Emacs portable dump file. All offsets are relative to
char magic[sizeof (dump_magic)];
/* Associated Emacs binary. */
- unsigned char fingerprint[32];
+ unsigned char fingerprint[sizeof fingerprint];
/* Relocation table for the dump file; each entry is a
struct dump_reloc. */