Skip to content

Commit 23f2c4d

Browse files
authored
test: use non-deprecated api for OpenSSL example (#6)
1 parent 4457a7e commit 23f2c4d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

examples/ssl.cc

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Demonstrate linking against a conda package, in this case OpenSSL.
22

3-
#include <openssl/sha.h>
3+
#include <openssl/evp.h>
44

55
#include <iostream>
66
#include <string_view>
@@ -9,15 +9,16 @@ using std::string_view;
99

1010
int main() {
1111
const string_view message = "Hello World";
12-
unsigned char hash[SHA256_DIGEST_LENGTH];
12+
unsigned char hash[EVP_MAX_MD_SIZE];
13+
size_t hashLen;
1314

14-
SHA256_CTX sha256;
15-
SHA256_Init(&sha256);
16-
SHA256_Update(&sha256, message.data(), message.size());
17-
SHA256_Final(hash, &sha256);
15+
if (!EVP_Q_digest(nullptr, "SHA256", nullptr, message.data(),
16+
message.length(), hash, &hashLen)) {
17+
return 1;
18+
}
1819

1920
std::cout << "SHA-256 Hash of 'Hello World': ";
20-
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
21+
for (int i = 0; i < hashLen; i++) {
2122
printf("%02x", hash[i]);
2223
}
2324
std::cout << std::endl;

0 commit comments

Comments
 (0)