And use it internally. This way it's a bit less magical.
ostree_cmp_checksum_bytes (const guchar *a,
const guchar *b)
{
- return memcmp (a, b, 32);
+ return memcmp (a, b, OSTREE_SHA256_DIGEST_LEN);
}
/**
guint i;
guint j;
- for (i = 0, j = 0; i < 32; i += 1, j += 2)
+ for (i = 0, j = 0; i < OSTREE_SHA256_DIGEST_LEN; i += 1, j += 2)
{
gint big, little;
guchar *
ostree_checksum_to_bytes (const char *checksum)
{
- guchar *ret = g_malloc (32);
+ guchar *ret = g_malloc (OSTREE_SHA256_DIGEST_LEN);
ostree_checksum_inplace_to_bytes (checksum, ret);
return ret;
}
GVariant *
ostree_checksum_to_bytes_v (const char *checksum)
{
- guchar result[32];
+ guchar result[OSTREE_SHA256_DIGEST_LEN];
ostree_checksum_inplace_to_bytes (checksum, result);
- return ot_gvariant_new_bytearray ((guchar*)result, 32);
+ return ot_gvariant_new_bytearray ((guchar*)result, OSTREE_SHA256_DIGEST_LEN);
}
/**
static const gchar hexchars[] = "0123456789abcdef";
guint i, j;
- for (i = 0, j = 0; i < 32; i++, j += 2)
+ for (i = 0, j = 0; i < OSTREE_SHA256_DIGEST_LEN; i++, j += 2)
{
guchar byte = csum[i];
buf[j] = hexchars[byte >> 4];
* a lot easier to reuse GLib's base64 encoder and postprocess it
* to replace the '/' with '_'.
*/
- outlen = g_base64_encode_step (csum, 32, FALSE, tmpbuf, &state, &save);
+ outlen = g_base64_encode_step (csum, OSTREE_SHA256_DIGEST_LEN, FALSE, tmpbuf, &state, &save);
outlen += g_base64_encode_close (FALSE, tmpbuf+outlen, &state, &save);
g_assert (outlen == 44);
gsize n_elts;
const guchar *ret;
ret = g_variant_get_fixed_array (bytes, &n_elts, 1);
- if (G_UNLIKELY (n_elts != 32))
+ if (G_UNLIKELY (n_elts != OSTREE_SHA256_DIGEST_LEN))
return NULL;
return ret;
}
const char *to,
const char *target)
{
- guint8 csum_to[32];
+ guint8 csum_to[OSTREE_SHA256_DIGEST_LEN];
char to_b64[44];
- guint8 csum_to_copy[32];
+ guint8 csum_to_copy[OSTREE_SHA256_DIGEST_LEN];
GString *ret = g_string_new ("deltas/");
ostree_checksum_inplace_to_bytes (to, csum_to);
ostree_checksum_b64_inplace_from_bytes (csum_to, to_b64);
ostree_checksum_b64_inplace_to_bytes (to_b64, csum_to_copy);
- g_assert (memcmp (csum_to, csum_to_copy, 32) == 0);
+ g_assert (memcmp (csum_to, csum_to_copy, OSTREE_SHA256_DIGEST_LEN) == 0);
if (from != NULL)
{
- guint8 csum_from[32];
+ guint8 csum_from[OSTREE_SHA256_DIGEST_LEN];
char from_b64[44];
ostree_checksum_inplace_to_bytes (from, csum_from);
*/
#define OSTREE_MAX_RECURSION (256)
+#define OSTREE_SHA256_DIGEST_LEN (32)
+
/**
* OstreeObjectType:
* @OSTREE_OBJECT_TYPE_FILE: Content; regular file, symbolic link
for (i = 0; i < sorted_keys->len; i++)
{
- guint8 csum[32];
+ guint8 csum[OSTREE_SHA256_DIGEST_LEN];
const char *e_checksum = sorted_keys->pdata[i];
GString *buffer = g_string_new (NULL);
ostree_checksum_inplace_to_bytes (e_checksum, csum);
- g_string_append_len (buffer, (char*)csum, 32);
+ g_string_append_len (buffer, (char*)csum, sizeof (csum));
e_size = g_hash_table_lookup (self->object_sizes, e_checksum);
_ostree_write_varuint64 (buffer, e_size->archived);
} FetchStaticDeltaData;
typedef struct {
- guchar csum[32];
+ guchar csum[OSTREE_SHA256_DIGEST_LEN];
OstreeObjectType objtype;
guint recursion_depth;
} ScanObjectQueueData;
OstreeObjectType objtype,
guint recursion_depth)
{
- guchar buf[32];
+ guchar buf[OSTREE_SHA256_DIGEST_LEN];
ostree_checksum_inplace_to_bytes (csum, buf);
queue_scan_one_metadata_object_c (pull_data, buf, objtype, recursion_depth);
}
{
const char *delta;
GVariant *csum_v = NULL;
- guchar *csum_data = g_malloc (32);
+ guchar *csum_data = g_malloc (OSTREE_SHA256_DIGEST_LEN);
g_autoptr(GVariant) ref = g_variant_get_child_value (deltas, i);
g_variant_get_child (ref, 0, "&s", &delta);
GVariant *serialized_key = objects->pdata[i];
OstreeObjectType objtype;
const char *checksum;
- guint8 csum[32];
+ guint8 csum[OSTREE_SHA256_DIGEST_LEN];
guint8 objtype_v;
ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
{ gsize mode_offset, xattr_offset, from_csum_offset;
gboolean reading_payload = TRUE;
- guchar source_csum[32];
+ guchar source_csum[OSTREE_SHA256_DIGEST_LEN];
guint i;
write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs,
g_ptr_array_add (current_part->objects, ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_FILE));
{ gsize mode_offset, xattr_offset;
- guchar source_csum[32];
+ guchar source_csum[OSTREE_SHA256_DIGEST_LEN];
write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs,
&mode_offset, &xattr_offset);
cancellable, error))
goto out;
- checksum_bytes = g_bytes_new (part_checksum, 32);
+ checksum_bytes = g_bytes_new (part_checksum, OSTREE_SHA256_DIGEST_LEN);
objtype_checksum_array = objtype_checksum_array_new (part_builder->objects);
delta_part_header = g_variant_new ("(u@aytt@ay)",
OSTREE_DELTAPART_VERSION,
g_autofree char *buf = g_strconcat (name1, name2, NULL);
GString *out = g_string_new ("");
char checksum[65];
- guchar csum[32];
+ guchar csum[OSTREE_SHA256_DIGEST_LEN];
const char *dash = strchr (buf, '-');
ostree_checksum_b64_inplace_to_bytes (buf, csum);