Add ccapi [header-only] lib to includes

This is the open source crypto connector lib
This commit is contained in:
John Colvin committed 2022-06-06 11:57:00 -04:00
1 parent 27310d2829
commit 99c440f568
102 files changed
+33735

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#ifndef INCLUDE_CCAPI_CPP_CCAPI_JWT_H_
#define INCLUDE_CCAPI_CPP_CCAPI_JWT_H_
#include "ccapi_cpp/ccapi_hmac.h"
#include "ccapi_cpp/ccapi_macro.h"
#include "ccapi_cpp/ccapi_util_private.h"
namespace ccapi {
class Jwt CCAPI_FINAL {
public:
static std::string generate(const Hmac::ShaVersion shaVersion, const std::string& secret, const std::string& payload) {
std::string output;
switch (shaVersion) {
case Hmac::ShaVersion::SHA256:
output += UtilAlgorithm::base64UrlEncode("{\"alg\":\"HS256\",\"typ\":\"JWT\"}");
break;
default:
CCAPI_LOGGER_FATAL(CCAPI_UNSUPPORTED_VALUE);
}
output += ".";
output += UtilAlgorithm::base64UrlEncode(payload);
std::string signature = Hmac::hmac(shaVersion, secret, output);
output += ".";
output += UtilAlgorithm::base64UrlEncode(signature);
return output;
}
};
} // namespace ccapi
#endif // INCLUDE_CCAPI_CPP_CCAPI_JWT_H_