-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cppalliance/wchar
Add native interfaces to wider character types for MD5
- Loading branch information
Showing
5 changed files
with
335 additions
and
35 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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 Matt Borland | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#ifndef BOOST_CRYPT_UTILITES_ITERATOR_HPP | ||
#define BOOST_CRYPT_UTILITES_ITERATOR_HPP | ||
|
||
#include <boost/crypt/utility/config.hpp> | ||
|
||
#ifdef BOOST_CRYPT_HAS_CUDA | ||
|
||
#include <cuda/std/iterator> | ||
|
||
namespace boost { | ||
namespace crypt { | ||
|
||
template <typename Iter> | ||
struct iterator_traits : public cuda::std::iterator_traits<Iter> {}; | ||
|
||
template <typename T> | ||
struct iterator_traits<T*> : public cuda::std::iterator_traits<T*> {}; | ||
|
||
} // namespace crypt | ||
} // namespace boost | ||
|
||
#else | ||
|
||
#ifndef BOOST_CRYPT_BUILD_MODULE | ||
#include <iterator> | ||
#endif | ||
|
||
namespace boost { | ||
namespace crypt { | ||
namespace utility { | ||
|
||
template <typename Iter> | ||
struct iterator_traits : public std::iterator_traits<Iter> {}; | ||
|
||
template <typename T> | ||
struct iterator_traits<T*> : public std::iterator_traits<T*> {}; | ||
|
||
} // namespace utility | ||
} // namespace crypt | ||
} // namespace boost | ||
|
||
#endif // BOOST_CRYPT_HAS_CUDA | ||
|
||
#endif //BOOST_CRYPT_UTILITES_ITERATOR_HPP |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2024 Matt Borland | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#ifndef BOOST_CRYPT_TEST_GENERATE_RANDOM_STRINGS | ||
#define BOOST_CRYPT_TEST_GENERATE_RANDOM_STRINGS | ||
|
||
#include <random> | ||
#include <cstdlib> | ||
#include <ctime> | ||
#include <cstring> | ||
|
||
namespace boost { | ||
namespace crypt { | ||
|
||
inline void generate_random_string(char* str, std::size_t length) | ||
{ | ||
|
||
const char charset[] = "0123456789" | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
"abcdefghijklmnopqrstuvwxyz"; | ||
|
||
const std::size_t charset_size = sizeof(charset) - 1; | ||
|
||
std::mt19937_64 rng(42); | ||
std::uniform_int_distribution<std::size_t> dist(0, charset_size); | ||
|
||
for (std::size_t i = 0; i < length - 1; ++i) | ||
{ | ||
const auto index = dist(rng); | ||
str[i] = charset[index]; | ||
} | ||
|
||
str[length - 1] = '\0'; | ||
} | ||
|
||
inline void generate_random_string(char16_t* str, std::size_t length) | ||
{ | ||
const char16_t charset[] = u"0123456789" | ||
u"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
u"abcdefghijklmnopqrstuvwxyz"; | ||
|
||
const std::size_t charset_size = std::char_traits<char16_t>::length(charset); | ||
|
||
std::mt19937_64 rng(42); | ||
std::uniform_int_distribution<std::size_t> dist(0, charset_size - 1); | ||
|
||
for (std::size_t i = 0; i < length - 1; ++i) | ||
{ | ||
const auto index = dist(rng); | ||
str[i] = charset[index]; | ||
} | ||
|
||
str[length - 1] = u'\0'; | ||
} | ||
|
||
inline void generate_random_string(char32_t* str, std::size_t length) | ||
{ | ||
const char32_t charset[] = U"0123456789" | ||
U"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
U"abcdefghijklmnopqrstuvwxyz"; | ||
|
||
const std::size_t charset_size = std::char_traits<char32_t>::length(charset); | ||
|
||
std::mt19937_64 rng(42); | ||
std::uniform_int_distribution<std::size_t> dist(0, charset_size - 1); | ||
|
||
for (std::size_t i = 0; i < length - 1; ++i) | ||
{ | ||
const auto index = dist(rng); | ||
str[i] = charset[index]; | ||
} | ||
|
||
str[length - 1] = u'\0'; | ||
} | ||
|
||
inline void generate_random_string(wchar_t* str, std::size_t length) | ||
{ | ||
const wchar_t charset[] = L"0123456789" | ||
L"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
L"abcdefghijklmnopqrstuvwxyz"; | ||
|
||
const std::size_t charset_size = std::char_traits<wchar_t>::length(charset); | ||
|
||
std::mt19937_64 rng(42); | ||
std::uniform_int_distribution<std::size_t> dist(0, charset_size - 1); | ||
|
||
for (std::size_t i = 0; i < length - 1; ++i) | ||
{ | ||
const auto index = dist(rng); | ||
str[i] = charset[index]; | ||
} | ||
|
||
str[length - 1] = u'\0'; | ||
} | ||
|
||
} // Namespace crypt | ||
} // namespace boost | ||
|
||
#endif // BOOST_CRYPT_TEST_GENERATE_RANDOM_STRINGS |
Oops, something went wrong.