Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(jwa): move algorithm types into jose-jwa #5

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions jose-jwa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ readme = "README.md"
edition = "2021"
rust-version = "1.63"

[dependencies]
serde = { version = "1.0.136", default-features = false, features = ["alloc", "derive"] }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
88 changes: 88 additions & 0 deletions jose-jwa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![doc = include_str!("../README.md")]
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
Expand All @@ -15,3 +18,88 @@
unused_lifetimes,
unused_qualifications
)]

use serde::{Deserialize, Serialize};

/// Algorithms
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[allow(missing_docs)]
#[serde(untagged)]
#[non_exhaustive]
pub enum Algorithm {
Signing(Signing),
}

impl From<Signing> for Algorithm {
#[inline(always)]
fn from(alg: Signing) -> Self {
Self::Signing(alg)
}
}

/// Signing Algorithms
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Signing {
/// EdDSA signature algorithms (Optional)
#[serde(rename = "EdDSA")]
EdDsa,

/// ECDSA using P-256 and SHA-256 (Recommended+)
#[serde(rename = "ES256")]
Es256,

/// ECDSA using secp256k1 curve and SHA-256 (Optional)
#[serde(rename = "ES256K")]
Es256K,

/// ECDSA using P-384 and SHA-384 (Optional)
#[serde(rename = "ES384")]
Es384,

/// ECDSA using P-521 and SHA-512 (Optional)
#[serde(rename = "ES512")]
Es512,

/// HMAC using SHA-256 (Required)
#[serde(rename = "HS256")]
Hs256,

/// HMAC using SHA-384 (Optional)
#[serde(rename = "HS384")]
Hs384,

/// HMAC using SHA-512 (Optional)
#[serde(rename = "HS512")]
Hs512,

/// RSASSA-PSS using SHA-256 and MGF1 with SHA-256 (Optional)
#[serde(rename = "PS256")]
Ps256,

/// RSASSA-PSS using SHA-384 and MGF1 with SHA-384 (Optional)
#[serde(rename = "PS384")]
Ps384,

/// RSASSA-PSS using SHA-512 and MGF1 with SHA-512 (Optional)
#[serde(rename = "PS512")]
Ps512,

/// RSASSA-PKCS1-v1_5 using SHA-256 (Recommended)
#[serde(rename = "RS256")]
Rs256,

/// RSASSA-PKCS1-v1_5 using SHA-384 (Optional)
#[serde(rename = "RS384")]
Rs384,

/// RSASSA-PKCS1-v1_5 using SHA-512 (Optional)
#[serde(rename = "RS512")]
Rs512,

/// No digital signature or MAC performed (Optional)
///
/// This variant is renamed as `Null` to avoid colliding with `Option::None`.
#[serde(rename = "none")]
Null,
}
1 change: 1 addition & 0 deletions jose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rsa = ["dep:rand_core", "dep:rsa"]
serde = { version = "1.0.136", default-features = false, features = ["alloc", "derive"] }
zeroize = { version = "1.5.7", default-features = false, features = ["alloc", "serde"] }
subtle = { version = "2.4.1", default-features = false }
jose-jwa = { path = "../jose-jwa" }

# Optional Dependencies
url = { version = "2.2.2", default-features = false, optional = true, features = ["serde"] }
Expand Down
88 changes: 2 additions & 86 deletions jose/src/alg.rs
Original file line number Diff line number Diff line change
@@ -1,90 +1,6 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! IANA-Defined Algorithms

use serde::{Deserialize, Serialize};

/// Algorithms
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[allow(missing_docs)]
#[serde(untagged)]
#[non_exhaustive]
pub enum Algorithm {
Signing(Signing),
Unknown(alloc::string::String),
}

impl From<Signing> for Algorithm {
#[inline(always)]
fn from(alg: Signing) -> Self {
Self::Signing(alg)
}
}

