From c0ec65bbaef5becb0afeca0aa0e1a06a473bdd57 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 21 Nov 2014 08:06:29 -0500 Subject: [PATCH] Make identicon color an optional feature and specify the dependency. --- MasterPassword/C/build | 9 ++++++++- MasterPassword/C/types.c | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/MasterPassword/C/build b/MasterPassword/C/build index e4d655dc..6df3c41b 100755 --- a/MasterPassword/C/build +++ b/MasterPassword/C/build @@ -9,6 +9,8 @@ # try ./build -lrt instead. # - If you see 'x86.S:202: Error: junk at end of line, first unrecognized character is `,'', # try commenting the line in lib/bcrypt/x86.S. +# - Take a look at the "Optional features" section. Some features have dependencies, +# either make sure you have them or disable those features. # # BUGS # masterpassword@lyndir.com @@ -35,6 +37,9 @@ else ) fi +# Optional features. +mpw_color=1 # Colorized Identicon, requires libncurses-dev + ### DEPENDENCIES @@ -192,7 +197,7 @@ mpw() { # library paths -L"." -L"lib/scrypt" # link libraries - -l"crypto" -l"curses" + -l"crypto" # scrypt "lib/scrypt/scrypt-crypto_aesctr.o" "lib/scrypt/scrypt-sha256.o" @@ -201,6 +206,8 @@ mpw() { "lib/scrypt/scrypt-scryptenc_cpuperf.o" "lib/scrypt/scrypt-scryptenc.o" ) + # optional features + (( mpw_color )) && CFLAGS+=( -DCOLOR ) LDFLAGS+=( -l"curses" ) cc "${CFLAGS[@]}" -c types.c -o types.o "$@" cc "${CFLAGS[@]}" "${LDFLAGS[@]}" "types.o" mpw.c -o mpw "$@" diff --git a/MasterPassword/C/types.c b/MasterPassword/C/types.c index fc342a9f..b3d621f2 100644 --- a/MasterPassword/C/types.c +++ b/MasterPassword/C/types.c @@ -217,7 +217,7 @@ const char *Identicon(const char *userName, const char *masterPassword) { uint8_t identiconSeed[32]; HMAC_SHA256_Buf(masterPassword, strlen(masterPassword), userName, strlen(userName), identiconSeed); - char *identicon = (char *)calloc(20, sizeof(char)); +#ifdef COLOR setupterm(NULL, 2, NULL); initputvar(); tputs(tparm(tgetstr("AF", NULL), identiconSeed[4] % 7 + 1), 1, putvar); @@ -226,6 +226,11 @@ const char *Identicon(const char *userName, const char *masterPassword) { tputs(tgetstr("me", NULL), 1, putvar); char reset[strlen(putvarc)]; strcpy(reset, putvarc); +#else + const char *red = "", *reset = ""; +#endif + + char *identicon = (char *)calloc(20, sizeof(char)); sprintf(identicon, "%s%s%s%s%s%s", red, left[identiconSeed[0] % (sizeof(left) / sizeof(left[0]))],