digestpp 1.0
C++11 header-only message digest library
Loading...
Searching...
No Matches
validate_hash_size.hpp
Go to the documentation of this file.
1/*
2This 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
8namespace digestpp
9{
10namespace detail
11{
12
13// Validate that variable hash is within the list of allowed sizes
14inline 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
26inline 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
void validate_hash_size(size_t hs, std::initializer_list< size_t > set)
Definition validate_hash_size.hpp:14
digestpp namespace
Definition ascon.hpp:14