-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CONSOLE: Add C++ generator for JWK info and drop the go implementation.
- Loading branch information
Showing
13 changed files
with
25,054 additions
and
85 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
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,53 @@ | ||
#pragma once | ||
#include <memory> | ||
#include <functional> | ||
#include <type_traits> | ||
#include <stdexcept> | ||
|
||
template <typename T, auto deleter, auto allocator = nullptr> | ||
class c_resource | ||
{ | ||
private: | ||
std::unique_ptr<T, decltype(deleter)> ptr; | ||
public: | ||
c_resource(std::function<T*()> creater) : ptr{creater(), deleter} {} | ||
c_resource(T* ptr) : ptr{ptr, deleter} {} | ||
c_resource() : ptr {nullptr, deleter} {} | ||
|
||
static c_resource allocate() | ||
{ | ||
static_assert(not std::is_null_pointer_v<decltype(allocator)>, | ||
"allocate should not be used without a defined allocator"); | ||
return c_resource(allocator); | ||
} | ||
|
||
operator bool() const | ||
{ | ||
return ptr; | ||
} | ||
|
||
auto release() | ||
{ | ||
return ptr.release(); | ||
} | ||
|
||
auto get() | ||
{ | ||
return ptr.get(); | ||
} | ||
|
||
auto get() const | ||
{ | ||
return ptr.get(); | ||
} | ||
|
||
operator T* () | ||
{ | ||
return get(); | ||
} | ||
|
||
operator const T* () const | ||
{ | ||
return get(); | ||
} | ||
}; |
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,22 @@ | ||
#pragma once | ||
#include <openssl/err.h> | ||
#include <string> | ||
#include <stdexcept> | ||
|
||
namespace jwk_generator | ||
{ | ||
struct openssl_error: public std::runtime_error { | ||
private: | ||
static inline std::string open_ssl_last_error() | ||
{ | ||
int err = ERR_get_error(); | ||
char errStr[256]; | ||
ERR_error_string(err, errStr); | ||
return std::string(errStr); | ||
} | ||
public: | ||
openssl_error(std::string what) : std::runtime_error(what + | ||
open_ssl_last_error()) {} | ||
}; | ||
}; | ||
|
Oops, something went wrong.