// Copyright 2023 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only #ifndef __SVR2_UTIL_BYTES_H #define __SVR2_UTIL_BYTES_H #include #include #include #include #include "util/macros.h" #include "proto/error.pb.h" namespace svr2::util { template std::string ByteArrayToString(const std::array& bytes) { std::string result; result.resize(N, '\0'); std::copy(bytes.begin(), bytes.end(), result.begin()); return result; } template std::pair, error::Error> StringToByteArray(const std::string& str) { std::array result{0}; if (str.size() > N) { return std::make_pair(result, error::Util_ArrayCopyTooBig); } std::copy(str.begin(), str.end(), result.begin()); return std::make_pair(result, error::OK); } std::string ByteVectorToString(const std::vector& bytes); inline std::string ByteVectorToString(const std::vector& bytes) { std::string result; result.resize(bytes.size()); std::copy(bytes.begin(), bytes.end(), result.begin()); return result; } } // namespace svr2::util #endif // __SVR2_UTIL_BYTES_H