Blame src/libotutil/ot-checksum-utils.h

rpm-build 0fba15
/*
rpm-build 0fba15
 * Copyright (C) 2011 Colin Walters <walters@verbum.org>.
rpm-build 0fba15
 *
rpm-build 0fba15
 * SPDX-License-Identifier: LGPL-2.0+
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is free software; you can redistribute it and/or
rpm-build 0fba15
 * modify it under the terms of the GNU Lesser General Public
rpm-build 0fba15
 * License as published by the Free Software Foundation; either
rpm-build 0fba15
 * version 2 of the License, or (at your option) any later version.
rpm-build 0fba15
 *
rpm-build 0fba15
 * This library is distributed in the hope that it will be useful,
rpm-build 0fba15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 0fba15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 0fba15
 * Lesser General Public License for more details.
rpm-build 0fba15
 *
rpm-build 0fba15
 * You should have received a copy of the GNU Lesser General Public
rpm-build 0fba15
 * License along with this library; if not, write to the
rpm-build 0fba15
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
rpm-build 0fba15
 * Boston, MA 02111-1307, USA.
rpm-build 0fba15
 *
rpm-build 0fba15
 * Author: Colin Walters <walters@verbum.org>
rpm-build 0fba15
 */
rpm-build 0fba15
rpm-build 0fba15
#pragma once
rpm-build 0fba15
rpm-build 0fba15
#include "libglnx.h"
rpm-build 0fba15
rpm-build 0fba15
G_BEGIN_DECLS
rpm-build 0fba15
rpm-build 0fba15
void ot_bin2hex (char *out_buf, const guint8 *inbuf, gsize len);
rpm-build 0fba15
rpm-build 0fba15
guchar *ot_csum_from_gchecksum (GChecksum *checksum);
rpm-build 0fba15
rpm-build 0fba15
struct OtChecksum {
rpm-build 0fba15
  gboolean initialized;
rpm-build 0fba15
  guint uints[2];
rpm-build 0fba15
  gpointer data[2];
rpm-build 0fba15
};
rpm-build 0fba15
typedef struct OtChecksum OtChecksum;
rpm-build 0fba15
rpm-build 0fba15
/* Same as OSTREE_SHA256_DIGEST_LEN, but this header can't depend on that */
rpm-build 0fba15
#define _OSTREE_SHA256_DIGEST_LEN (32)
rpm-build 0fba15
#if defined(OSTREE_SHA256_DIGEST_LEN) && _OSTREE_SHA256_DIGEST_LEN != OSTREE_SHA256_DIGEST_LEN
rpm-build 0fba15
#error Mismatched OSTREE_SHA256_DIGEST_LEN
rpm-build 0fba15
#endif
rpm-build 0fba15
/* See above */
rpm-build 0fba15
#define _OSTREE_SHA256_STRING_LEN (64)
rpm-build 0fba15
#if defined(OSTREE_SHA256_STRING_LEN) && _OSTREE_SHA256_STRING_LEN != OSTREE_SHA256_STRING_LEN
rpm-build 0fba15
#error Mismatched OSTREE_SHA256_STRING_LEN
rpm-build 0fba15
#endif
rpm-build 0fba15
rpm-build 0fba15
void ot_checksum_init (OtChecksum *checksum);
rpm-build 0fba15
void ot_checksum_update (OtChecksum *checksum,
rpm-build 0fba15
                         const guint8   *buf,
rpm-build 0fba15
                         size_t          len);
rpm-build 0fba15
static inline void
rpm-build 0fba15
ot_checksum_update_bytes (OtChecksum *checksum,
rpm-build 0fba15
                          GBytes     *buf)
rpm-build 0fba15
{
rpm-build 0fba15
  gsize len;
rpm-build 0fba15
  const guint8 *bufdata = g_bytes_get_data (buf, &len;;
rpm-build 0fba15
  ot_checksum_update (checksum, bufdata, len);
rpm-build 0fba15
}
rpm-build 0fba15
void ot_checksum_get_digest (OtChecksum *checksum,
rpm-build 0fba15
                             guint8      *buf,
rpm-build 0fba15
                             size_t       buflen);
rpm-build 0fba15
void ot_checksum_get_hexdigest (OtChecksum *checksum,
rpm-build 0fba15
                                char           *buf,
rpm-build 0fba15
                                size_t          buflen);
rpm-build 0fba15
void ot_checksum_clear (OtChecksum *checksum);
rpm-build 0fba15
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(OtChecksum, ot_checksum_clear)
rpm-build 0fba15
rpm-build 0fba15
gboolean ot_gio_write_update_checksum (GOutputStream  *out,
rpm-build 0fba15
                                       gconstpointer   data,
rpm-build 0fba15
                                       gsize           len,
rpm-build 0fba15
                                       gsize          *out_bytes_written,
rpm-build 0fba15
                                       OtChecksum     *checksum,
rpm-build 0fba15
                                       GCancellable   *cancellable,
rpm-build 0fba15
                                       GError        **error);
rpm-build 0fba15
rpm-build 0fba15
gboolean ot_gio_splice_get_checksum (GOutputStream  *out,
rpm-build 0fba15
                                     GInputStream   *in,
rpm-build 0fba15
                                     guchar        **out_csum,
rpm-build 0fba15
                                     GCancellable   *cancellable,
rpm-build 0fba15
                                     GError        **error);
rpm-build 0fba15
rpm-build 0fba15
gboolean ot_gio_splice_update_checksum (GOutputStream  *out,
rpm-build 0fba15
                                        GInputStream   *in,
rpm-build 0fba15
                                        OtChecksum     *checksum,
rpm-build 0fba15
                                        GCancellable   *cancellable,
rpm-build 0fba15
                                        GError        **error);
rpm-build 0fba15
rpm-build 0fba15
char * ot_checksum_file_at (int             dfd,
rpm-build 0fba15
                            const char     *path,
rpm-build 0fba15
                            GChecksumType   checksum_type,
rpm-build 0fba15
                            GCancellable   *cancellable,
rpm-build 0fba15
                            GError        **error);
rpm-build 0fba15
rpm-build 0fba15
G_END_DECLS