-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
unparsed: expose content of the extension #72
Conversation
Unparsed is intended to hold the value of the extension. Specification calls for: ``` byte SSH_AGENTC_EXTENSION string extension type byte[] extension request-specific contents ``` But does not mandates for content to be serialized according to ssh regular serialization format (as in implements `ssh_encoding::Decode`). The `Unparsed::From` implementation allows for content to be formatted in any serialization, but you can't read data back unless it was encoded according to SSH serialization. This partially reverts wiktor-k#67 Signed-off-by: Arthur Gautier <[email protected]>
src/proto/message/unparsed.rs
Outdated
@@ -16,6 +16,11 @@ impl Unparsed { | |||
let mut v = &self.0[..]; | |||
T::decode(&mut v) | |||
} | |||
|
|||
/// Expose the inner content in raw format. | |||
pub fn as_slice(&self) -> &[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.
I would be happy to add an hazmat
feature if needed, or rename it like as_raw
or something to highlight this is dangerous, but then I would argue From<Vec<u8>>
should be removed too and replaced by:
impl Unparsed {
pub fn new<T>(v: T) where T: ssh_encoding::Encoding -> Result<Self> {
}
}
to highlight that.
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.
Okay, I like the "as raw" naming. Maybe to keep the symmetry we'd need "from raw" which takes a vec of unparsed data and doesn't interpret it in any way?
I like this new constructor. Do I read the signature well that it is intended for ssh encod-able data not for raw stuff?
I mean... we need raw support for crazy folks that want to use serde there (just when we got rid of it 😉).
One potential addition, not sure if good, is implementing AsRef<[u8]>
. This would allow treating Unparsed as byte buffers (the implementation is the same as what you have here, just... more idiomatic (?)).
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.
AsRef<[u8]>
makes accessing the content not-so-explicit imho, which renders the use of a type system a bit moot.
Signed-off-by: Arthur Gautier <[email protected]>
Just to be transparent about the intent: Arguably I could just shove everything in a Vec and hand that to Unparsed, but that makes for a double (or triple) serialization, and I find it somehow irritating. |
Add conversion methods to gain access to the inner bytes of `Unparsed`, per discussion in wiktor-k#72 Signed-off-by: Ross Williams <[email protected]>
SummaryPR #73 opened to show proposed alternative.
DiscussionThe ssh-agent-lib/src/proto/message/unparsed.rs Lines 32 to 39 in 845c218
Regarding the Regarding
I don't think there is any double- or triple-serialization or even allocation happening in this case, because the If we wanted to provide an owned-not-borrowed deserialization path, I'd propose the inverse of |
superseded by #73 |
Unparsed is intended to hold the value of the extension. Specification calls for:
But does not mandates for content to be serialized according to ssh regular serialization format (as in implements
ssh_encoding::Decode
).The
Unparsed::From
implementation allows for content to be formatted in any serialization, but you can't read data back unless it was encoded according to SSH serialization.This partially reverts #67