aboutsummaryrefslogtreecommitdiff
path: root/test_digest.c
diff options
context:
space:
mode:
authorRichard Levitte <richard@levitte.org>2021-02-22 06:08:55 +0100
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>2021-02-22 09:30:54 +0100
commitb56b7ee05276b92c282efa412ae94163b88ec350 (patch)
tree2b7e81802f7213e72091a1889d691b072d366046 /test_digest.c
parentbc111014be6390ae8f3674d05b76eb205ab4c49b (diff)
downloadgost-engine-b56b7ee05276b92c282efa412ae94163b88ec350.zip
gost-engine-b56b7ee05276b92c282efa412ae94163b88ec350.tar.gz
gost-engine-b56b7ee05276b92c282efa412ae94163b88ec350.tar.bz2
Always cNORM before "\n"
Using cNORM after "\n" may or may not work, probably because of the line buffered nature of standard output. If an error is displayed immediately after a printf that has cNORM after "\n", the error output sometimes "overrides" the cNORM, and you may end up with a surprisingly colorful error message, not to mention that this may also affect your prompt in the same manner. The lesson is to always output cNORM before the ending "\n".
Diffstat (limited to 'test_digest.c')
-rw-r--r--test_digest.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/test_digest.c b/test_digest.c
index 6a35533..876505b 100644
--- a/test_digest.c
+++ b/test_digest.c
@@ -49,9 +49,9 @@
#define cMAGENT "\033[1;35m"
#define cNORM "\033[m"
#define TEST_ASSERT(e) {if ((test = (e))) \
- printf(cRED " Test FAILED\n" cNORM); \
+ printf(cRED " Test FAILED" cNORM "\n"); \
else \
- printf(cGREEN " Test passed\n" cNORM);}
+ printf(cGREEN " Test passed" cNORM "\n");}
/* To test older APIs. */
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
@@ -509,7 +509,7 @@ static int do_hmac_old(int iter, const EVP_MD *type, const char *plaintext,
if (t->mdsize)
T(len == t->mdsize);
if (memcmp(md, t->hmac, len) != 0) {
- printf(cRED "hmac mismatch\n" cNORM);
+ printf(cRED "hmac mismatch" cNORM "\n");
hexdump(t->hmac, len);
hexdump(md, len);
return 1;
@@ -547,7 +547,7 @@ static int do_hmac_prov(int iter, const EVP_MD *type, const char *plaintext,
if (t->mdsize)
T(len == t->mdsize);
if (memcmp(md, t->hmac, len) != 0) {
- printf(cRED "hmac mismatch\n" cNORM);
+ printf(cRED "hmac mismatch" cNORM "\n");
hexdump(t->hmac, len);
hexdump(md, len);
return 1;
@@ -623,7 +623,7 @@ static int do_cmac_prov(int iter, const char *plaintext,
* So, just compare until what we need. */
T(mdsize <= len);
if (memcmp(md, t->digest, mdsize) != 0) {
- printf(cRED "cmac mismatch\n" cNORM);
+ printf(cRED "cmac mismatch" cNORM "\n");
hexdump(t->digest, mdsize);
hexdump(md, len);
return 1;
@@ -673,7 +673,7 @@ static int do_digest(int iter, const EVP_MD *type, const char *plaintext,
EVP_MD_CTX_free(ctx);
T(len == mdsize);
if (memcmp(md, t->digest, mdsize) != 0) {
- printf(cRED "digest mismatch\n" cNORM);
+ printf(cRED "digest mismatch" cNORM "\n");
hexdump(t->digest, mdsize);
hexdump(md, mdsize);
return 1;
@@ -711,9 +711,9 @@ static int do_test(const struct hash_testvec *tv)
OPENSSL_free(buf);
if (!ret)
- printf(cGREEN "success\n" cNORM);
+ printf(cGREEN "success" cNORM "\n");
else
- printf(cRED "fail\n" cNORM);
+ printf(cRED "fail" cNORM "\n");
return ret;
}
@@ -775,13 +775,13 @@ static int do_synthetic_once(const struct hash_testvec *tv, unsigned int shifts)
EVP_MD_CTX_free(ctx2);
if (len != mdlen) {
- printf(cRED "digest output len mismatch %u != %u (expected)\n" cNORM,
+ printf(cRED "digest output len mismatch %u != %u (expected)" cNORM "\n",
len, mdlen);
goto err;
}
if (memcmp(md, tv->digest, mdlen) != 0) {
- printf(cRED "digest mismatch\n" cNORM);
+ printf(cRED "digest mismatch" cNORM "\n");
unsigned int i;
printf(" Expected value is: ");
@@ -811,9 +811,9 @@ static int do_synthetic_test(const struct hash_testvec *tv)
ret |= do_synthetic_once(tv, shifts);
if (!ret)
- printf(cGREEN "success\n" cNORM);
+ printf(cGREEN "success" cNORM "\n");
else
- printf(cRED "fail\n" cNORM);
+ printf(cRED "fail" cNORM "\n");
return 0;
}
@@ -851,15 +851,15 @@ int main(int argc, char **argv)
if (tv->nid == nids[k])
break;
if (!tv->nid)
- printf(cMAGENT "Digest %s is untested!\n" cNORM, OBJ_nid2sn(nids[k]));
+ printf(cMAGENT "Digest %s is untested!" cNORM "\n", OBJ_nid2sn(nids[k]));
}
ENGINE_finish(eng);
ENGINE_free(eng);
if (ret)
- printf(cDRED "= Some tests FAILED!\n" cNORM);
+ printf(cDRED "= Some tests FAILED!" cNORM "\n");
else
- printf(cDGREEN "= All tests passed!\n" cNORM);
+ printf(cDGREEN "= All tests passed!" cNORM "\n");
return ret;
}