-
Notifications
You must be signed in to change notification settings - Fork 18
Serialize Vec<u8> in RPC struct fields to 0x-prefixed-hex-string #3355
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
Serialize Vec<u8> in RPC struct fields to 0x-prefixed-hex-string #3355
Conversation
pub n: Vec<u8>, | ||
#[serde_as(as = "serde_with::hex::Hex")] | ||
pub e: Vec<u8>, | ||
} |
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.
Shall we make Rsa3072PubKey to use fixed-size arrays to guarantee 3072-bit key length as below?:
pub struct Rsa3072PubKey {
pub n: [u8; 384],
pub e: [u8; 3],
}
pub e: Vec<u8>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct SerdeRsa3072PubKey { |
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.
Would it be better to rename this to SerdeRsaPubKey because the struct can handle RSA public keys of any length, not just 3072-bit?
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 mean this struct itself is a counterpart of Rsa3072PubKey
- so if we want to rename it, we have to rename both.
But Rsa3072PubKey
is serialised from public key of ShieldingKey
- which is a 3072 bit rsa key pair. So actually I think it's fine
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.
Bytes
seems like a quick solution, I do have one question other than that LGTM
|
||
impl From<Rsa3072PubKey> for SerdeRsa3072PubKey { | ||
fn from(k: Rsa3072PubKey) -> Self { | ||
Self { n: k.n.into(), e: k.e.into() } |
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.
Why do we need the wrapper, if the Bytes
support conversion to Vec
, this might get cumbersome for other types we want to ensure 0x
, if only here then i guess it's fine.
Context
As topic - it uses
ethers::types::Bytes
to do this.Alternatively we could write a manual serializer/deserializer, but I think that's too verbose.
Extra struct is defined to keep the original struct SCALE-codecable as we still use it internally. E.g.
AesOutput
vsSerdeAesOutput