FIx the unit test (#59)
There was an error in the Encrypt0 code which was not being detected by the Unit tests. Both the source and the unit tests have been updated to fix this.
* FIx the unit test
* Correct the string for encrypt0
diff --git a/src/Encrypt0.c b/src/Encrypt0.c
index 2e228f4..b6a85ec 100644
--- a/src/Encrypt0.c
+++ b/src/Encrypt0.c
@@ -136,7 +136,7 @@
return false;
}
- f = _COSE_Enveloped_decrypt(pcose, NULL, pbKey, cbKey, "Encrypt1", perr);
+ f = _COSE_Enveloped_decrypt(pcose, NULL, pbKey, cbKey, "Encrypt0", perr);
return f;
}
@@ -145,7 +145,7 @@
CHECK_CONDITION(IsValidEncryptHandle(h), COSE_ERR_INVALID_HANDLE);
CHECK_CONDITION(pbKey != NULL, COSE_ERR_INVALID_PARAMETER);
- return _COSE_Enveloped_encrypt((COSE_Encrypt *)h, pbKey, cbKey, "Encrypt1", perr);
+ return _COSE_Enveloped_encrypt((COSE_Encrypt *)h, pbKey, cbKey, "Encrypt0", perr);
errorReturn:
return false;
diff --git a/test/encrypt.c b/test/encrypt.c
index 434b4da..cf3a283 100644
--- a/test/encrypt.c
+++ b/test/encrypt.c
@@ -402,7 +402,11 @@
}
cn_cbor * alg = COSE_Encrypt_map_get_int(hEnc, COSE_Header_Algorithm, COSE_BOTH, NULL);
- if (!IsAlgorithmSupported(alg)) fAlgSupport = false;
+ if (!IsAlgorithmSupported(alg)) {
+ fAlgSupport = false;
+ fFail = false;
+ goto exitHere;
+ }
pFail = cn_cbor_mapget_string(pRecipients, "fail");
if (COSE_Encrypt_decrypt(hEnc, k->v.bytes, k->length, NULL)) {
@@ -424,12 +428,17 @@
exitHere:
- if (fFailBody) {
- if (!fFail) fFail = true;
- else fFail = false;
+ if (fAlgSupport) {
+ if (fFailBody) {
+ if (!fFail) fFail = true;
+ else fFail = false;
+ }
+ }
+ else {
+ fFail = false;
}
- if (fFail && fAlgSupport) CFails += 1;
+ if (fFail) CFails += 1;
return fAlgSupport ? 1 : 0;
returnError: