Skip to content

Commit

Permalink
Update: Support older versions of Jansson
Browse files Browse the repository at this point in the history
introduce _cjson_json_stringn so cjose compiles against Jansson 2.6
  • Loading branch information
linuxwolf authored Jul 28, 2016
2 parents e968f21 + e198f93 commit d9d3d43
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/include/jwk_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ bool cjose_jwk_hkdf(
unsigned int okm_len,
cjose_err *err);

json_t *_cjose_json_stringn(const char *value, size_t len);

#endif // SRC_JWK_INT_H
10 changes: 5 additions & 5 deletions src/jwk.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ static bool _oct_private_fields(
return false;
}

field = json_stringn(k, klen);
field = _cjose_json_stringn(k, klen);
cjose_get_dealloc()(k);
k = NULL;
if (!field)
Expand Down Expand Up @@ -627,7 +627,7 @@ static bool _EC_public_fields(
{
goto _ec_to_string_cleanup;
}
field = json_stringn(b64u, len);
field = _cjose_json_stringn(b64u, len);
if (!field)
{
CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY);
Expand All @@ -647,7 +647,7 @@ static bool _EC_public_fields(
{
goto _ec_to_string_cleanup;
}
field = json_stringn(b64u, len);
field = _cjose_json_stringn(b64u, len);
if (!field)
{
CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY);
Expand Down Expand Up @@ -721,7 +721,7 @@ static bool _EC_private_fields(
{
goto _ec_to_string_cleanup;
}
field = json_stringn(b64u, len);
field = _cjose_json_stringn(b64u, len);
if (!field)
{
CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY);
Expand Down Expand Up @@ -1007,7 +1007,7 @@ static inline bool _RSA_json_field(
{
goto RSA_json_field_cleanup;
}
field = json_stringn(b64u, b64ulen);
field = _cjose_json_stringn(b64u, b64ulen);
if (!field)
{
CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY);
Expand Down
12 changes: 12 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <jansson.h>
#include <openssl/crypto.h>
#include <stdlib.h>
#include <string.h>

static cjose_alloc_fn_t _alloc;
static cjose_realloc_fn_t _realloc;
Expand Down Expand Up @@ -89,3 +90,14 @@ char *_cjose_strndup(const char *str, ssize_t len, cjose_err *err)

return result;
}

json_t *_cjose_json_stringn(const char *value, size_t len) {
#if JANSSON_VERSION_HEX <= 0x020600
char *s = strndup(value, len);
json_t *r = json_string(s);
free(s);
return r;
#else
return json_stringn(value, len);
#endif
}

0 comments on commit d9d3d43

Please sign in to comment.