/// Signing Algorithms
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Signing {
/// EdDSA signature algorithms (Optional)
#[serde(rename = "EdDSA")]
EdDsa,

/// ECDSA using P-256 and SHA-256 (Recommended+)
#[serde(rename = "ES256")]
Es256,

/// ECDSA using secp256k1 curve and SHA-256 (Optional)
#[serde(rename = "ES256K")]
Es256K,

/// ECDSA using P-384 and SHA-384 (Optional)
#[serde(rename = "ES384")]
Es384,

/// ECDSA using P-521 and SHA-512 (Optional)
#[serde(rename = "ES512")]
Es512,

/// HMAC using SHA-256 (Required)
#[serde(rename = "HS256")]
Hs256,

/// HMAC using SHA-384 (Optional)
#[serde(rename = "HS384")]
Hs384,

/// HMAC using SHA-512 (Optional)
#[serde(rename = "HS512")]
Hs512,

/// RSASSA-PSS using SHA-256 and MGF1 with SHA-256 (Optional)
#[serde(rename = "PS256")]
Ps256,

/// RSASSA-PSS using SHA-384 and MGF1 with SHA-384 (Optional)
#[serde(rename = "PS384")]
Ps384,

/// RSASSA-PSS using SHA-512 and MGF1 with SHA-512 (Optional)
#[serde(rename = "PS512")]
Ps512,

/// RSASSA-PKCS1-v1_5 using SHA-256 (Recommended)
#[serde(rename = "RS256")]
Rs256,

/// RSASSA-PKCS1-v1_5 using SHA-384 (Optional)
#[serde(rename = "RS384")]
Rs384,

/// RSASSA-PKCS1-v1_5 using SHA-512 (Optional)
#[serde(rename = "RS512")]
Rs512,

/// No digital signature or MAC performed (Optional)
///
/// This variant is renamed as `Null` to avoid colliding with `Option::None`.
#[serde(rename = "none")]
Null,
}
pub use jose_jwa::{Algorithm, Signing};
2 changes: 1 addition & 1 deletion jose/src/b64/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use alloc::boxed::Box;
use alloc::string::String;
Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/codec/dec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use core::convert::Infallible;
use core::marker::PhantomData;
Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/codec/enc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use core::marker::PhantomData;
use zeroize::Zeroizing;
Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/codec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

mod dec;
mod enc;
Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/json.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![cfg(feature = "jws")]

Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Base64 Conversion Utilities

Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/optional.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use super::{Config, Encoder, Update, UrlSafe};

Expand Down
2 changes: 1 addition & 1 deletion jose/src/b64/secret.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use alloc::boxed::Box;
use core::fmt::Debug;
Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/crypto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK Cryptographic Implementation

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/crypto/rcrypto/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use super::super::super::*;
use crate::key::rcrypto::{Key, Type};
Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/crypto/rcrypto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK integrations with RustCrypto types

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/crypto/rcrypto/p256.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![cfg(feature = "p256")]

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/crypto/rcrypto/p384.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![cfg(feature = "p384")]

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/crypto/rcrypto/rsa.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![cfg(feature = "rsa")]

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/key/ec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK elliptic-curve key material.

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/key/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK key material.

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/key/oct.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK symmetric key material.

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/key/okp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK CFRG-curve key material.

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/key/rsa.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK RSA key material.

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jwk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK: JSON Web Key

Expand Down
5 changes: 2 additions & 3 deletions jose/src/jwk/prm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWK parameter types.

Expand Down Expand Up @@ -55,8 +55,7 @@ impl<T: Into<Algorithm>> From<T> for Parameters {

let cls = match alg {
Some(Algorithm::Signing(..)) => Some(Class::Signing),
Some(Algorithm::Unknown(..)) => None,
None => None,
_ => None,
};

Self {
Expand Down
2 changes: 1 addition & 1 deletion jose/src/jws/crypto/core.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use alloc::vec::Vec;

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jws/crypto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWS Cryptographic Implementation

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jws/crypto/rcrypto/hmac.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

#![cfg(feature = "hmac")]

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jws/crypto/rcrypto/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

use alloc::boxed::Box;

Expand Down
2 changes: 1 addition & 1 deletion jose/src/jws/crypto/rcrypto/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2022 Profian Inc. <opensource@profian.com>
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! JWS integrations with RustCrypto types

Expand Down