@@ -87,6 +87,15 @@ impl<S: AsyncRead + AsyncWrite + Unpin> AgentClient<S> {
8787 Ok ( ( ) )
8888 }
8989
90+ async fn read_success ( & mut self ) -> Result < ( ) , Error > {
91+ self . read_response ( ) . await ?;
92+ if self . buf . first ( ) == Some ( & msg:: SUCCESS ) {
93+ Ok ( ( ) )
94+ } else {
95+ Err ( Error :: AgentFailure )
96+ }
97+ }
98+
9099 /// Send a key to the agent, with a (possibly empty) slice of
91100 /// constraints to apply when using the key to sign.
92101 pub async fn add_identity (
@@ -131,12 +140,11 @@ impl<S: AsyncRead + AsyncWrite + Unpin> AgentClient<S> {
131140 }
132141 }
133142 if !constraints. is_empty ( ) {
134- self . buf . push_u32_be ( constraints. len ( ) as u32 ) ;
135143 for cons in constraints {
136144 match * cons {
137145 Constraint :: KeyLifetime { seconds } => {
138146 self . buf . push ( msg:: CONSTRAIN_LIFETIME ) ;
139- self . buf . push_u32_be ( seconds)
147+ self . buf . push_u32_be ( seconds) ;
140148 }
141149 Constraint :: Confirm => self . buf . push ( msg:: CONSTRAIN_CONFIRM ) ,
142150 Constraint :: Extensions {
@@ -153,7 +161,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> AgentClient<S> {
153161 let len = self . buf . len ( ) - 4 ;
154162 BigEndian :: write_u32 ( & mut self . buf [ ..] , len as u32 ) ;
155163
156- self . read_response ( ) . await ?;
164+ self . read_success ( ) . await ?;
157165 Ok ( ( ) )
158166 }
159167
@@ -467,8 +475,8 @@ impl<S: AsyncRead + AsyncWrite + Unpin> AgentClient<S> {
467475 self . buf . clear ( ) ;
468476 self . buf . resize ( 4 ) ;
469477 self . buf . push ( msg:: REMOVE_ALL_IDENTITIES ) ;
470- BigEndian :: write_u32 ( & mut self . buf [ ..] , 5 ) ;
471- self . read_response ( ) . await ?;
478+ BigEndian :: write_u32 ( & mut self . buf [ ..] , 1 ) ;
479+ self . read_success ( ) . await ?;
472480 Ok ( ( ) )
473481 }
474482
0 commit comments