mas_jose/jwa/
mod.rs

1// Copyright 2024 New Vector Ltd.
2// Copyright 2022-2024 The Matrix.org Foundation C.I.C.
3//
4// SPDX-License-Identifier: AGPL-3.0-only
5// Please see LICENSE in the repository root for full details.
6
7use mas_iana::jose::JsonWebSignatureAlg;
8use sha2::{Sha256, Sha384, Sha512};
9
10mod asymmetric;
11pub(crate) mod hmac;
12mod signature;
13mod symmetric;
14
15pub use self::{
16    asymmetric::{AsymmetricKeyFromJwkError, AsymmetricSigningKey, AsymmetricVerifyingKey},
17    symmetric::{InvalidAlgorithm, SymmetricKey},
18};
19
20pub type Hs256Key = self::hmac::Hmac<Sha256>;
21pub type Hs384Key = self::hmac::Hmac<Sha384>;
22pub type Hs512Key = self::hmac::Hmac<Sha512>;
23
24pub type Rs256SigningKey = rsa::pkcs1v15::SigningKey<Sha256>;
25pub type Rs256VerifyingKey = rsa::pkcs1v15::VerifyingKey<Sha256>;
26pub type Rs384SigningKey = rsa::pkcs1v15::SigningKey<Sha384>;
27pub type Rs384VerifyingKey = rsa::pkcs1v15::VerifyingKey<Sha384>;
28pub type Rs512SigningKey = rsa::pkcs1v15::SigningKey<Sha512>;
29pub type Rs512VerifyingKey = rsa::pkcs1v15::VerifyingKey<Sha512>;
30
31pub type Ps256SigningKey = rsa::pss::SigningKey<Sha256>;
32pub type Ps256VerifyingKey = rsa::pss::VerifyingKey<Sha256>;
33pub type Ps384SigningKey = rsa::pss::SigningKey<Sha384>;
34pub type Ps384VerifyingKey = rsa::pss::VerifyingKey<Sha384>;
35pub type Ps512SigningKey = rsa::pss::SigningKey<Sha512>;
36pub type Ps512VerifyingKey = rsa::pss::VerifyingKey<Sha512>;
37
38pub type Es256SigningKey = ecdsa::SigningKey<p256::NistP256>;
39pub type Es256VerifyingKey = ecdsa::VerifyingKey<p256::NistP256>;
40pub type Es384SigningKey = ecdsa::SigningKey<p384::NistP384>;
41pub type Es384VerifyingKey = ecdsa::VerifyingKey<p384::NistP384>;
42pub type Es256KSigningKey = ecdsa::SigningKey<k256::Secp256k1>;
43pub type Es256KVerifyingKey = ecdsa::VerifyingKey<k256::Secp256k1>;
44
45/// All the signing algorithms supported by this crate.
46pub const SUPPORTED_SIGNING_ALGORITHMS: [JsonWebSignatureAlg; 12] = [
47    JsonWebSignatureAlg::Hs256,
48    JsonWebSignatureAlg::Hs384,
49    JsonWebSignatureAlg::Hs512,
50    JsonWebSignatureAlg::Rs256,
51    JsonWebSignatureAlg::Rs384,
52    JsonWebSignatureAlg::Rs512,
53    JsonWebSignatureAlg::Ps256,
54    JsonWebSignatureAlg::Ps384,
55    JsonWebSignatureAlg::Ps512,
56    JsonWebSignatureAlg::Es256,
57    JsonWebSignatureAlg::Es384,
58    JsonWebSignatureAlg::Es256K,
59];