@@ -8,10 +8,10 @@ use ssh_key::{Algorithm, Certificate, HashAlg, PrivateKey, PublicKey, Signature}
88use tokio;
99use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite , AsyncWriteExt } ;
1010
11- use super :: { msg, AgentIdentity , Constraint } ;
12- use crate :: helpers:: EncodedExt ;
13- use crate :: keys:: { key, Error } ;
11+ use super :: { AgentIdentity , Constraint , msg} ;
1412use crate :: CryptoVec ;
13+ use crate :: helpers:: EncodedExt ;
14+ use crate :: keys:: { Error , key} ;
1515
1616pub trait AgentStream : AsyncRead + AsyncWrite { }
1717
@@ -254,43 +254,8 @@ impl<S: AgentStream + Unpin> AgentClient<S> {
254254 Ok ( ( ) )
255255 }
256256
257- /// Ask the agent for a list of the currently registered public keys.
258- ///
259- /// Note: Certificates held by the agent will be returned as their underlying public
260- /// key only, without the certificate data. Use
261- /// [`request_identities_full`](Self::request_identities_full) to retrieve full
262- /// certificate information.
263- pub async fn request_identities ( & mut self ) -> Result < Vec < PublicKey > , Error > {
264- self . buf . clear ( ) ;
265- self . buf . resize ( 4 ) ;
266- msg:: REQUEST_IDENTITIES . encode ( & mut self . buf ) ?;
267- let len = self . buf . len ( ) - 4 ;
268- BigEndian :: write_u32 ( & mut self . buf [ ..] , len as u32 ) ;
269-
270- self . read_response ( ) . await ?;
271- debug ! ( "identities: {:?}" , & self . buf[ ..] ) ;
272- let mut keys = Vec :: new ( ) ;
273-
274- #[ allow( clippy:: indexing_slicing) ] // static length
275- if let Some ( ( & msg:: IDENTITIES_ANSWER , mut r) ) = self . buf . split_first ( ) {
276- let n = u32:: decode ( & mut r) ?;
277- for _ in 0 ..n {
278- let key_blob = Bytes :: decode ( & mut r) ?;
279- let comment = String :: decode ( & mut r) ?;
280- let mut key = key:: parse_public_key ( & key_blob) ?;
281- key. set_comment ( comment) ;
282- keys. push ( key) ;
283- }
284- }
285-
286- Ok ( keys)
287- }
288-
289257 /// Ask the agent for a list of identities, including certificates.
290- ///
291- /// Unlike [`request_identities`](Self::request_identities) which only returns public keys,
292- /// this method correctly parses OpenSSH certificates held by the agent.
293- pub async fn request_identities_full ( & mut self ) -> Result < Vec < AgentIdentity > , Error > {
258+ pub async fn request_identities ( & mut self ) -> Result < Vec < AgentIdentity > , Error > {
294259 self . buf . clear ( ) ;
295260 self . buf . resize ( 4 ) ;
296261 msg:: REQUEST_IDENTITIES . encode ( & mut self . buf ) ?;
@@ -313,7 +278,7 @@ impl<S: AgentStream + Unpin> AgentClient<S> {
313278 // This avoids parsing the blob twice for regular keys.
314279 let identity = if Self :: is_certificate_blob ( & key_blob) {
315280 match Certificate :: decode ( & mut key_blob. as_ref ( ) ) {
316- Ok ( cert) => AgentIdentity :: Certificate { cert, comment } ,
281+ Ok ( cert) => AgentIdentity :: Certificate { certificate : cert, comment } ,
317282 Err ( _) => {
318283 // Fallback to public key if certificate parsing fails
319284 let key = key:: parse_public_key ( & key_blob) ?;
@@ -352,6 +317,20 @@ impl<S: AgentStream + Unpin> AgentClient<S> {
352317
353318 /// Ask the agent to sign the supplied piece of data.
354319 pub async fn sign_request (
320+ & mut self ,
321+ identity : & AgentIdentity ,
322+ hash_alg : Option < HashAlg > ,
323+ data : CryptoVec ,
324+ ) -> Result < CryptoVec , Error > {
325+ match identity {
326+ AgentIdentity :: PublicKey { key, .. } => self . sign_request_pk ( key, hash_alg, data) . await ,
327+ AgentIdentity :: Certificate { certificate, .. } => {
328+ self . sign_request_cert ( certificate, hash_alg, data) . await
329+ }
330+ }
331+ }
332+
333+ async fn sign_request_pk (
355334 & mut self ,
356335 public : & PublicKey ,
357336 hash_alg : Option < HashAlg > ,
@@ -381,7 +360,7 @@ impl<S: AgentStream + Unpin> AgentClient<S> {
381360 /// allowing the agent to match it to the correct private key.
382361 ///
383362 /// For RSA certificates, you can specify the hash algorithm to use.
384- pub async fn sign_request_cert (
363+ async fn sign_request_cert (
385364 & mut self ,
386365 cert : & Certificate ,
387366 hash_alg : Option < HashAlg > ,
0 commit comments