fix(lib/attestation): fix MISRA C:2012 defects in attestation_token.c
Fixes the following MISRA C:2012 defects:
- The return value of a non-void function
"attest_get_realm_signing_key" is unused.
- Using uninitialized value "key_handle".
- Identifier "rmm_platform_token" is already used
to represent an object with internal linkage.
- Implicit conversion of "token_ret" from essential
type "anonymous enum" to different or narrower
essential type "signed 32-bit int".
- Implicit conversion of "ATTEST_TOKEN_ERR_SUCCESS"
from essential type "anonymous enum" to different
or narrower essential type "signed 32-bit int".
Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
Change-Id: I464fd408ff8a61578729dcb6dc2e4d13f977c740
diff --git a/lib/attestation/src/attestation_token.c b/lib/attestation/src/attestation_token.c
index 752427e..1f9fe09 100644
--- a/lib/attestation/src/attestation_token.c
+++ b/lib/attestation/src/attestation_token.c
@@ -99,7 +99,10 @@
/*
* Get the reference to `mbedtls_ecp_keypair` and set it to t_cose.
*/
- attest_get_realm_signing_key(&key_handle);
+ if (attest_get_realm_signing_key(&key_handle) != 0) {
+ return ATTEST_TOKEN_ERR_SIGNING_KEY;
+ }
+
attest_key.key.handle = key_handle;
t_cose_signature_sign_restart_set_signing_key(&me->restartable_signer_ctx, attest_key);
@@ -180,15 +183,15 @@
struct q_useful_buf_c completed_token;
QCBOREncodeContext cbor_enc_ctx;
QCBORError qcbor_res;
- struct q_useful_buf_c rmm_platform_token;
+ struct q_useful_buf_c platform_token;
struct q_useful_buf attest_token_ub = {attest_token_buf, attest_token_buf_size};
struct q_useful_buf_c realm_token_ub = {realm_token_buf, realm_token_len};
__unused int ret;
/* Get the platform token */
- ret = attest_get_platform_token(&rmm_platform_token.ptr,
- &rmm_platform_token.len);
+ ret = attest_get_platform_token(&platform_token.ptr,
+ &platform_token.len);
assert(ret == 0);
QCBOREncode_Init(&cbor_enc_ctx, attest_token_ub);
@@ -199,7 +202,7 @@
QCBOREncode_AddBytesToMapN(&cbor_enc_ctx,
CCA_PLAT_TOKEN,
- rmm_platform_token);
+ platform_token);
QCBOREncode_AddBytesToMapN(&cbor_enc_ctx,
CCA_REALM_DELEGATED_TOKEN,
@@ -265,7 +268,7 @@
T_COSE_ALGORITHM_ES384,
&realm_token_ub);
if (token_ret != ATTEST_TOKEN_ERR_SUCCESS) {
- return token_ret;
+ return (int)token_ret;
}
QCBOREncode_BstrWrap(&(ctx->ctx.cbor_enc_ctx));
@@ -326,5 +329,5 @@
QCBOREncode_CloseBstrWrap2(&(ctx->ctx.cbor_enc_ctx), false,
&(ctx->ctx.signed_payload));
- return ATTEST_TOKEN_ERR_SUCCESS;
+ return (int)ATTEST_TOKEN_ERR_SUCCESS;
}