]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Update cupsJWTNew to accept a claims argument with the initial JSON claims.
authorMichael R Sweet <msweet@msweet.org>
Fri, 16 May 2025 22:28:38 +0000 (18:28 -0400)
committerMichael R Sweet <msweet@msweet.org>
Fri, 16 May 2025 22:28:38 +0000 (18:28 -0400)
cups/jwt.c
cups/jwt.h
cups/testjwt.c

index d097bdedab8255e809205a2ae3194414e8d2b7ca..6435cb16164150114f7592164eede6049757b312 100644 (file)
@@ -1264,7 +1264,8 @@ cupsJWTMakePublicKey(cups_json_t *jwk)    // I - Private JSON Web Key
 //
 
 cups_jwt_t *                           // O - JWT object
-cupsJWTNew(const char *type)           // I - JWT type or `NULL` for default ("JWT")
+cupsJWTNew(const char  *type,          // I - JWT type or `NULL` for default ("JWT")
+           cups_json_t *claims)                // I - JSON claims or `NULL` for empty
 {
   cups_jwt_t   *jwt;                   // JWT object
 
@@ -1275,7 +1276,12 @@ cupsJWTNew(const char *type)             // I - JWT type or `NULL` for default ("JWT")
     {
       cupsJSONNewString(jwt->jose, cupsJSONNewKey(jwt->jose, NULL, "typ"), type ? type : "JWT");
 
-      if ((jwt->claims = cupsJSONNew(NULL, NULL, CUPS_JTYPE_OBJECT)) != NULL)
+      if (claims)
+        jwt->claims = claims;
+      else
+        jwt->claims = cupsJSONNew(NULL, NULL, CUPS_JTYPE_OBJECT);
+
+      if (jwt->claims)
         return (jwt);
     }
   }
index 1fdbab33e4d7cb96a06c3cf3627a5b20e75a2362..7bdfaf26bacf82a5cae5529fd770fb87ecb70768 100644 (file)
@@ -1,7 +1,7 @@
 //
 // JSON Web Token API definitions for CUPS.
 //
-// Copyright © 2023-2024 by OpenPrinting.
+// Copyright © 2023-2025 by OpenPrinting.
 //
 // Licensed under Apache License v2.0.  See the file "LICENSE" for more
 // information.
@@ -79,7 +79,7 @@ extern cups_jwt_t     *cupsJWTImportString(const char *s, cups_jws_format_t format)
 extern cups_json_t     *cupsJWTLoadCredentials(const char *path, const char *common_name) _CUPS_PUBLIC;
 extern cups_json_t     *cupsJWTMakePrivateKey(cups_jwa_t alg) _CUPS_PUBLIC;
 extern cups_json_t     *cupsJWTMakePublicKey(cups_json_t *jwk) _CUPS_PUBLIC;
-extern cups_jwt_t      *cupsJWTNew(const char *type) _CUPS_PUBLIC;
+extern cups_jwt_t      *cupsJWTNew(const char *type, cups_json_t *claims) _CUPS_PUBLIC;
 extern void            cupsJWTSetClaimNumber(cups_jwt_t *jwt, const char *claim, double value) _CUPS_PUBLIC;
 extern void            cupsJWTSetClaimString(cups_jwt_t *jwt, const char *claim, const char *value) _CUPS_PUBLIC;
 extern void            cupsJWTSetClaimValue(cups_jwt_t *jwt, const char *claim, cups_json_t *value) _CUPS_PUBLIC;
index 3fbab61d9cda60abb2ef1674ecda41d8b9514e92..91da59189d8d6f19834f58b363d0652d44bd0ebf 100644 (file)
@@ -99,8 +99,8 @@ main(int  argc,                               // I - Number of command-line arguments
       }*/
     };
 
-    testBegin("cupsJWTNew(NULL)");
-    jwt = cupsJWTNew(NULL);
+    testBegin("cupsJWTNew(NULL, NULL)");
+    jwt = cupsJWTNew(NULL, NULL);
     testEnd(jwt != NULL);
 
     testBegin("cupsJWTSetClaimNumber(CUPS_JWT_IAT)");
@@ -302,8 +302,8 @@ main(int  argc,                             // I - Number of command-line arguments
        testMessage("jwk=\"%s\"", s);
        free(s);
 
-       testBegin("cupsJWTNew(NULL)");
-       jwt = cupsJWTNew(NULL);
+       testBegin("cupsJWTNew(NULL, NULL)");
+       jwt = cupsJWTNew(NULL, NULL);
        testEnd(jwt != NULL);
 
        testBegin("cupsJWTSetClaimNumber(CUPS_JWT_IAT)");
@@ -346,8 +346,8 @@ main(int  argc,                             // I - Number of command-line arguments
        testMessage("jwk=\"%s\"", s);
        free(s);
 
-       testBegin("cupsJWTNew(NULL)");
-       jwt = cupsJWTNew(NULL);
+       testBegin("cupsJWTNew(NULL, NULL)");
+       jwt = cupsJWTNew(NULL, NULL);
        testEnd(jwt != NULL);
 
        testBegin("cupsJWTSetClaimNumber(CUPS_JWT_IAT)");