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

fix: into_jwk takes Option<impl Into<..>> #98

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/jwk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,5 @@ pub trait IntoJsonWebKey: Sealed {
/// # Errors
///
/// Returns an [`Err`] if the conversion fails.
fn into_jwk(self, alg: impl Into<Option<Self::Algorithm>>) -> Result<JsonWebKey, Self::Error>;
fn into_jwk(self, alg: Option<impl Into<Self::Algorithm>>) -> Result<JsonWebKey, Self::Error>;
}
12 changes: 4 additions & 8 deletions src/jwk/okp/curve25519/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,12 @@
type Algorithm = ();
type Error = Infallible;

fn into_jwk(self, alg: impl Into<Option<Self::Algorithm>>) -> Result<JsonWebKey, Self::Error> {
fn into_jwk(self, alg: Option<impl Into<Self::Algorithm>>) -> Result<JsonWebKey, Self::Error> {

Check warning on line 138 in src/jwk/okp/curve25519/ed25519.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/okp/curve25519/ed25519.rs#L138

Added line #L138 was not covered by tests
let key = JsonWebKeyType::Asymmetric(Box::new(AsymmetricJsonWebKey::Private(
Private::Okp(OkpPrivate::Curve25519(Curve25519Private::Ed(self))),
)));
let mut jwk = JsonWebKey::new(key);
jwk.algorithm = alg
.into()
.map(|_| JsonWebAlgorithm::Signing(JsonWebSigningAlgorithm::EdDSA));
jwk.algorithm = alg.map(|_| JsonWebAlgorithm::Signing(JsonWebSigningAlgorithm::EdDSA));

Check warning on line 143 in src/jwk/okp/curve25519/ed25519.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/okp/curve25519/ed25519.rs#L143

Added line #L143 was not covered by tests
Ok(jwk)
}
}
Expand All @@ -152,14 +150,12 @@
type Algorithm = ();
type Error = Infallible;

