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

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