summaryrefslogtreecommitdiff
path: root/src/libotutil/ot-checksum-utils.h
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2017-10-06 16:38:08 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2017-10-10 21:25:40 +0000
commit1c9975cbd12b05927e1969e5675479aea437188b (patch)
treedf0cf969cd9f8119b31a6508804900f63a554953 /src/libotutil/ot-checksum-utils.h
parentbba7eb80699cb789f31914bc98fc338c46237b37 (diff)
downloadostree-1c9975cbd12b05927e1969e5675479aea437188b.tar.gz
lib: Add a lighter weight internal checksum wrapper
The faster (OpenSSL/GnuTLS) code lived in a `GInputStream` wrapper, and that adds a lot of weight (GObject + vtable calls). Move it into a simple autoptr-struct wrapper, and use it in the metadata path, so we're now using the faster checksums there too. This also drops a malloc there as the new API does hexdigest in place to a buffer. Prep for more work in the commit path to avoid `GInputStream` for local file commits, and ["adopting" files](https://github.com/ostreedev/ostree/pull/1255). Closes: #1256 Approved by: jlebon
Diffstat (limited to 'src/libotutil/ot-checksum-utils.h')
-rw-r--r--src/libotutil/ot-checksum-utils.h37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/libotutil/ot-checksum-utils.h b/src/libotutil/ot-checksum-utils.h
index a0e72dbc..abf3c6db 100644
--- a/src/libotutil/ot-checksum-utils.h
+++ b/src/libotutil/ot-checksum-utils.h
@@ -21,7 +21,7 @@
#pragma once
-#include <gio/gio.h>
+#include "libglnx.h"
G_BEGIN_DECLS
@@ -29,11 +29,42 @@ void ot_bin2hex (char *out_buf, const guint8 *inbuf, gsize len);
guchar *ot_csum_from_gchecksum (GChecksum *checksum);
+struct OtChecksum {
+ gboolean initialized;
+ guint uints[2];
+ gpointer data[2];
+};
+typedef struct OtChecksum OtChecksum;
+
+/* Same as OSTREE_SHA256_DIGEST_LEN, but this header can't depend on that */
+#define _OSTREE_SHA256_DIGEST_LEN (32)
+#if defined(OSTREE_SHA256_DIGEST_LEN) && _OSTREE_SHA256_DIGEST_LEN != OSTREE_SHA256_DIGEST_LEN
+#error Mismatched OSTREE_SHA256_DIGEST_LEN
+#endif
+/* See above */
+#define _OSTREE_SHA256_STRING_LEN (64)
+#if defined(OSTREE_SHA256_STRING_LEN) && _OSTREE_SHA256_STRING_LEN != OSTREE_SHA256_STRING_LEN
+#error Mismatched OSTREE_SHA256_STRING_LEN
+#endif
+
+void ot_checksum_init (OtChecksum *checksum);
+void ot_checksum_update (OtChecksum *checksum,
+ const guint8 *buf,
+ size_t len);
+void ot_checksum_get_digest (OtChecksum *checksum,
+ guint8 *buf,
+ size_t buflen);
+void ot_checksum_get_hexdigest (OtChecksum *checksum,
+ char *buf,
+ size_t buflen);
+void ot_checksum_clear (OtChecksum *checksum);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OtChecksum, ot_checksum_clear)
+
gboolean ot_gio_write_update_checksum (GOutputStream *out,
gconstpointer data,
gsize len,
gsize *out_bytes_written,
- GChecksum *checksum,
+ OtChecksum *checksum,
GCancellable *cancellable,
GError **error);
@@ -45,7 +76,7 @@ gboolean ot_gio_splice_get_checksum (GOutputStream *out,
gboolean ot_gio_splice_update_checksum (GOutputStream *out,
GInputStream *in,
- GChecksum *checksum,
+ OtChecksum *checksum,
GCancellable *cancellable,
GError **error);