You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mi...@apache.org on 2018/09/01 22:08:50 UTC

svn commit: r1839860 - in /apr/apr-util/branches/1.7.x: include/apr_jose.h jose/apr_jose.c jose/apr_jose_decode.c test/testjose.c

Author: minfrin
Date: Sat Sep  1 22:08:49 2018
New Revision: 1839860

URL: http://svn.apache.org/viewvc?rev=1839860&view=rev
Log:
Backport r1839859.

apr_jose: Change the signature of apr_jose_make() so that it is no
longer neceessary to pass in a pointer to a NULL pointer, but keep
supporting the option to pre-allocate structures.

Modified:
    apr/apr-util/branches/1.7.x/include/apr_jose.h
    apr/apr-util/branches/1.7.x/jose/apr_jose.c
    apr/apr-util/branches/1.7.x/jose/apr_jose_decode.c
    apr/apr-util/branches/1.7.x/test/testjose.c

Modified: apr/apr-util/branches/1.7.x/include/apr_jose.h
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/include/apr_jose.h?rev=1839860&r1=1839859&r2=1839860&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/include/apr_jose.h (original)
+++ apr/apr-util/branches/1.7.x/include/apr_jose.h Sat Sep  1 22:08:49 2018
@@ -923,8 +923,9 @@ APU_DECLARE(apu_err_t *) apr_jose_error(
  *   be reused.
  * @param type the type of structure to create.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_make(apr_jose_t **jose, apr_jose_type_e type,
+APU_DECLARE(apr_jose_t *) apr_jose_make(apr_jose_t *jose, apr_jose_type_e type,
         apr_pool_t *pool);
 
 /**
@@ -934,8 +935,9 @@ APU_DECLARE(apr_status_t) apr_jose_make(
  *   be reused.
  * @param key the json representing the key. May be NULL.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jwk_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwk_make(apr_jose_t *jose,
         apr_json_value_t *key, apr_pool_t *pool);
 
 /**
@@ -945,8 +947,9 @@ APU_DECLARE(apr_status_t) apr_jose_jwk_m
  *   be reused.
  * @param keys the array of keys in JSON format. May be NULL.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jwks_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwks_make(apr_jose_t *jose,
         apr_json_value_t *keys, apr_pool_t *pool);
 
 /**
@@ -956,9 +959,10 @@ APU_DECLARE(apr_status_t) apr_jose_jwks_
  * @param header the unprotected header.
  * @param protected the protected header.
  * @param pool the pool to use.
+ * @return The apr_jose_signature_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_signature_make(
-        apr_jose_signature_t **signature, apr_json_value_t *header,
+APU_DECLARE(apr_jose_signature_t *) apr_jose_signature_make(
+        apr_jose_signature_t *signature, apr_json_value_t *header,
         apr_json_value_t *protected, apr_pool_t *pool);
 
 /**
@@ -967,8 +971,9 @@ APU_DECLARE(apr_status_t) apr_jose_signa
  * @param recipient the result.
  * @param unprotected the unprotected header.
  * @param pool the pool to use.
+ * @return The apr_jose_recipient_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_recipient_make(apr_jose_recipient_t **recipient,
+APU_DECLARE(apr_jose_recipient_t *) apr_jose_recipient_make(apr_jose_recipient_t *recipient,
         apr_json_value_t *unprotected, apr_pool_t *pool);
 
 /**
@@ -978,8 +983,9 @@ APU_DECLARE(apr_status_t) apr_jose_recip
  * @param unprotected the unprotected shared header.
  * @param protected the protected header.
  * @param pool the pool to use.
+ * @return The apr_jose_encryption_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_encryption_make(apr_jose_encryption_t **encryption,
+APU_DECLARE(apr_jose_encryption_t *) apr_jose_encryption_make(apr_jose_encryption_t *encryption,
         apr_json_value_t *unprotected, apr_json_value_t *protected,
         apr_pool_t *pool);
 
@@ -993,8 +999,9 @@ APU_DECLARE(apr_status_t) apr_jose_encry
  * @param encryption the encryption structure.
  * @param payload the JOSE payload to encrypt.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jwe_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwe_make(apr_jose_t *jose,
         apr_jose_recipient_t *recipient, apr_array_header_t *recipients,
         apr_jose_encryption_t *encryption, apr_jose_t *payload,
         apr_pool_t *pool);
@@ -1009,8 +1016,9 @@ APU_DECLARE(apr_status_t) apr_jose_jwe_m
  * @param encryption the encryption structure.
  * @param payload the JOSE payload to encrypt.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jwe_json_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwe_json_make(apr_jose_t *jose,
         apr_jose_recipient_t *recipient,
         apr_array_header_t *recipients, apr_jose_encryption_t *encryption,
         apr_jose_t *payload, apr_pool_t *pool);
@@ -1024,8 +1032,9 @@ APU_DECLARE(apr_status_t) apr_jose_jwe_j
  * @param signatures array of header / protected header / signature used with general JSON syntax.
  * @param payload the payload to be wrapped by this JWS.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jws_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jws_make(apr_jose_t *jose,
         apr_jose_signature_t *signature, apr_array_header_t *signatures,
         apr_jose_t *payload, apr_pool_t *pool);
 
@@ -1038,8 +1047,9 @@ APU_DECLARE(apr_status_t) apr_jose_jws_m
  * @param signatures array of header / protected header / signature used with general JSON syntax.
  * @param payload the payload to be wrapped by this JWS.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jws_json_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jws_json_make(apr_jose_t *jose,
         apr_jose_signature_t *signature, apr_array_header_t *signatures,
         apr_jose_t *payload, apr_pool_t *pool);
 
@@ -1053,8 +1063,9 @@ APU_DECLARE(apr_status_t) apr_jose_jws_j
  *   be reused.
  * @param claims the claims to sign.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_jwt_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwt_make(apr_jose_t *jose,
         apr_json_value_t *claims, apr_pool_t *pool);
 
 /**
@@ -1066,8 +1077,9 @@ APU_DECLARE(apr_status_t) apr_jose_jwt_m
  * @param in the plaintext to sign.
  * @param inlen length of the plaintext.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_data_make(apr_jose_t **jose, const char *typ,
+APU_DECLARE(apr_jose_t *) apr_jose_data_make(apr_jose_t *jose, const char *typ,
         const unsigned char *in, apr_size_t inlen, apr_pool_t *pool);
 
 /**
@@ -1080,8 +1092,9 @@ APU_DECLARE(apr_status_t) apr_jose_data_
  * @param in the UTF-8 encoded text string.
  * @param inlen length of the UTF-8 encoded text string.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_text_make(apr_jose_t **jose, const char *cty,
+APU_DECLARE(apr_jose_t *) apr_jose_text_make(apr_jose_t *jose, const char *cty,
         const char *in, apr_size_t inlen, apr_pool_t *pool);
 
 /**
@@ -1092,8 +1105,9 @@ APU_DECLARE(apr_status_t) apr_jose_text_
  * @param cty the content type.
  * @param json the json object to add.
  * @param pool pool used to allocate the result from.
+ * @return The apr_jose_t is returned.
  */
-APU_DECLARE(apr_status_t) apr_jose_json_make(apr_jose_t **jose, const char *cty,
+APU_DECLARE(apr_jose_t *) apr_jose_json_make(apr_jose_t *jose, const char *cty,
         apr_json_value_t *json, apr_pool_t *pool);
 
 /**

Modified: apr/apr-util/branches/1.7.x/jose/apr_jose.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/jose/apr_jose.c?rev=1839860&r1=1839859&r2=1839860&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/jose/apr_jose.c (original)
+++ apr/apr-util/branches/1.7.x/jose/apr_jose.c Sat Sep  1 22:08:49 2018
@@ -21,141 +21,138 @@ APU_DECLARE(apu_err_t *) apr_jose_error(
     return &jose->result;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_make(apr_jose_t **jose, apr_jose_type_e type,
+APU_DECLARE(apr_jose_t *) apr_jose_make(apr_jose_t *jose, apr_jose_type_e type,
         apr_pool_t *pool)
 {
-    apr_jose_t *j;
 
-    if (*jose) {
-        j = *jose;
-    } else {
-        *jose = j = apr_pcalloc(pool, sizeof(apr_jose_t));
-        if (!j) {
-            return APR_ENOMEM;
+    if (!jose) {
+        jose = apr_pcalloc(pool, sizeof(apr_jose_t));
+        if (!jose) {
+            return NULL;
         }
     }
 
-    j->pool = pool;
-    j->type = type;
+    jose->pool = pool;
+    jose->type = type;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_data_make(apr_jose_t **jose, const char *typ,
+APU_DECLARE(apr_jose_t *) apr_jose_data_make(apr_jose_t *jose, const char *typ,
         const unsigned char *in, apr_size_t inlen, apr_pool_t *pool)
 {
-    apr_jose_t *j;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_DATA, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_DATA, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    j->typ = typ;
-    j->jose.data = apr_palloc(pool, sizeof(apr_jose_data_t));
-    if (!j->jose.data) {
-        return APR_ENOMEM;
+    jose->typ = typ;
+    jose->jose.data = apr_palloc(pool, sizeof(apr_jose_data_t));
+    if (!jose->jose.data) {
+        return NULL;
     }
-    j->jose.data->data = in;
-    j->jose.data->len = inlen;
+    jose->jose.data->data = in;
+    jose->jose.data->len = inlen;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_json_make(apr_jose_t **jose, const char *cty,
+APU_DECLARE(apr_jose_t *) apr_jose_json_make(apr_jose_t *jose, const char *cty,
         apr_json_value_t *json, apr_pool_t *pool)
 {
-    apr_jose_t *j;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JSON, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JSON, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    j->cty = cty;
-    j->jose.json = apr_palloc(pool, sizeof(apr_jose_json_t));
-    if (!j->jose.json) {
-        return APR_ENOMEM;
+    jose->cty = cty;
+    jose->jose.json = apr_palloc(pool, sizeof(apr_jose_json_t));
+    if (!jose->jose.json) {
+        return NULL;
     }
-    j->jose.json->json = json;
+    jose->jose.json->json = json;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_signature_make(
-        apr_jose_signature_t **signature, apr_json_value_t *header,
+APU_DECLARE(apr_jose_signature_t *) apr_jose_signature_make(
+        apr_jose_signature_t *signature, apr_json_value_t *header,
         apr_json_value_t *protected, apr_pool_t *pool)
 {
-    apr_jose_signature_t *s;
 
-    *signature = s = apr_pcalloc(pool, sizeof(apr_jose_signature_t));
-    if (!s) {
-        return APR_ENOMEM;
+    if (!signature) {
+        signature = apr_pcalloc(pool, sizeof(apr_jose_signature_t));
+        if (!signature) {
+            return NULL;
+        }
     }
 
-    s->header = header;
-    s->protected_header = protected;
+    signature->header = header;
+    signature->protected_header = protected;
 
-    return APR_SUCCESS;
+    return signature;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_recipient_make(
-        apr_jose_recipient_t **recipient, apr_json_value_t *header,
+APU_DECLARE(apr_jose_recipient_t *) apr_jose_recipient_make(
+        apr_jose_recipient_t *recipient, apr_json_value_t *header,
         apr_pool_t *pool)
 {
-    apr_jose_recipient_t *r;
 
-    *recipient = r = apr_pcalloc(pool, sizeof(apr_jose_recipient_t));
-    if (!r) {
-        return APR_ENOMEM;
+    if (!recipient) {
+        recipient = apr_pcalloc(pool, sizeof(apr_jose_recipient_t));
+        if (!recipient) {
+            return NULL;
+        }
     }
 
-    r->header = header;
+    recipient->header = header;
 
-    return APR_SUCCESS;
+    return recipient;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_encryption_make(
-        apr_jose_encryption_t **encryption, apr_json_value_t *header,
+APU_DECLARE(apr_jose_encryption_t *) apr_jose_encryption_make(
+        apr_jose_encryption_t *encryption, apr_json_value_t *header,
         apr_json_value_t *protected_header, apr_pool_t *pool)
 {
-    apr_jose_encryption_t *e;
 
-    *encryption = e = apr_pcalloc(pool, sizeof(apr_jose_encryption_t));
-    if (!e) {
-        return APR_ENOMEM;
+    if (!encryption) {
+        encryption = apr_pcalloc(pool, sizeof(apr_jose_encryption_t));
+        if (!encryption) {
+            return NULL;
+        }
     }
 
-    e->unprotected = header;
-    e->protected = protected_header;
+    encryption->unprotected = header;
+    encryption->protected = protected_header;
 
-    return APR_SUCCESS;
+    return encryption;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jwe_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwe_make(apr_jose_t *jose,
         apr_jose_recipient_t *recipient, apr_array_header_t *recipients,
         apr_jose_encryption_t *encryption, apr_jose_t *payload,
         apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jwe_t *jwe;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWE, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWE, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    j->cty = payload->cty;
+    jose->cty = payload->cty;
 
-    jwe = j->jose.jwe = apr_palloc(pool, sizeof(apr_jose_jwe_t));
+    jwe = jose->jose.jwe = apr_palloc(pool, sizeof(apr_jose_jwe_t));
     if (!jwe) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jwe->recipient = recipient;
@@ -163,31 +160,30 @@ APU_DECLARE(apr_status_t) apr_jose_jwe_m
     jwe->encryption = encryption;
     jwe->payload = payload;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jwe_json_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwe_json_make(apr_jose_t *jose,
         apr_jose_recipient_t *recipient, apr_array_header_t *recipients,
         apr_jose_encryption_t *encryption, apr_jose_t *payload,
         apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jwe_t *jwe;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWE_JSON, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWE_JSON, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
     if (payload) {
-        j->cty = payload->cty;
+        jose->cty = payload->cty;
     }
 
-    jwe = j->jose.jwe = apr_palloc(pool, sizeof(apr_jose_jwe_t));
+    jwe = jose->jose.jwe = apr_palloc(pool, sizeof(apr_jose_jwe_t));
     if (!jwe) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jwe->recipient = recipient;
@@ -195,159 +191,153 @@ APU_DECLARE(apr_status_t) apr_jose_jwe_j
     jwe->encryption = encryption;
     jwe->payload = payload;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jwk_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwk_make(apr_jose_t *jose,
         apr_json_value_t *key, apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jwk_t *jwk;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWK, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWK, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    jwk = j->jose.jwk = apr_palloc(pool, sizeof(apr_jose_jwk_t));
+    jwk = jose->jose.jwk = apr_palloc(pool, sizeof(apr_jose_jwk_t));
     if (!jwk) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jwk->key = key;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jwks_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jwks_make(apr_jose_t *jose,
         apr_json_value_t *keys, apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jwks_t *jwks;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWKS, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWKS, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    jwks = j->jose.jwks = apr_palloc(pool, sizeof(apr_jose_jwks_t));
+    jwks = jose->jose.jwks = apr_palloc(pool, sizeof(apr_jose_jwks_t));
     if (!jwks) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jwks->keys = keys;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jws_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jws_make(apr_jose_t *jose,
         apr_jose_signature_t *signature, apr_array_header_t *signatures,
         apr_jose_t *payload, apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jws_t *jws;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWS, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWS, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
     if (payload) {
-        j->cty = payload->cty;
+        jose->cty = payload->cty;
     }
 
-    jws = j->jose.jws = apr_pcalloc(pool, sizeof(apr_jose_jws_t));
+    jws = jose->jose.jws = apr_pcalloc(pool, sizeof(apr_jose_jws_t));
     if (!jws) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jws->signature = signature;
     jws->signatures = signatures;
     jws->payload = payload;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jws_json_make(apr_jose_t **jose,
+APU_DECLARE(apr_jose_t *) apr_jose_jws_json_make(apr_jose_t *jose,
         apr_jose_signature_t *signature, apr_array_header_t *signatures,
         apr_jose_t *payload, apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jws_t *jws;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWS_JSON, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWS_JSON, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
     if (payload) {
-        j->cty = payload->cty;
+        jose->cty = payload->cty;
     }
 
-    jws = j->jose.jws = apr_pcalloc(pool, sizeof(apr_jose_jws_t));
+    jws = jose->jose.jws = apr_pcalloc(pool, sizeof(apr_jose_jws_t));
     if (!jws) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jws->signature = signature;
     jws->signatures = signatures;
     jws->payload = payload;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_jwt_make(apr_jose_t **jose, apr_json_value_t *claims,
+APU_DECLARE(apr_jose_t *) apr_jose_jwt_make(apr_jose_t *jose, apr_json_value_t *claims,
         apr_pool_t *pool)
 {
-    apr_jose_t *j;
     apr_jose_jwt_t *jwt;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_JWT, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_JWT, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    j->cty = "JWT";
+    jose->cty = "JWT";
 
-    jwt = j->jose.jwt = apr_palloc(pool, sizeof(apr_jose_jwt_t));
+    jwt = jose->jose.jwt = apr_palloc(pool, sizeof(apr_jose_jwt_t));
     if (!jwt) {
-        return APR_ENOMEM;
+        return NULL;
     }
 
     jwt->claims = claims;
 
-    return APR_SUCCESS;
+    return jose;
 }
 
-APU_DECLARE(apr_status_t) apr_jose_text_make(apr_jose_t **jose, const char *cty,
+APU_DECLARE(apr_jose_t *) apr_jose_text_make(apr_jose_t *jose, const char *cty,
         const char *in, apr_size_t inlen, apr_pool_t *pool)
 {
-    apr_jose_t *j;
-    apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_TEXT, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jose) {
+        jose = apr_jose_make(jose, APR_JOSE_TYPE_TEXT, pool);
+        if (!jose) {
+            return NULL;
+        }
     }
-    j = *jose;
 
-    j->cty = cty;
-    j->jose.text = apr_palloc(pool, sizeof(apr_jose_text_t));
-    if (!j->jose.text) {
-        return APR_ENOMEM;
+    jose->cty = cty;
+    jose->jose.text = apr_palloc(pool, sizeof(apr_jose_text_t));
+    if (!jose->jose.text) {
+        return NULL;
     }
-    j->jose.text->text = in;
-    j->jose.text->len = inlen;
+    jose->jose.text->text = in;
+    jose->jose.text->len = inlen;
 
-    return APR_SUCCESS;
+    return jose;
 }

Modified: apr/apr-util/branches/1.7.x/jose/apr_jose_decode.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/jose/apr_jose_decode.c?rev=1839860&r1=1839859&r2=1839860&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/jose/apr_jose_decode.c (original)
+++ apr/apr-util/branches/1.7.x/jose/apr_jose_decode.c Sat Sep  1 22:08:49 2018
@@ -41,23 +41,24 @@ apr_status_t apr_jose_decode_jwk(apr_jos
         const char *typ, apr_bucket_brigade *bb, apr_jose_cb_t *cb,
         int level, int flags, apr_pool_t *pool)
 {
+    apr_json_value_t *key;
     apr_jose_text_t in;
     apr_off_t offset;
     apr_status_t status;
 
-    status = apr_jose_jwk_make(jose, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
-    }
-
     status = apr_jose_flatten(bb, &in, pool);
     if (APR_SUCCESS != status) {
         return status;
     }
 
-    status = apr_json_decode(&(*jose)->jose.jwk->key, in.text, in.len, &offset,
+    status = apr_json_decode(&key, in.text, in.len, &offset,
             APR_JSON_FLAGS_WHITESPACE, level, pool);
 
+    *jose = apr_jose_jwk_make(NULL, key, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
+    }
+
     if (APR_SUCCESS != status) {
         char buf[1024];
         apr_strerror(status, buf, sizeof(buf));
@@ -75,23 +76,24 @@ apr_status_t apr_jose_decode_jwks(apr_jo
         const char *typ, apr_bucket_brigade *bb, apr_jose_cb_t *cb,
         int level, int flags, apr_pool_t *pool)
 {
+    apr_json_value_t *keys;
     apr_jose_text_t in;
     apr_off_t offset;
     apr_status_t status;
 
-    status = apr_jose_jwks_make(jose, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
-    }
-
     status = apr_jose_flatten(bb, &in, pool);
     if (APR_SUCCESS != status) {
         return status;
     }
 
-    status = apr_json_decode(&(*jose)->jose.jwks->keys, in.text, in.len,
+    status = apr_json_decode(&keys, in.text, in.len,
             &offset, APR_JSON_FLAGS_WHITESPACE, level, pool);
 
+    *jose = apr_jose_jwks_make(NULL, keys, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
+    }
+
     if (APR_SUCCESS != status) {
         char buf[1024];
         apr_strerror(status, buf, sizeof(buf));
@@ -102,7 +104,7 @@ apr_status_t apr_jose_decode_jwks(apr_jo
         return status;
     }
 
-    if ((*jose)->jose.jwks->keys->type != APR_JSON_ARRAY) {
+    if (keys->type != APR_JSON_ARRAY) {
         apr_errprintf(&(*jose)->result, pool, NULL, 0,
                 "Syntax error: JWKS 'keys' is not an array");
         return APR_EINVAL;
@@ -115,23 +117,24 @@ apr_status_t apr_jose_decode_jwt(apr_jos
         const char *typ, apr_bucket_brigade *bb, apr_jose_cb_t *cb,
         int level, int flags, apr_pool_t *pool)
 {
+    apr_json_value_t *claims;
     apr_jose_text_t in;
     apr_off_t offset;
     apr_status_t status;
 
-    status = apr_jose_jwt_make(jose, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
-    }
-
     status = apr_jose_flatten(bb, &in, pool);
     if (APR_SUCCESS != status) {
         return status;
     }
 
-    status = apr_json_decode(&(*jose)->jose.jwt->claims, in.text, in.len, &offset,
+    status = apr_json_decode(&claims, in.text, in.len, &offset,
             APR_JSON_FLAGS_WHITESPACE, level, pool);
 
+    *jose = apr_jose_jwt_make(NULL, claims, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
+    }
+
     if (APR_SUCCESS != status) {
         char buf[1024];
         apr_strerror(status, buf, sizeof(buf));
@@ -157,10 +160,10 @@ apr_status_t apr_jose_decode_data(apr_jo
         return status;
     }
 
-    status = apr_jose_data_make(jose, typ, (const unsigned char *) in.text, in.len,
-            pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_data_make(NULL, typ, (const unsigned char *) in.text,
+            in.len, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
 
     return status;
@@ -404,9 +407,9 @@ apr_status_t apr_jose_decode_compact_jws
         return APR_EINIT;
     }
 
-    status = apr_jose_jws_make(jose, NULL, NULL, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_jws_make(*jose, NULL, NULL, NULL, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
     jws = (*jose)->jose.jws;
 
@@ -415,9 +418,9 @@ apr_status_t apr_jose_decode_compact_jws
      * the JWS Protected Header.
      */
 
-    status = apr_jose_signature_make(&jws->signature, NULL, ph, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    jws->signature = apr_jose_signature_make(NULL, NULL, ph, pool);
+    if (!jws->signature) {
+        return APR_ENOMEM;
     }
 
     dot = memchr(left, '.', right - left);
@@ -501,21 +504,21 @@ apr_status_t apr_jose_decode_compact_jwe
         return APR_EINIT;
     }
 
-    status = apr_jose_jwe_make(jose, NULL, NULL, NULL, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_jwe_make(*jose, NULL, NULL, NULL, NULL, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
     jwe = (*jose)->jose.jwe;
 
-    status = apr_jose_encryption_make(&jwe->encryption, NULL,
+    jwe->encryption = apr_jose_encryption_make(NULL, NULL,
             NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jwe->encryption) {
+        return APR_ENOMEM;
     }
 
-    status = apr_jose_recipient_make(&jwe->recipient, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    jwe->recipient = apr_jose_recipient_make(NULL, NULL, pool);
+    if (!jwe->recipient) {
+        return APR_ENOMEM;
     }
 
     /*
@@ -655,9 +658,9 @@ apr_status_t apr_jose_decode_compact(apr
     left = in.text;
     right = in.text + in.len;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_NONE, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_make(NULL, APR_JOSE_TYPE_NONE, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
 
     bb = apr_brigade_create(pool, brigade->bucket_alloc);
@@ -852,9 +855,9 @@ apr_status_t apr_jose_decode_json_jws(ap
         return APR_BADCH;
     }
 
-    status = apr_jose_jws_json_make(jose, NULL, NULL, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_jws_json_make(*jose, NULL, NULL, NULL, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
     jws = (*jose)->jose.jws;
 
@@ -1037,10 +1040,10 @@ apr_status_t apr_jose_decode_json_jws(ap
         return APR_SUCCESS;
     }
 
-    status = apr_jose_signature_make(&jws->signature, NULL, NULL,
+    jws->signature = apr_jose_signature_make(NULL, NULL, NULL,
             pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jws->signature) {
+        return APR_ENOMEM;
     }
 
     kv = apr_json_object_get(val, APR_JOSE_JWSE_PROTECTED,
@@ -1173,16 +1176,16 @@ apr_status_t apr_jose_decode_json_jwe(ap
         return APR_EINVAL;
     }
 
-    status = apr_jose_jwe_json_make(jose, NULL, NULL, NULL, NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_jwe_json_make(*jose, NULL, NULL, NULL, NULL, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
     jwe = (*jose)->jose.jwe;
 
-    status = apr_jose_encryption_make(&jwe->encryption, NULL,
+    jwe->encryption = apr_jose_encryption_make(NULL, NULL,
             NULL, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    if (!jwe->encryption) {
+        return APR_ENOMEM;
     }
 
     /*
@@ -1547,9 +1550,9 @@ apr_status_t apr_jose_decode_json(apr_jo
     apr_off_t offset;
     apr_status_t status;
 
-    status = apr_jose_make(jose, APR_JOSE_TYPE_NONE, pool);
-    if (APR_SUCCESS != status) {
-        return status;
+    *jose = apr_jose_make(NULL, APR_JOSE_TYPE_NONE, pool);
+    if (!*jose) {
+        return APR_ENOMEM;
     }
 
     status = apr_jose_flatten(brigade, &in, pool);

Modified: apr/apr-util/branches/1.7.x/test/testjose.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/testjose.c?rev=1839860&r1=1839859&r2=1839860&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/testjose.c (original)
+++ apr/apr-util/branches/1.7.x/test/testjose.c Sat Sep  1 22:08:49 2018
@@ -599,8 +599,8 @@ static void test_jose_encode_jws_compact
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_jose_signature_t signature;
     char buf[1024];
     apr_size_t len = sizeof(buf);
@@ -631,8 +631,8 @@ static void test_jose_encode_jws_compact
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "JWT", pl, sizeof(pl), p);
-    apr_jose_jws_make(&jose, &signature, NULL, jdata, p);
+    jdata = apr_jose_data_make(NULL, "JWT", pl, sizeof(pl), p);
+    jose = apr_jose_jws_make(NULL, &signature, NULL, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -649,8 +649,8 @@ static void test_jose_encode_jws_compact
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_jose_signature_t signature;
     char buf[1024];
     apr_size_t len = sizeof(buf);
@@ -685,8 +685,8 @@ static void test_jose_encode_jws_compact
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "JWT", pl, sizeof(pl), p);
-    apr_jose_jws_make(&jose, &signature, NULL, jdata, p);
+    jdata = apr_jose_data_make(NULL, "JWT", pl, sizeof(pl), p);
+    jose = apr_jose_jws_make(NULL, &signature, NULL, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -703,8 +703,8 @@ static void test_jose_encode_jws_json_ge
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_jose_signature_t **signature;
     apr_jose_signature_t signature1;
     apr_jose_signature_t signature2;
@@ -771,8 +771,8 @@ static void test_jose_encode_jws_json_ge
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "JWT", pl, sizeof(pl), p);
-    apr_jose_jws_json_make(&jose, NULL, signatures, jdata, p);
+    jdata = apr_jose_data_make(NULL, "JWT", pl, sizeof(pl), p);
+    jose = apr_jose_jws_json_make(NULL, NULL, signatures, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -790,8 +790,8 @@ static void test_jose_encode_jws_json_fl
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_jose_signature_t signature2;
     char buf[1024];
     apr_size_t len = sizeof(buf);
@@ -832,8 +832,8 @@ static void test_jose_encode_jws_json_fl
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "JWT", pl, sizeof(pl), p);
-    apr_jose_jws_json_make(&jose, &signature2, NULL, jdata, p);
+    jdata = apr_jose_data_make(NULL, "JWT", pl, sizeof(pl), p);
+    jose = apr_jose_jws_json_make(NULL, &signature2, NULL, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -851,8 +851,8 @@ static void test_jose_encode_jwe_compact
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_jose_encryption_t *encryption;
     apr_jose_recipient_t *recipient;
     apr_json_value_t *header = NULL;
@@ -893,10 +893,10 @@ static void test_jose_encode_jwe_compact
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "JWT", pl, sizeof(pl), p);
-    apr_jose_recipient_make(&recipient, header, p);
-    apr_jose_encryption_make(&encryption, NULL, protected_header, p);
-    apr_jose_jwe_make(&jose, recipient, NULL, encryption, jdata, p);
+    jdata = apr_jose_data_make(NULL, "JWT", pl, sizeof(pl), p);
+    recipient = apr_jose_recipient_make(NULL, header, p);
+    encryption = apr_jose_encryption_make(NULL, NULL, protected_header, p);
+    jose = apr_jose_jwe_make(NULL, recipient, NULL, encryption, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -913,8 +913,8 @@ static void test_jose_encode_jwe_json_ge
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_json_value_t *header = NULL;
     apr_json_value_t *protected_header = NULL;
     apr_jose_recipient_t **recipient;
@@ -979,9 +979,6 @@ static void test_jose_encode_jwe_json_ge
     recipient = apr_array_push(recipients);
     *recipient = &recipient2;
 
-
-
-
     apr_json_decode(&header, h, APR_JSON_VALUE_STRING, &offset,
             APR_JSON_FLAGS_WHITESPACE, 10, p);
     apr_json_decode(&protected_header, ph, APR_JSON_VALUE_STRING, &offset,
@@ -990,9 +987,9 @@ static void test_jose_encode_jwe_json_ge
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "plain", pl, sizeof(pl), p);
-    apr_jose_encryption_make(&encryption, header, protected_header, p);
-    apr_jose_jwe_json_make(&jose, NULL, recipients, encryption, jdata, p);
+    jdata = apr_jose_data_make(NULL, "plain", pl, sizeof(pl), p);
+    encryption = apr_jose_encryption_make(NULL, header, protected_header, p);
+    jose = apr_jose_jwe_json_make(NULL, NULL, recipients, encryption, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -1009,8 +1006,8 @@ static void test_jose_encode_jwe_json_fl
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
-    apr_jose_t *jdata = NULL;
+    apr_jose_t *jose;
+    apr_jose_t *jdata;
     apr_json_value_t *header = NULL;
     apr_json_value_t *protected_header = NULL;
     apr_jose_recipient_t recipient;
@@ -1061,9 +1058,9 @@ static void test_jose_encode_jwe_json_fl
     ba = apr_bucket_alloc_create(p);
     bb = apr_brigade_create(p, ba);
 
-    apr_jose_data_make(&jdata, "plain", pl, sizeof(pl), p);
-    apr_jose_encryption_make(&encryption, header, protected_header, p);
-    apr_jose_jwe_json_make(&jose, &recipient, NULL, encryption, jdata, p);
+    jdata = apr_jose_data_make(NULL, "plain", pl, sizeof(pl), p);
+    encryption = apr_jose_encryption_make(NULL, header, protected_header, p);
+    jose = apr_jose_jwe_json_make(NULL, &recipient, NULL, encryption, jdata, p);
 
     status = apr_jose_encode(bb, NULL, NULL, jose, &cb, p);
 
@@ -1080,7 +1077,7 @@ static void test_jose_decode_jws_compact
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_json_kv_t *kv;
     apr_status_t status;
 
@@ -1121,7 +1118,7 @@ static void test_jose_decode_jws_compact
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_json_kv_t *kv;
     apr_status_t status;
 
@@ -1186,7 +1183,7 @@ static void test_jose_decode_jws_json_ge
 
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_status_t status;
 
     apr_jose_cb_t cb;
@@ -1220,7 +1217,7 @@ static void test_jose_decode_jws_json_fl
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_status_t status;
 
     const char *source = "{"
@@ -1261,7 +1258,7 @@ static void test_jose_decode_jwe_compact
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_status_t status;
 
     const char *source = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ."
@@ -1302,7 +1299,7 @@ static void test_jose_decode_jwe_json_ge
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_status_t status;
 
     const char *source = "{"
@@ -1359,7 +1356,7 @@ static void test_jose_decode_jwe_json_fl
 {
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
-    apr_jose_t *jose = NULL;
+    apr_jose_t *jose;
     apr_status_t status;
 
     const char *source = "{"