mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 01:08:31 +00:00
Add algorithm parameter
This commit is contained in:
parent
ffd6280026
commit
da6d4932c3
5 changed files with 117 additions and 63 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <utility>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "jwt/algorithm.hpp"
|
||||
#include "jwt/detail/meta.hpp"
|
||||
#include "jwt/string_view.hpp"
|
||||
|
||||
|
@ -55,6 +56,31 @@ struct secret_param
|
|||
string_view secret_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parameter for providing the algorithm to use.
|
||||
* The parameter can accept either the string representation
|
||||
* or the enum class.
|
||||
*
|
||||
* Modeled as ParameterConcept.
|
||||
*/
|
||||
struct algorithm_param
|
||||
{
|
||||
algorithm_param(const string_view alg)
|
||||
: alg_(str_to_alg(alg))
|
||||
{}
|
||||
|
||||
algorithm_param(jwt::algorithm alg)
|
||||
: alg_(alg)
|
||||
{}
|
||||
|
||||
jwt::algorithm get() const noexcept
|
||||
{
|
||||
return alg_;
|
||||
}
|
||||
|
||||
typename jwt::algorithm alg_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parameter for providing additional headers.
|
||||
* Takes a mapping concept representing
|
||||
|
@ -108,11 +134,25 @@ payload(const param_init_list_t& kvs)
|
|||
|
||||
/**
|
||||
*/
|
||||
detail::secret_param secret(string_view sv)
|
||||
detail::secret_param secret(const string_view sv)
|
||||
{
|
||||
return { sv };
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
detail::algorithm_param algorithm(const string_view sv)
|
||||
{
|
||||
return { sv };
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
detail::algorithm_param algorithm(jwt::algorithm alg)
|
||||
{
|
||||
return { alg };
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
template <typename MappingConcept,
|
||||
|
@ -125,7 +165,7 @@ headers(MappingConcept&& mc)
|
|||
|
||||
/**
|
||||
*/
|
||||
detail::headers_param<std::map<std::string, std::string>>
|
||||
detail::headers_param<std::map<std::string, std::string>>
|
||||
headers(const param_init_list_t& kvs)
|
||||
{
|
||||
std::map<std::string, std::string> m;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue