Skip to content

Commit

Permalink
fixup! lib: Add a lighter weight internal checksum wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Oct 6, 2017
1 parent af58622 commit dfc9079
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/libotutil/ot-checksum-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ot_bin2hex (char *out_buf, const guint8 *inbuf, gsize len)
* aka http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html
*/
typedef struct {
gboolean initialized;
#if defined(HAVE_OPENSSL)
EVP_MD_CTX *checksum;
#elif defined(HAVE_GNUTLS)
Expand All @@ -68,6 +69,7 @@ void
ot_checksum_init (OtChecksum *checksum)
{
OtRealChecksum *real = (OtRealChecksum*)checksum;
g_return_if_fail (!real->initialized);
#if defined(HAVE_OPENSSL)
real->checksum = EVP_MD_CTX_create ();
g_assert (real->checksum);
Expand All @@ -79,6 +81,7 @@ ot_checksum_init (OtChecksum *checksum)
real->checksum = g_checksum_new (G_CHECKSUM_SHA256);
real->digest_len = g_checksum_type_get_length (G_CHECKSUM_SHA256);
#endif
real->initialized = TRUE;
}

void
Expand All @@ -87,6 +90,7 @@ ot_checksum_update (OtChecksum *checksum,
size_t len)
{
OtRealChecksum *real = (OtRealChecksum*)checksum;
g_return_if_fail (real->initialized);
#if defined(HAVE_OPENSSL)
g_assert (EVP_DigestUpdate (real->checksum, buf, len));
#elif defined(HAVE_GNUTLS)
Expand All @@ -102,6 +106,7 @@ ot_checksum_get_hexdigest (OtChecksum *checksum,
size_t buflen)
{
OtRealChecksum *real = (OtRealChecksum*)checksum;
g_return_if_fail (real->initialized);
/* OSTREE_SHA256_STRING_LEN */
g_assert_cmpint (buflen, ==, _OSTREE_SHA256_STRING_LEN+1);
#if defined(HAVE_OPENSSL)
Expand All @@ -118,6 +123,7 @@ ot_checksum_get_hexdigest (OtChecksum *checksum,
g_checksum_get_digest (real->checksum, digest_buf, &digest_len);
#endif
ot_bin2hex (buf, (guint8*)digest_buf, digest_len);
real->initialized = FALSE;
}

void
Expand Down
3 changes: 2 additions & 1 deletion src/libotutil/ot-checksum-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ void ot_bin2hex (char *out_buf, const guint8 *inbuf, gsize len);
guchar *ot_csum_from_gchecksum (GChecksum *checksum);

struct OtChecksum {
gpointer data[2];
gboolean initialized;
guint uints[2];
gpointer data[2];
};
typedef struct OtChecksum OtChecksum;

Expand Down

0 comments on commit dfc9079

Please sign in to comment.