Skip to content

Commit 5af8c56

Browse files
authored
refactor: remove deprecated usage of OpenSSL SHA1_ and SHA256_ functions (#354)
The `SHA1_*` family of functions were [deprecated](https://www.openssl.org/docs/man3.1/man3/SHA1_Init.html) in OpenSSL 3.0, but plain old `SHA1` is not. Same goes for `SHA256_*`.
1 parent ffeb6f6 commit 5af8c56

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libs/internal/src/encoding/sha_1.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ std::array<unsigned char, SHA_DIGEST_LENGTH> Sha1String(
88
std::string const& input) {
99
std::array<unsigned char, SHA_DIGEST_LENGTH> hash{};
1010

11-
SHA_CTX sha;
12-
SHA1_Init(&sha);
13-
SHA1_Update(&sha, input.c_str(), input.size());
14-
SHA1_Final(hash.data(), &sha);
11+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
12+
SHA1(reinterpret_cast<unsigned char const*>(input.data()), input.size(),
13+
hash.data());
1514

1615
return hash;
1716
}

libs/internal/src/encoding/sha_256.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ std::array<unsigned char, SHA256_DIGEST_LENGTH> Sha256String(
88
std::string const& input) {
99
std::array<unsigned char, SHA256_DIGEST_LENGTH> hash{};
1010

11-
SHA256_CTX sha256;
12-
SHA256_Init(&sha256);
13-
SHA256_Update(&sha256, input.c_str(), input.size());
14-
SHA256_Final(hash.data(), &sha256);
11+
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
12+
SHA256(reinterpret_cast<unsigned char const*>(input.data()), input.size(),
13+
hash.data());
1514

1615
return hash;
1716
}

0 commit comments

Comments
 (0)