-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SSL clean-up] Avoid memory allocations for SSL module, clean-up and …
…factorize code
- Loading branch information
Showing
15 changed files
with
250 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <climits> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <span> | ||
#include <string_view> | ||
|
||
#include "cct_fixedcapacityvector.hpp" | ||
#include "cct_string.hpp" | ||
|
||
namespace cct::ssl { | ||
|
||
/// @brief Helper type containing the number of bytes of the SHA | ||
enum class ShaType : uint8_t { kSha256 = 256 / CHAR_BIT, kSha512 = 512 / CHAR_BIT }; | ||
|
||
std::string_view GetOpenSSLVersion(); | ||
|
||
/// @brief Helper type containing the number of bytes of the SHA | ||
enum class ShaType : int16_t { kSha256 = 256 / CHAR_BIT, kSha512 = 512 / CHAR_BIT }; | ||
using Md256 = std::array<char, static_cast<std::size_t>(ShaType::kSha256)>; | ||
using Md512 = std::array<char, static_cast<std::size_t>(ShaType::kSha512)>; | ||
|
||
using Md256 = FixedCapacityVector<char, static_cast<int16_t>(ShaType::kSha256)>; | ||
using Md512 = FixedCapacityVector<char, static_cast<int16_t>(ShaType::kSha512)>; | ||
using Sha256HexArray = std::array<char, 2UL * static_cast<std::size_t>(ShaType::kSha256)>; | ||
using Sha512HexArray = std::array<char, 2UL * static_cast<std::size_t>(ShaType::kSha512)>; | ||
|
||
/// @brief Compute Sha256 from 'data' | ||
Md256 Sha256(std::string_view data); | ||
using Sha256DigestArray = std::array<char, 2UL * static_cast<std::size_t>(ShaType::kSha256)>; | ||
using Sha512DigestArray = std::array<char, 2UL * static_cast<std::size_t>(ShaType::kSha512)>; | ||
|
||
Md256 Sha256Bin(std::string_view data, std::string_view secret); | ||
Md512 Sha512Bin(std::string_view data, std::string_view secret); | ||
|
||
Md512 ShaBin(ShaType shaType, std::string_view data, std::string_view secret); | ||
Md256 Sha256(std::string_view data); | ||
|
||
string ShaHex(ShaType shaType, std::string_view data, std::string_view secret); | ||
Sha256HexArray Sha256Hex(std::string_view data, std::string_view secret); | ||
Sha512HexArray Sha512Hex(std::string_view data, std::string_view secret); | ||
|
||
string ShaDigest(ShaType shaType, std::string_view data); | ||
Sha256DigestArray Sha256Digest(std::string_view data); | ||
Sha512DigestArray Sha512Digest(std::string_view data); | ||
|
||
string ShaDigest(ShaType shaType, std::span<const string> data); | ||
Sha256DigestArray Sha256Digest(std::span<const std::string_view> data); | ||
Sha512DigestArray Sha512Digest(std::span<const std::string_view> data); | ||
|
||
} // namespace cct::ssl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.