Permalink
Browse files

Avoid sloppy use of assert in tests and examples

  • Loading branch information...
1 parent 7da5175 commit 3a7c907d488b1f332d459bdac818cf1684b40262 @rg3 committed Feb 15, 2014
Showing with 17 additions and 7 deletions.
  1. +9 −4 bcrypt.c
  2. +8 −3 bcrypt.h
View
@@ -104,23 +104,28 @@ int main()
clock_t after;
char salt[BCRYPT_HASHSIZE];
char hash[BCRYPT_HASHSIZE];
+ int ret;
const char pass[] = "hi,mom";
const char hash1[] = "$2a$10$VEVmGHy4F4XQMJ3eOZJAUeb.MedU0W10pTPCuf53eHdKJPiSE8sMK";
const char hash2[] = "$2a$10$3F0BVk5t8/aoS.3ddaB3l.fxg5qvafQ9NybxcpXLzMeAt.nVWn.NO";
- assert(bcrypt_gensalt(12, salt) == 0);
+ ret = bcrypt_gensalt(12, salt);
+ assert(ret == 0);
printf("Generated salt: %s\n", salt);
before = clock();
- assert(bcrypt_hashpw("testtesttest", salt, hash) == 0);
+ ret = bcrypt_hashpw("testtesttest", salt, hash);
+ assert(ret == 0);
after = clock();
printf("Hashed password: %s\n", hash);
printf("Time taken: %f seconds\n",
(float)(after - before) / CLOCKS_PER_SEC);
- assert(bcrypt_hashpw(pass, hash1, hash) == 0);
+ ret = bcrypt_hashpw(pass, hash1, hash);
+ assert(ret == 0);
printf("First hash check: %s\n", (strcmp(hash1, hash) == 0)?"OK":"FAIL");
- assert(bcrypt_hashpw(pass, hash2, hash) == 0);
+ ret = bcrypt_hashpw(pass, hash2, hash);
+ assert(ret == 0);
printf("Second hash check: %s\n", (strcmp(hash2, hash) == 0)?"OK":"FAIL");
return 0;
View
@@ -54,16 +54,21 @@ int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
*
* char salt[BCRYPT_HASHSIZE];
* char hash[BCRYPT_HASHSIZE];
+ * int ret;
*
- * assert(bcrypt_gensalt(12, salt) == 0);
- * assert(bcrypt_hashpw("thepassword", salt, hash) == 0);
+ * ret = bcrypt_gensalt(12, salt);
+ * assert(ret == 0);
+ * ret = bcrypt_hashpw("thepassword", salt, hash);
+ * assert(ret == 0);
*
*
* Verifying a password:
*
* char outhash[BCRYPT_HASHSIZE];
+ * int ret;
*
- * assert(bcrypt_hashpw("thepassword", "expectedhash", outhash) == 0);
+ * ret = bcrypt_hashpw("thepassword", "expectedhash", outhash);
+ * assert(ret == 0);
*
* if (strcmp("expectedhash", outhash) == 0) {
* printf("The password matches\n");

0 comments on commit 3a7c907

Please sign in to comment.