feat: add Jwk::from_decoding_key#475
Conversation
|
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. |
5260d7c to
4016f48
Compare
|
@Keats @arckoor PTAL. I removed As an aside, why are function pointers used instead of traits? |
There was a problem hiding this comment.
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
4e8bd5f to
7a64e5d
Compare
89c40ef to
4cf5422
Compare
4cf5422 to
d648c85
Compare
|
Ping. I addressed the comments. Please unlock the workflows to run the checks. |
e7c7b58 to
c065e8c
Compare
c065e8c to
b7754f5
Compare
|
Please rebase to latest master. A bunch of other PRs are also adding more utility functions to |
Allow for constructing a Jwk from a decoding key. This allows it to be created from a DER encoded file, for example. This patch renames JwkUtils to KeyUtils.
b7754f5 to
3888bab
Compare
|
Rebased, brought back the struct and called it |
| #[allow(unused)] | ||
| 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())) | ||
| } | ||
|
|
There was a problem hiding this comment.
This still can't be part of KeyUtils / the CryptoProvider as a whole, it's completely inaccessible from the outside of the crate. What about just making it pub(crate) and referring to it directly from jwk.rs? Should also be ec_pub_components_...
| unimplemented!(); | ||
| unimplemented!("Edwards curve is not supported"); |
There was a problem hiding this comment.
Document this please, from_encoding_key should have a doc comment either way
| }) | ||
| } | ||
|
|
||
| pub fn from_decoding_key( |
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.