2
0

Better ftl failure handling.

This commit is contained in:
Maarten Billemont
2017-08-01 16:50:50 -04:00
parent 46cdf56944
commit 99e286456e
4 changed files with 42 additions and 28 deletions

View File

@@ -105,16 +105,15 @@ const char **mpw_templatesForType(MPPasswordType type, size_t *count) {
if (!(type & MPPasswordTypeClassGenerated)) {
ftl( "Not a generated type: %d", type );
*count = 0;
return NULL;
}
switch (type) {
case MPPasswordTypeGeneratedMaximum:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"anoxxxxxxxxxxxxxxxxx", "axxxxxxxxxxxxxxxxxno" );
case MPPasswordTypeGeneratedLong:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"CvcvnoCvcvCvcv", "CvcvCvcvnoCvcv", "CvcvCvcvCvcvno",
"CvccnoCvcvCvcv", "CvccCvcvnoCvcv", "CvccCvcvCvcvno",
"CvcvnoCvccCvcv", "CvcvCvccnoCvcv", "CvcvCvccCvcvno",
@@ -123,26 +122,25 @@ const char **mpw_templatesForType(MPPasswordType type, size_t *count) {
"CvcvnoCvccCvcc", "CvcvCvccnoCvcc", "CvcvCvccCvccno",
"CvccnoCvcvCvcc", "CvccCvcvnoCvcc", "CvccCvcvCvccno" );
case MPPasswordTypeGeneratedMedium:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"CvcnoCvc", "CvcCvcno" );
case MPPasswordTypeGeneratedBasic:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"aaanaaan", "aannaaan", "aaannaaa" );
case MPPasswordTypeGeneratedShort:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"Cvcn" );
case MPPasswordTypeGeneratedPIN:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"nnnn" );
case MPPasswordTypeGeneratedName:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"cvccvcvcv" );
case MPPasswordTypeGeneratedPhrase:
return mpw_alloc_array( *count, const char *,
return mpw_alloc_array( count, const char *,
"cvcc cvc cvccvcv cvc", "cvc cvccvcvcv cvcv", "cv cvccv cvc cvcvccv" );
default: {
ftl( "Unknown generated type: %d", type );
*count = 0;
return NULL;
}
}
@@ -174,6 +172,7 @@ const MPKeyPurpose mpw_purposeWithName(const char *purposeName) {
return MPKeyPurposeRecovery;
ftl( "Not a purpose name: %s", stdPurposeName );
return MPKeyPurposeAuthentication;
}
const char *mpw_nameForPurpose(MPKeyPurpose purpose) {

View File

@@ -60,8 +60,7 @@ extern int mpw_verbosity;
#define ftl_level -2
#define ftl(...) ({ \
if (mpw_verbosity >= -2) \
fprintf( stderr, __VA_ARGS__ ); \
exit( 2 ); })
fprintf( stderr, __VA_ARGS__ ); })
#endif
#ifndef min
#define min(a, b) ({ \
@@ -78,9 +77,11 @@ extern int mpw_verbosity;
//// Buffers and memory.
/** Allocate a new array of _type, assign its element count to _count if not NULL and populate it with the varargs. */
#define mpw_alloc_array(_count, _type, ...) ({ \
_type stackElements[] = { __VA_ARGS__ }; \
_count = sizeof( stackElements ) / sizeof( _type ); \
if (_count) \
*_count = sizeof( stackElements ) / sizeof( _type ); \
_type *allocElements = malloc( sizeof( stackElements ) ); \
memcpy( allocElements, stackElements, sizeof( stackElements ) ); \
allocElements; \