Skip to content

Commit abeb914

Browse files
committed
Refactor proto::message::SignRequest to module
Signed-off-by: Ross Williams <ross@ross-williams.net>
1 parent 2f232d9 commit abeb914

File tree

2 files changed

+62
-54
lines changed

2 files changed

+62
-54
lines changed

src/proto/message.rs

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Agent protocol message structures.
22
33
pub mod identity;
4+
pub mod sign;
45
pub mod unparsed;
56

67
use core::str::FromStr;
@@ -10,67 +11,14 @@ use ssh_key::{
1011
certificate::Certificate, private::KeypairData, public::KeyData, Algorithm, Error, Signature,
1112
};
1213

13-
pub use self::{identity::*, unparsed::*};
14+
pub use self::{identity::*, sign::*, unparsed::*};
1415
use super::{
1516
extension::{KeyConstraintExtension, MessageExtension},
1617
PrivateKeyData, ProtoError,
1718
};
1819

1920
type Result<T> = core::result::Result<T, ProtoError>;
2021

21-
/// Signature request with data to be signed with a key in an agent.
22-
///
23-
/// This structure is sent in a [`Request::SignRequest`] (`SSH_AGENTC_SIGN_REQUEST`) message.
24-
///
25-
/// Described in [draft-miller-ssh-agent-14 § 3.6](https://www.ietf.org/archive/id/draft-miller-ssh-agent-14.html#section-3.6)
26-
#[derive(Clone, PartialEq, Debug)]
27-
pub struct SignRequest {
28-
/// The public key portion of the [`Identity`] in the agent to sign the data with
29-
pub pubkey: KeyData,
30-
31-
/// Binary data to be signed
32-
pub data: Vec<u8>,
33-
34-
/// Signature flags, as described in
35-
/// [draft-miller-ssh-agent-14 § 3.6.1](https://www.ietf.org/archive/id/draft-miller-ssh-agent-14.html#section-3.6.1)
36-
pub flags: u32,
37-
}
38-
39-
impl Decode for SignRequest {
40-
type Error = ProtoError;
41-
42-
fn decode(reader: &mut impl Reader) -> Result<Self> {
43-
let pubkey = reader.read_prefixed(KeyData::decode)?;
44-
let data = Vec::decode(reader)?;
45-
let flags = u32::decode(reader)?;
46-
47-
Ok(Self {
48-
pubkey,
49-
data,
50-
flags,
51-
})
52-
}
53-
}
54-
55-
impl Encode for SignRequest {
56-
fn encoded_len(&self) -> ssh_encoding::Result<usize> {
57-
[
58-
self.pubkey.encoded_len_prefixed()?,
59-
self.data.encoded_len()?,
60-
self.flags.encoded_len()?,
61-
]
62-
.checked_sum()
63-
}
64-
65-
fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
66-
self.pubkey.encode_prefixed(writer)?;
67-
self.data.encode(writer)?;
68-
self.flags.encode(writer)?;
69-
70-
Ok(())
71-
}
72-
}
73-
7422
/// A container for a public / private key pair, or a certificate / private key.
7523
///
7624
/// When adding an identity to an agent, a user can provide either:

src/proto/message/sign.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! Signature request with data to be signed with a key in an agent.
2+
3+
use ssh_encoding::{self, CheckedSum, Decode, Encode, Reader, Writer};
4+
use ssh_key::public::KeyData;
5+
6+
use super::Result;
7+
use crate::proto::ProtoError;
8+
9+
/// Signature request with data to be signed with a key in an agent.
10+
///
11+
/// This structure is sent in a [`Request::SignRequest`](super::Request::SignRequest) (`SSH_AGENTC_SIGN_REQUEST`) message.
12+
///
13+
/// Described in [draft-miller-ssh-agent-14 § 3.6](https://www.ietf.org/archive/id/draft-miller-ssh-agent-14.html#section-3.6)
14+
#[derive(Clone, PartialEq, Debug)]
15+
pub struct SignRequest {
16+
/// The public key portion of the [`Identity`](super::Identity) in the agent to sign the data with
17+
pub pubkey: KeyData,
18+
19+
/// Binary data to be signed
20+
pub data: Vec<u8>,
21+
22+
/// Signature flags, as described in
23+
/// [draft-miller-ssh-agent-14 § 3.6.1](https://www.ietf.org/archive/id/draft-miller-ssh-agent-14.html#section-3.6.1)
24+
pub flags: u32,
25+
}
26+
27+
impl Decode for SignRequest {
28+
type Error = ProtoError;
29+
30+
fn decode(reader: &mut impl Reader) -> Result<Self> {
31+
let pubkey = reader.read_prefixed(KeyData::decode)?;
32+
let data = Vec::decode(reader)?;
33+
let flags = u32::decode(reader)?;
34+
35+
Ok(Self {
36+
pubkey,
37+
data,
38+
flags,
39+
})
40+
}
41+
}
42+
43+
impl Encode for SignRequest {
44+
fn encoded_len(&self) -> ssh_encoding::Result<usize> {
45+
[
46+
self.pubkey.encoded_len_prefixed()?,
47+
self.data.encoded_len()?,
48+
self.flags.encoded_len()?,
49+
]
50+
.checked_sum()
51+
}
52+
53+
fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
54+
self.pubkey.encode_prefixed(writer)?;
55+
self.data.encode(writer)?;
56+
self.flags.encode(writer)?;
57+
58+
Ok(())
59+
}
60+
}

0 commit comments

Comments
 (0)