Skip to content

Commit fc0959a

Browse files
authored
refactor: update HMAC_SHA256 function to return error status (#3)
1 parent 1643bca commit fc0959a

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ int HMAC_SHA256(const unsigned char *data, size_t data_len,
99
unsigned char *out, size_t *out_len)
1010
{
1111
unsigned int len = 0;
12-
HMAC(EVP_sha256(), key, key_len, data, data_len, out, &len);
12+
char *ac = HMAC(EVP_sha256(), key, key_len, data, data_len, out, &len);
1313
*out_len = len;
14-
return 0;
14+
return (ac != NULL) ? 0 : -1;
1515
}
1616

1717
int main()

test.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <stdlib.h>
21
#include <openssl/hmac.h>
32
#include <openssl/sha.h>
43
#include <check.h>
@@ -10,9 +9,9 @@ int HMAC_SHA256(const unsigned char *data, size_t data_len,
109
unsigned char *out, size_t *out_len)
1110
{
1211
unsigned int len = 0;
13-
HMAC(EVP_sha256(), key, key_len, data, data_len, out, &len);
12+
char *ac = HMAC(EVP_sha256(), key, key_len, data, data_len, out, &len);
1413
*out_len = len;
15-
return 0;
14+
return (ac != NULL) ? 0 : -1;
1615
}
1716

1817
START_TEST(AwsSigv4Test_AwsSigv4Sign)

0 commit comments

Comments
 (0)