fn into_jwk(self, alg: impl Into<Option<Self::Algorithm>>) -> Result<JsonWebKey, Self::Error> {
fn into_jwk(self, alg: Option<impl Into<Self::Algorithm>>) -> Result<JsonWebKey, Self::Error> {

Check warning on line 153 in src/jwk/okp/curve25519/ed25519.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/okp/curve25519/ed25519.rs#L153

Added line #L153 was not covered by tests
let key = JsonWebKeyType::Asymmetric(Box::new(AsymmetricJsonWebKey::Public(Public::Okp(
OkpPublic::Curve25519(Curve25519Public::Ed(self)),
))));
let mut jwk = JsonWebKey::new(key);
jwk.algorithm = alg
.into()
.map(|_| JsonWebAlgorithm::Signing(JsonWebSigningAlgorithm::EdDSA));
jwk.algorithm = alg.map(|_| JsonWebAlgorithm::Signing(JsonWebSigningAlgorithm::EdDSA));

Check warning on line 158 in src/jwk/okp/curve25519/ed25519.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/okp/curve25519/ed25519.rs#L158

Added line #L158 was not covered by tests
Ok(jwk)
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/jwk/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@

fn into_jwk(
self,
alg: impl Into<Option<Self::Algorithm>>,
alg: Option<impl Into<Self::Algorithm>>,

Check warning on line 42 in src/jwk/rsa.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/rsa.rs#L42

Added line #L42 was not covered by tests
) -> Result<crate::JsonWebKey, Self::Error> {
let alg = alg
.into()
.map(|rsa| jwa::JsonWebAlgorithm::Signing(jwa::JsonWebSigningAlgorithm::Rsa(rsa)));
let alg = alg.map(|rsa| {
jwa::JsonWebAlgorithm::Signing(jwa::JsonWebSigningAlgorithm::Rsa(rsa.into()))
});

Check warning on line 46 in src/jwk/rsa.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/rsa.rs#L44-L46

Added lines #L44 - L46 were not covered by tests

let key = super::JsonWebKeyType::Asymmetric(Box::new(super::AsymmetricJsonWebKey::Public(
super::Public::Rsa(self),
Expand Down Expand Up @@ -150,11 +150,11 @@

fn into_jwk(
self,
alg: impl Into<Option<Self::Algorithm>>,
alg: Option<impl Into<Self::Algorithm>>,

Check warning on line 153 in src/jwk/rsa.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/rsa.rs#L153

Added line #L153 was not covered by tests
) -> Result<crate::JsonWebKey, Self::Error> {
let alg = alg
.into()
.map(|rsa| jwa::JsonWebAlgorithm::Signing(jwa::JsonWebSigningAlgorithm::Rsa(rsa)));
let alg = alg.map(|rsa| {
jwa::JsonWebAlgorithm::Signing(jwa::JsonWebSigningAlgorithm::Rsa(rsa.into()))
});

Check warning on line 157 in src/jwk/rsa.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/rsa.rs#L155-L157

Added lines #L155 - L157 were not covered by tests

let key = super::JsonWebKeyType::Asymmetric(Box::new(
super::AsymmetricJsonWebKey::Private(super::Private::Rsa(Box::new(self))),
Expand Down
4 changes: 2 additions & 2 deletions src/jwk/symmetric/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@

fn into_jwk(
self,
alg: impl Into<Option<Self::Algorithm>>,
alg: Option<impl Into<Self::Algorithm>>,

Check warning on line 128 in src/jwk/symmetric/hmac.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/symmetric/hmac.rs#L128

Added line #L128 was not covered by tests
) -> Result<crate::JsonWebKey, Self::Error> {
let key = jwk::JsonWebKeyType::Symmetric(jwk::SymmetricJsonWebKey::OctetSequence(
OctetSequence::new(self.key),
));

let mut jwk = crate::JsonWebKey::new(key);
jwk.algorithm = alg.into().map(|_| JsonWebAlgorithm::Signing(H::ALGORITHM));
jwk.algorithm = alg.map(|_| JsonWebAlgorithm::Signing(H::ALGORITHM));

Check warning on line 135 in src/jwk/symmetric/hmac.rs

View check run for this annotation

Codecov / codecov/patch

src/jwk/symmetric/hmac.rs#L135

Added line #L135 was not covered by tests
Ok(jwk)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

fn into_jwk(
self,
alg: impl Into<Option<Self::Algorithm>>,
alg: Option<impl Into<Self::Algorithm>>,

Check warning on line 47 in src/macros.rs

View check run for this annotation

Codecov / codecov/patch

src/macros.rs#L47

Added line #L47 was not covered by tests
) -> Result<crate::JsonWebKey, Self::Error> {
let key = crate::jwk::JsonWebKeyType::Asymmetric(alloc::boxed::Box::new(
crate::jwk::AsymmetricJsonWebKey::Public(crate::jwk::Public::Ec(
Expand All @@ -53,7 +53,7 @@
));

let mut jwk = crate::JsonWebKey::new(key);
jwk.algorithm = alg.into().map(|_| crate::jwa::JsonWebAlgorithm::Signing($alg));
jwk.algorithm = alg.map(|_| crate::jwa::JsonWebAlgorithm::Signing($alg.into()));

Check warning on line 56 in src/macros.rs

View check run for this annotation

Codecov / codecov/patch

src/macros.rs#L56

Added line #L56 was not covered by tests
Ok(jwk)
}
}
Expand All @@ -74,7 +74,7 @@

fn into_jwk(
self,
alg: impl Into<Option<Self::Algorithm>>,
alg: Option<impl Into<Self::Algorithm>>,

Check warning on line 77 in src/macros.rs

View check run for this annotation

Codecov / codecov/patch

src/macros.rs#L77

Added line #L77 was not covered by tests
) -> Result<crate::JsonWebKey, Self::Error> {
let key = crate::jwk::JsonWebKeyType::Asymmetric(alloc::boxed::Box::new(
crate::jwk::AsymmetricJsonWebKey::Private(crate::jwk::Private::Ec(
Expand All @@ -83,7 +83,7 @@
));

let mut jwk = crate::JsonWebKey::new(key);
jwk.algorithm = alg.into().map(|_| crate::jwa::JsonWebAlgorithm::Signing($alg));
jwk.algorithm = alg.map(|_| crate::jwa::JsonWebAlgorithm::Signing($alg.into()));

Check warning on line 86 in src/macros.rs

View check run for this annotation

Codecov / codecov/patch

src/macros.rs#L86

Added line #L86 was not covered by tests
Ok(jwk)
}
}
Expand Down
Loading