Skip to content

Commit

Permalink
jwt/OsslJWS: basic JWS definitions for OpenSSL
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Nov 3, 2023
1 parent 4032405 commit f0a7140
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/jwt/OsslJWS.cxx
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
24 changes: 24 additions & 0 deletions src/jwt/OsslJWS.hxx
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
1 change: 1 addition & 0 deletions src/jwt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jwt = static_library(
'RS256.cxx',
'EdDSA.cxx',
'OsslJWK.cxx',
'OsslJWS.cxx',
include_directories: inc,
dependencies: [
crypto_dep,
Expand Down

0 comments on commit f0a7140

Please sign in to comment.