-
Notifications
You must be signed in to change notification settings - Fork 156
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
added serdect support #420
Conversation
Since all of these have a straightforward serialization to bytes, it would be good to use that, rather than custom derive. @dignifiedquire perhaps we should use the |
Why has |
It hasn't been used in the |
So kinda like this? impl Serialize for Signature {
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
S: serdect::serde::Serializer,
{
serdect::slice::serialize_hex_lower_or_bin(&self.inner.to_bytes_be(), serializer)
}
}
impl<'de> Deserialize<'de> for Signature {
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: serdect::serde::Deserializer<'de>,
{
let bytes = serdect::slice::deserialize_hex_or_bin_vec(deserializer)?;
let inner = BigUint::from_bytes_be(&bytes);
Ok(Self {
inner,
len: bytes.len(),
})
}
} I can also do the others |
sure 👍 |
I guess only |
@LWEdslev the |
@tarcieri |
|
Co-authored-by: Tony Arcieri <[email protected]>
Should I add some |
Sure |
Due to the |
Can you post the code that isn’t working? |
For the #[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
use serde_test::{assert_tokens, Configure, Token};
let mut rng = ChaCha8Rng::from_seed([42; 32]);
let priv_key = crate::RsaPrivateKey::new(&mut rng, 64).expect("failed to generate key");
let encrypting_key = EncryptingKey::<sha2::Sha256>::new(priv_key.to_public_key());
let tokens = [
Token::Struct { name: "EncryptingKey", len: 2 },
Token::Str("inner"),
Token::Str("3024300d06092a864886f70d01010105000313003010020900cc6c6130e35b46bf0203010001"),
Token::Str("label"),
Token::Str("None"),
Token::StructEnd,
];
assert_tokens(&encrypting_key.readable(), &tokens);
} To use the error[E0277]: can't compare `CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, OidSha256>>` with `CoreWrapper<CtVariableCoreWrapper<Sha256VarCore, UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, OidSha256>>` |
As a bit of a meta comment on the above suggestions: all of these types have built-in serialization support that the |
Yeah, that's better |
How do I make the Edit: I see that this is addressed in #422 |
@tarcieri I don't see how either OID should work for the private_key_info
.algorithm
.assert_algorithm_oid(ID_RSASSA_PSS)?;
self.inner.to_pkcs8_der() And the inner |
@LWEdslev aah, so it does. It should probably use |
@tarcieri Will you review this when you have time? |
Yes |
D: Digest, | ||
{ | ||
fn eq(&self, other: &Self) -> bool { | ||
self.inner == other.inner && self.salt_len == other.salt_len |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I just noticed the derived Eq
/PartialEq
on RsaPrivateKey
are not constant-time, which seems bad, although not directly related to this PR except it's indirectly invoking it.
private_key_info | ||
.algorithm | ||
.assert_algorithm_oid(ID_RSASSA_PSS)?; | ||
verify_algorithm_id(&private_key_info.algorithm)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is a fix for handling PKCS#8 keys with PSS OIDs
Co-authored-by: Tony Arcieri <[email protected]>
Added serde support (Serialization, Deserialization) for structs in
src/pkcs1v15/
:#419