Skip to content

Conversation

@eyakubovich
Copy link

Allow for constructing a Jwk from a decoding key.
This allows it to be created from a DER encoded file, for example.

This patch refactors some Jwk internals to reduce code duplication.

@Keats
Copy link
Owner

Keats commented Jan 5, 2026

That will need to wait a bit, we need to merge #452 first that has a lot of change that would overlap with some of your changes.

@eyakubovich
Copy link
Author

@Keats @arckoor PTAL. I removed JwkUtils (technically those functions are not JWK specific) and put everything up at the same level. However I added separate structs from RSA and EC component extraction, each with a from_private and from_public functions.

As an aside, why are function pointers used instead of traits?

Copy link
Contributor

@arckoor arckoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, why are function pointers used instead of traits?

It was what happened to work when I implemented it, I didn't explicitly choose not to use traits, there wasn't any deep logic behind it.
I didn't necessarily plan for more stuff being added in the future

Comment on lines 208 to 175
pub(crate) fn ec_components_from_public_key(
pub_bytes: &[u8],
) -> errors::Result<(EllipticCurve, Vec<u8>, Vec<u8>)> {
let (curve, pub_elem_bytes) = match pub_bytes.len() {
65 => (EllipticCurve::P256, 32),
97 => (EllipticCurve::P384, 48),
_ => return Err(ErrorKind::InvalidEcdsaKey.into()),
};

if pub_bytes[0] != 4 {
return Err(ErrorKind::InvalidEcdsaKey.into());
}

let (x, y) = pub_bytes[1..].split_at(pub_elem_bytes);
Ok((curve, x.to_vec(), y.to_vec()))
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't depend on the crypto backend, and shouldn't be part of the public api. Remove that from EcPublicComponents, which then has only one attribute, so should be combined with RsaPublicComponents into something like PublicComponents or similar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it into the crypto backend for symmetry but also because the fact that it doesn't depend on the crypto backend is an implementation detail. From the user POV, it's a crypto related operation. Technically it's an operation on a data/file format, not a crypto algorithm but neither are the rest of the extraction functions.

If I pull it out, what module should I put into?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The end user doesn't really care about this, third party providers do. If it were to remain, every other provider would need to reference it in their CryptoProvider, for seemingly no reason at all (also it would need to be public).

I guess you could pull it out to jwk.rs, but for consistency it's probably not too bad if it stays with the CryptoProvider
I'm not really set on that though

}

impl RsaPublicComponents {
/// Creates a instance filled with dummy functions that always panic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an instance

/// Initialises all values to dummies.
/// Will lead to a panic when JWKs are required, so only use it if you don't want to support JWKs.
impl EcPublicComponents {
/// Creates a instance filled with dummy functions that always panic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an instance

Comment on lines 3 to 5
pkcs1::{
DecodeRsaPrivateKey, DecodeRsaPublicKey
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt, for many files

pub rsa_public_components: RsaPublicComponents,
/// Functions to extract EC public key components from private and public keys
pub ec_public_components: EcPublicComponents,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the newlines everywhere?

@eyakubovich eyakubovich force-pushed the ey/jwk-from-decoding-key branch 2 times, most recently from 4e8bd5f to 7a64e5d Compare January 15, 2026 19:42
@eyakubovich eyakubovich requested a review from arckoor January 15, 2026 19:42
@eyakubovich eyakubovich force-pushed the ey/jwk-from-decoding-key branch from 7a64e5d to 89c40ef Compare January 15, 2026 19:44
Allow for constructing a Jwk from a decoding key.
This allows it to be created from a DER encoded file, for example.

This patch flattens JwkUtils but adds separate structs for RSA and EC
component extraction.
@eyakubovich eyakubovich force-pushed the ey/jwk-from-decoding-key branch from 89c40ef to 4cf5422 Compare January 16, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants