Skip to content

Commit

Permalink
Move bytes::set_random implementation to a .cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 17, 2021
1 parent 861642e commit 9729d6f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ PRIVATE
base/basic_types.h
base/binary_guard.h
base/build_config.h
base/bytes.cpp
base/bytes.h
base/call_delayed.cpp
base/call_delayed.h
Expand Down
21 changes: 21 additions & 0 deletions base/bytes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#include "base/bytes.h"

#include "base/openssl_help.h"

namespace bytes {

void set_random(span destination) {
if (!destination.empty()) {
RAND_bytes(
reinterpret_cast<unsigned char*>(destination.data()),
destination.size());
}
}

} // namespace bytes
4 changes: 1 addition & 3 deletions base/bytes.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ vector concatenate(Args &&...args) {
return result;
}

template <
typename SpanRange>
template <typename SpanRange>
vector concatenate(SpanRange args) {
auto size = std::size_t(0);
for (const auto &arg : args) {
Expand All @@ -166,7 +165,6 @@ vector concatenate(SpanRange args) {
return result;
}

// Implemented in base/openssl_help.h
void set_random(span destination);

} // namespace bytes
12 changes: 0 additions & 12 deletions base/openssl_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,15 +593,3 @@ inline bytes::vector HmacSha256(
}

} // namespace openssl

namespace bytes {

inline void set_random(span destination) {
if (!destination.empty()) {
RAND_bytes(
reinterpret_cast<unsigned char*>(destination.data()),
destination.size());
}
}

} // namespace bytes

0 comments on commit 9729d6f

Please sign in to comment.