Skip to content

Commit

Permalink
jwt: rename exp variables to expt
Browse files Browse the repository at this point in the history
Fix 'WARNING: Violation to rule 21.2 (Should not used a reserved
identifier) - exp'

Signed-off-by: Benjamin Lemouzy <blemouzy@centralp.fr>
  • Loading branch information
blemouzy committed Oct 9, 2024
1 parent 77f99ad commit 34de574
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions include/zephyr/data/jwt.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int jwt_init_builder(struct jwt_builder *builder,
* @retval <0 Failure.
*/
int jwt_add_payload(struct jwt_builder *builder,
int32_t exp,
int32_t expt,
int32_t iat,
const char *aud);

Check notice on line 125 in include/zephyr/data/jwt.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/data/jwt.h:125 -int jwt_add_payload(struct jwt_builder *builder, - int32_t expt, - int32_t iat, - const char *aud); +int jwt_add_payload(struct jwt_builder *builder, int32_t expt, int32_t iat, const char *aud);
Expand Down Expand Up @@ -162,14 +162,14 @@ int jwt_init_parser(struct jwt_parser *parser, const char *token, char *buffer,
* Parse JWT payload from a previously initialized parser.
*
* @param parser A previously initialized parser.
* @param exp A valid pointer to store Expiration Time value.
* @param expt A valid pointer to store Expiration Time value.
* @param iat A valid pointer to store Issued At value.
* @param aud A valid pointer to store Audience value.
*
* @retval 0 Success.
* @retval <0 Failure.
*/
int jwt_parse_payload(struct jwt_parser *parser, int32_t *exp, int32_t *iat, char *aud);
int jwt_parse_payload(struct jwt_parser *parser, int32_t *expt, int32_t *iat, char *aud);

/**
* @brief Verify JWT header and signature.
Expand Down
8 changes: 4 additions & 4 deletions subsys/jwt/jwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ static int jwt_add_header(struct jwt_builder *builder)
}

int jwt_add_payload(struct jwt_builder *builder,
int32_t exp,
int32_t expt,
int32_t iat,
const char *aud)
{

Check notice on line 247 in subsys/jwt/jwt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/jwt/jwt.c:247 -int jwt_add_payload(struct jwt_builder *builder, - int32_t expt, - int32_t iat, - const char *aud) +int jwt_add_payload(struct jwt_builder *builder, int32_t expt, int32_t iat, const char *aud)
struct jwt_payload payload = {
.exp = exp,
.exp = expt,
.iat = iat,
.aud = aud,
};
Expand Down Expand Up @@ -292,7 +292,7 @@ int jwt_init_builder(struct jwt_builder *builder,
return jwt_add_header(builder);
}

int jwt_parse_payload(struct jwt_parser *parser, int32_t *exp, int32_t *iat, char *aud)
int jwt_parse_payload(struct jwt_parser *parser, int32_t *expt, int32_t *iat, char *aud)
{
struct jwt_payload payload;
int res;
Expand All @@ -305,7 +305,7 @@ int jwt_parse_payload(struct jwt_parser *parser, int32_t *exp, int32_t *iat, cha
res = json_obj_parse(parser->buf, res, jwt_payload_desc, ARRAY_SIZE(jwt_payload_desc),
&payload);
if (res == (1 << ARRAY_SIZE(jwt_payload_desc)) - 1) {
*exp = payload.exp;
*expt = payload.exp;
*iat = payload.iat;
strcpy(aud, payload.aud);
res = 0;
Expand Down
10 changes: 5 additions & 5 deletions tests/subsys/jwt/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern unsigned int jwt_test_private_der_len;

ZTEST(jwt_tests, test_jwt)
{
const int32_t exp = 1530312026;
const int32_t expt = 1530312026;
const int32_t iat = 1530308426;
static const char aud[] = "iot-work-199419";
/*
Expand All @@ -39,15 +39,15 @@ ZTEST(jwt_tests, test_jwt)
struct jwt_builder build;
char jwt[460];
struct jwt_parser parse;
int32_t parsed_exp = 0;
int32_t parsed_expt = 0;
int32_t parsed_iat = 0;
char parsed_aud[32] = {0};
int res;

res = jwt_init_builder(&build, buf, sizeof(buf));
zassert_equal(res, 0, "Setting up jwt");

res = jwt_add_payload(&build, exp, iat, aud);
res = jwt_add_payload(&build, expt, iat, aud);
zassert_equal(res, 0, "Adding payload");

res = jwt_sign(&build, jwt_test_private_der, jwt_test_private_der_len);
Expand All @@ -63,9 +63,9 @@ ZTEST(jwt_tests, test_jwt)
res = jwt_init_parser(&parse, jwt, buf, sizeof(buf));
zassert_equal(res, 0, "Setting up jwt parsing");

res = jwt_parse_payload(&parse, &parsed_exp, &parsed_iat, parsed_aud);
res = jwt_parse_payload(&parse, &parsed_expt, &parsed_iat, parsed_aud);
zassert_equal(res, 0, "Parsing payload");
zassert_equal(parsed_exp, exp, "Comparing expiration time");
zassert_equal(parsed_expt, expt, "Comparing expiration time");
zassert_equal(parsed_iat, iat, "Comparing issued at");
zassert_mem_equal(parsed_aud, aud, sizeof(aud), "Comparing audience");

Expand Down

0 comments on commit 34de574

Please sign in to comment.