ssh_agent_lib/proto/message/
sign.rs

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