diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index f1e1fc97..92311418 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -972,9 +972,17 @@ ostree_object_name_deserialize (GVariant *variant, *out_objtype = (OstreeObjectType)objtype_u32; } -static void -checksum_to_bytes (const char *checksum, - guchar *buf) +/** + * ostree_checksum_inplace_to_bytes: + * @checksum: a SHA256 string + * @buf: Output buffer with at least 32 bytes of space + * + * Convert @checksum from a string to binary in-place, without + * allocating memory. Use this function in hot code paths. + */ +void +ostree_checksum_inplace_to_bytes (const char *checksum, + guchar *buf) { guint i; guint j; @@ -1000,7 +1008,7 @@ guchar * ostree_checksum_to_bytes (const char *checksum) { guchar *ret = g_malloc (32); - checksum_to_bytes (checksum, ret); + ostree_checksum_inplace_to_bytes (checksum, ret); return ret; } @@ -1008,7 +1016,7 @@ GVariant * ostree_checksum_to_bytes_v (const char *checksum) { guchar result[32]; - checksum_to_bytes (checksum, result); + ostree_checksum_inplace_to_bytes (checksum, result); return ot_gvariant_new_bytearray ((guchar*)result, 32); } diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h index 6f892659..a28b0ca8 100644 --- a/src/libostree/ostree-core.h +++ b/src/libostree/ostree-core.h @@ -132,6 +132,9 @@ char * ostree_checksum_from_bytes_v (GVariant *bytes); void ostree_checksum_inplace_from_bytes (const guchar *bytes, char *buf); +void ostree_checksum_inplace_to_bytes (const char *checksum, + guchar *buf); + const guchar *ostree_checksum_bytes_peek (GVariant *bytes); int ostree_cmp_checksum_bytes (const guchar *a, const guchar *b);