@@ -5,6 +5,8 @@ mod credential;
5
5
6
6
pub use constrained:: * ;
7
7
pub use credential:: * ;
8
+ use secrecy:: ExposeSecret as _;
9
+ use secrecy:: SecretString ;
8
10
use ssh_encoding:: { self , CheckedSum , Decode , Encode , Reader , Writer } ;
9
11
use ssh_key:: public:: KeyData ;
10
12
@@ -46,7 +48,7 @@ impl Encode for AddIdentity {
46
48
/// This structure is sent in a [`Request::AddSmartcardKey`](super::Request::AddSmartcardKey) (`SSH_AGENTC_ADD_SMARTCARD_KEY`) message.
47
49
///
48
50
/// Described in [draft-miller-ssh-agent-14 § 3.2](https://www.ietf.org/archive/id/draft-miller-ssh-agent-14.html#section-3.2)
49
- #[ derive( Clone , PartialEq , Debug ) ]
51
+ #[ derive( Clone , Debug ) ]
50
52
pub struct SmartcardKey {
51
53
/// An opaque identifier for the hardware token
52
54
///
@@ -55,33 +57,43 @@ pub struct SmartcardKey {
55
57
pub id : String ,
56
58
57
59
/// An optional password to unlock the key
58
- pub pin : String ,
60
+ pub pin : SecretString ,
59
61
}
60
62
61
63
impl Decode for SmartcardKey {
62
64
type Error = Error ;
63
65
64
66
fn decode ( reader : & mut impl Reader ) -> Result < Self > {
65
67
let id = String :: decode ( reader) ?;
66
- let pin = String :: decode ( reader) ?;
68
+ let pin = String :: decode ( reader) ?. into ( ) ;
67
69
68
70
Ok ( Self { id, pin } )
69
71
}
70
72
}
71
73
72
74
impl Encode for SmartcardKey {
73
75
fn encoded_len ( & self ) -> ssh_encoding:: Result < usize > {
74
- [ self . id . encoded_len ( ) ?, self . pin . encoded_len ( ) ?] . checked_sum ( )
76
+ [
77
+ self . id . encoded_len ( ) ?,
78
+ self . pin . expose_secret ( ) . encoded_len ( ) ?,
79
+ ]
80
+ . checked_sum ( )
75
81
}
76
82
77
83
fn encode ( & self , writer : & mut impl Writer ) -> ssh_encoding:: Result < ( ) > {
78
84
self . id . encode ( writer) ?;
79
- self . pin . encode ( writer) ?;
85
+ self . pin . expose_secret ( ) . encode ( writer) ?;
80
86
81
87
Ok ( ( ) )
82
88
}
83
89
}
84
90
91
+ impl 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
+
85
97
/// Remove a key from an agent.
86
98
///
87
99
/// This structure is sent in a [`Request::RemoveIdentity`](super::Request::RemoveIdentity) (`SSH_AGENTC_REMOVE_IDENTITY`) message.
0 commit comments