mas_jose/jwa/
mod.rs

1// Copyright 2022 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use mas_iana::jose::JsonWebSignatureAlg;
16use sha2::{Sha256, Sha384, Sha512};
17
18mod asymmetric;
19pub(crate) mod hmac;
20mod signature;
21mod symmetric;
22
23pub use self::{
24    asymmetric::{AsymmetricKeyFromJwkError, AsymmetricSigningKey, AsymmetricVerifyingKey},
25    symmetric::{InvalidAlgorithm, SymmetricKey},
26};
27
28pub type Hs256Key = self::hmac::Hmac<Sha256>;
29pub type Hs384Key = self::hmac::Hmac<Sha384>;
30pub type Hs512Key = self::hmac::Hmac<Sha512>;
31
32pub type Rs256SigningKey = rsa::pkcs1v15::SigningKey<Sha256>;
33pub type Rs256VerifyingKey = rsa::pkcs1v15::VerifyingKey<Sha256>;
34pub type Rs384SigningKey = rsa::pkcs1v15::SigningKey<Sha384>;
35pub type Rs384VerifyingKey = rsa::pkcs1v15::VerifyingKey<Sha384>;
36pub type Rs512SigningKey = rsa::pkcs1v15::SigningKey<Sha512>;
37pub type Rs512VerifyingKey = rsa::pkcs1v15::VerifyingKey<Sha512>;
38
39pub type Ps256SigningKey = rsa::pss::SigningKey<Sha256>;
40pub type Ps256VerifyingKey = rsa::pss::VerifyingKey<Sha256>;
41pub type Ps384SigningKey = rsa::pss::SigningKey<Sha384>;
42pub type Ps384VerifyingKey = rsa::pss::VerifyingKey<Sha384>;
43pub type Ps512SigningKey = rsa::pss::SigningKey<Sha512>;
44pub type Ps512VerifyingKey = rsa::pss::VerifyingKey<Sha512>;
45
46pub type Es256SigningKey = ecdsa::SigningKey<p256::NistP256>;
47pub type Es256VerifyingKey = ecdsa::VerifyingKey<p256::NistP256>;
48pub type Es384SigningKey = ecdsa::SigningKey<p384::NistP384>;
49pub type Es384VerifyingKey = ecdsa::VerifyingKey<p384::NistP384>;
50pub type Es256KSigningKey = ecdsa::SigningKey<k256::Secp256k1>;
51pub type Es256KVerifyingKey = ecdsa::VerifyingKey<k256::Secp256k1>;
52
53/// All the signing algorithms supported by this crate.
54pub const SUPPORTED_SIGNING_ALGORITHMS: [JsonWebSignatureAlg; 12] = [
55    JsonWebSignatureAlg::Hs256,
56    JsonWebSignatureAlg::Hs384,
57    JsonWebSignatureAlg::Hs512,
58    JsonWebSignatureAlg::Rs256,
59    JsonWebSignatureAlg::Rs384,
60    JsonWebSignatureAlg::Rs512,
61    JsonWebSignatureAlg::Ps256,
62    JsonWebSignatureAlg::Ps384,
63    JsonWebSignatureAlg::Ps512,
64    JsonWebSignatureAlg::Es256,
65    JsonWebSignatureAlg::Es384,
66    JsonWebSignatureAlg::Es256K,
67];