ssh_agent_lib/proto/message/
add_remove.rs1mod constrained;
4mod credential;
5
6pub use constrained::*;
7pub use credential::*;
8use secrecy::ExposeSecret as _;
9use secrecy::SecretString;
10use ssh_encoding::{self, CheckedSum, Decode, Encode, Reader, Writer};
11use ssh_key::public::KeyData;
12
13use crate::proto::{Error, Result};
14
15#[derive(Clone, PartialEq, Debug)]
21pub struct AddIdentity {
22 pub credential: Credential,
24}
25
26impl Decode for AddIdentity {
27 type Error = Error;
28
29 fn decode(reader: &mut impl Reader) -> Result<Self> {
30 let credential = Credential::decode(reader)?;
31
32 Ok(Self { credential })
33 }
34}
35
36impl Encode for AddIdentity {
37 fn encoded_len(&self) -> ssh_encoding::Result<usize> {
38 self.credential.encoded_len()
39 }
40
41 fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
42 self.credential.encode(writer)
43 }
44}
45
46#[derive(Clone, Debug)]
52pub struct SmartcardKey {
53 pub id: String,
58
59 pub pin: SecretString,
61}
62
63impl Decode for SmartcardKey {
64 type Error = Error;
65
66 fn decode(reader: &mut impl Reader) -> Result<Self> {
67 let id = String::decode(reader)?;
68 let pin = String::decode(reader)?.into();
69
70 Ok(Self { id, pin })
71 }
72}
73
74impl Encode for SmartcardKey {
75 fn encoded_len(&self) -> ssh_encoding::Result<usize> {
76 [
77 self.id.encoded_len()?,
78 self.pin.expose_secret().encoded_len()?,
79 ]
80 .checked_sum()
81 }
82
83 fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
84 self.id.encode(writer)?;
85 self.pin.expose_secret().encode(writer)?;
86
87 Ok(())
88 }
89}
90
91impl PartialEq for SmartcardKey {
92 fn eq(&self, other: &Self) -> bool {
93 self.id == other.id && self.pin.expose_secret() == other.pin.expose_secret()
94 }
95}
96
97#[derive(Clone, PartialEq, Debug)]
103pub struct RemoveIdentity {
104 pub pubkey: KeyData,
106}
107
108impl Decode for RemoveIdentity {
109 type Error = Error;
110
111 fn decode(reader: &mut impl Reader) -> Result<Self> {
112 let pubkey = reader.read_prefixed(KeyData::decode)?;
113
114 Ok(Self { pubkey })
115 }
116}
117
118impl Encode for RemoveIdentity {
119 fn encoded_len(&self) -> ssh_encoding::Result<usize> {
120 self.pubkey.encoded_len_prefixed()
121 }
122
123 fn encode(&self, writer: &mut impl Writer) -> ssh_encoding::Result<()> {
124 self.pubkey.encode_prefixed(writer)
125 }
126}