From 4e55c1d682a49bb4c46fbd37182e9f72b2f4189d Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 14 Apr 2017 18:59:49 +0200 Subject: [PATCH] rgw: add std::array-aware variants of calc_hmac_sha256() and buf_to_hex(). Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_common.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index d21faebcebcb..dca06b25053c 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -16,6 +16,8 @@ #ifndef CEPH_RGW_COMMON_H #define CEPH_RGW_COMMON_H +#include + #include "common/ceph_crypto.h" #include "common/perf_counters.h" #include "acconfig.h" @@ -2068,6 +2070,14 @@ static inline void buf_to_hex(const unsigned char *buf, int len, char *str) } } +template static inline std::array +buf_to_hex(const std::array& buf) +{ + std::array hex_dest; + buf_to_hex(buf.data(), N, hex_dest.data()); + return hex_dest; +} + static inline int hexdigit(char c) { if (c >= '0' && c <= '9') @@ -2222,6 +2232,29 @@ extern void calc_hmac_sha1(const char *key, int key_len, const char *msg, int msg_len, char *dest); /* destination should be CEPH_CRYPTO_HMACSHA256_DIGESTSIZE bytes long */ extern void calc_hmac_sha256(const char *key, int key_len, const char *msg, int msg_len, char *dest); + +static inline std::array +calc_hmac_sha256(const char *key, const int key_len, + const char *msg, const int msg_len) { + std::array dest; + calc_hmac_sha256(key, key_len, msg, msg_len, + reinterpret_cast(dest.data())); + return dest; +} + +template +static inline std::array +calc_hmac_sha256(const std::array& key, + const char *msg, const int msg_len) { + std::array dest; + calc_hmac_sha256(reinterpret_cast(key.data()), key.size(), + msg, msg_len, + reinterpret_cast(dest.data())); + return dest; +} + extern void calc_hash_sha256(const char *msg, int len, string& dest); extern void calc_hash_sha256(const string& msg, string& dest); -- 2.47.3