digestpp
1.0
C++11 header-only message digest library
Loading...
Searching...
No Matches
detail
validate_hash_size.hpp
Go to the documentation of this file.
1
/*
2
This code is written by kerukuro and released into public domain.
3
*/
4
5
#ifndef DIGESTPP_DETAIL_VALIDATE_HASH_SIZE_HPP
6
#define DIGESTPP_DETAIL_VALIDATE_HASH_SIZE_HPP
7
8
namespace
digestpp
9
{
10
namespace
detail
11
{
12
13
// Validate that variable hash is within the list of allowed sizes
14
inline
void
validate_hash_size
(
size_t
hs, std::initializer_list<size_t> set)
15
{
16
if
(!hs)
17
throw
std::runtime_error(
"hash size can't be zero"
);
18
19
if
(std::find(set.begin(), set.end(), hs))
20
return
;
21
22
throw
std::runtime_error(
"invalid hash size"
);
23
}
24
25
// Validate variable hash size up to max bits
26
inline
void
validate_hash_size
(
size_t
hs,
size_t
max)
27
{
28
if
(!hs)
29
throw
std::runtime_error(
"hash size can't be zero"
);
30
31
if
(hs % 8)
32
throw
std::runtime_error(
"non-byte hash sizes are not supported"
);
33
34
if
(hs > max)
35
throw
std::runtime_error(
"invalid hash size"
);
36
}
37
38
}
// namespace detail
39
}
// namespace digestpp
40
41
#endif
// DIGESTPP_DETAIL_VALIDATE_HASH_SIZE_HPP
digestpp::detail::validate_hash_size
void validate_hash_size(size_t hs, std::initializer_list< size_t > set)
Definition
validate_hash_size.hpp:14
digestpp
digestpp namespace
Definition
ascon.hpp:14
Generated by
1.12.0