-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jwt/OsslJWS: basic JWS definitions for OpenSSL
- Loading branch information
1 parent
4032405
commit f0a7140
Showing
3 changed files
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// Copyright CM4all GmbH | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#include "OsslJWS.hxx" | ||
|
||
#include <openssl/evp.h> | ||
|
||
#include <stdexcept> | ||
|
||
using std::string_view_literals::operator""sv; | ||
|
||
namespace JWS { | ||
|
||
std::string_view | ||
GetAlg(const EVP_PKEY &key) | ||
{ | ||
switch (EVP_PKEY_get_base_id(&key)) { | ||
case EVP_PKEY_RSA: | ||
return "RS256"sv; | ||
|
||
default: | ||
throw std::invalid_argument{"Unsupported key type"}; | ||
} | ||
} | ||
|
||
} // namespace JWS |
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,24 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// Copyright CM4all GmbH | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#pragma once | ||
|
||
#include <openssl/ossl_typ.h> | ||
|
||
#include <string_view> | ||
|
||
namespace JWS { | ||
|
||
/** | ||
* Returns the "alg" (Algorithm) Header Parameter Values for JWS for | ||
* the specified key. The digest algorithm is assumed to be SHA2-256. | ||
* | ||
* Throws on error. | ||
* | ||
* @see RFC 7518 section 3.1 | ||
*/ | ||
std::string_view | ||
GetAlg(const EVP_PKEY &key); | ||
|
||
} // namespace JWS |
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