Skip to content

Commit

Permalink
crypto: pkcs7: Use match_string() helper to simplify the code
Browse files Browse the repository at this point in the history
match_string() returns the array index of a matching string.
Use it instead of the open-coded implementation.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Ben Boeckel <mathstuf@gmail.com>
  • Loading branch information
YueHaibing authored and David Howells committed Jan 21, 2021
1 parent d13fc87 commit 3c0940c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions crypto/asymmetric_keys/pkcs7_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ int pkcs7_get_digest(struct pkcs7_message *pkcs7, const u8 **buf, u32 *len,
*buf = sinfo->sig->digest;
*len = sinfo->sig->digest_size;

for (i = 0; i < HASH_ALGO__LAST; i++)
if (!strcmp(hash_algo_name[i], sinfo->sig->hash_algo)) {
*hash_algo = i;
break;
}
i = match_string(hash_algo_name, HASH_ALGO__LAST,
sinfo->sig->hash_algo);
if (i >= 0)
*hash_algo = i;

return 0;
}
Expand Down

0 comments on commit 3c0940c

Please sign in to comment.