File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3434//!
3535//! [Session]: client::Session
3636
37+ use std:: borrow:: Cow ;
3738use std:: collections:: { HashMap , VecDeque } ;
3839use std:: convert:: TryInto ;
3940use std:: num:: Wrapping ;
@@ -1701,11 +1702,12 @@ pub struct Config {
17011702impl Default for Config {
17021703 fn default ( ) -> Config {
17031704 Config {
1704- client_id : SshId :: Standard ( format ! (
1705- "SSH-2.0-{}_{} " ,
1705+ client_id : SshId :: Standard ( Cow :: Borrowed ( concat ! (
1706+ "SSH-2.0-" ,
17061707 env!( "CARGO_PKG_NAME" ) ,
1708+ "_" ,
17071709 env!( "CARGO_PKG_VERSION" )
1708- ) ) ,
1710+ ) ) ) ,
17091711 limits : Limits :: default ( ) ,
17101712 window_size : 2097152 ,
17111713 maximum_packet_size : 32768 ,
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ mod tests {
8787 // Configure the server
8888 let mut config = server:: Config :: default ( ) ;
8989 config. auth_rejection_time = std:: time:: Duration :: from_secs ( 1 ) ;
90- config. server_id = SshId :: Standard ( "SSH-1.99-CustomServer_1.0" . to_string ( ) ) ;
90+ config. server_id = SshId :: Standard ( "SSH-1.99-CustomServer_1.0" . into ( ) ) ;
9191 config. inactivity_timeout = None ;
9292 config
9393 . keys
Original file line number Diff line number Diff line change @@ -102,11 +102,12 @@ pub struct Config {
102102impl Default for Config {
103103 fn default ( ) -> Config {
104104 Config {
105- server_id : SshId :: Standard ( format ! (
106- "SSH-2.0-{}_{} " ,
105+ server_id : SshId :: Standard ( Cow :: Borrowed ( concat ! (
106+ "SSH-2.0-" ,
107107 env!( "CARGO_PKG_NAME" ) ,
108+ "_" ,
108109 env!( "CARGO_PKG_VERSION" )
109- ) ) ,
110+ ) ) ) ,
110111 methods : auth:: MethodSet :: all ( ) ,
111112 auth_rejection_time : std:: time:: Duration :: from_secs ( 1 ) ,
112113 auth_rejection_time_initial : None ,
Original file line number Diff line number Diff line change 1414//
1515
1616use core:: fmt;
17+ use std:: borrow:: Cow ;
1718use std:: num:: Wrapping ;
1819
1920use cipher:: SealingKey ;
@@ -26,9 +27,9 @@ use super::*;
2627#[ derive( Debug ) ]
2728pub enum SshId {
2829 /// When sending the id, append RFC standard `\r\n`. Example: `SshId::Standard("SSH-2.0-acme")`
29- Standard ( String ) ,
30+ Standard ( Cow < ' static , str > ) ,
3031 /// When sending the id, use this buffer as it is and do not append additional line terminators.
31- Raw ( String ) ,
32+ Raw ( Cow < ' static , str > ) ,
3233}
3334
3435impl SshId {
@@ -52,19 +53,19 @@ impl SshId {
5253#[ test]
5354fn test_ssh_id ( ) {
5455 let mut buffer = Vec :: new ( ) ;
55- SshId :: Standard ( "SSH-2.0-acme" . to_string ( ) ) . write ( & mut buffer) ;
56+ SshId :: Standard ( "SSH-2.0-acme" . into ( ) ) . write ( & mut buffer) ;
5657 assert_eq ! ( & buffer[ ..] , b"SSH-2.0-acme\r \n " ) ;
5758
5859 let mut buffer = Vec :: new ( ) ;
59- SshId :: Raw ( "SSH-2.0-raw\n " . to_string ( ) ) . write ( & mut buffer) ;
60+ SshId :: Raw ( "SSH-2.0-raw\n " . into ( ) ) . write ( & mut buffer) ;
6061 assert_eq ! ( & buffer[ ..] , b"SSH-2.0-raw\n " ) ;
6162
6263 assert_eq ! (
63- SshId :: Standard ( "SSH-2.0-acme" . to_string ( ) ) . as_kex_hash_bytes( ) ,
64+ SshId :: Standard ( "SSH-2.0-acme" . into ( ) ) . as_kex_hash_bytes( ) ,
6465 b"SSH-2.0-acme"
6566 ) ;
6667 assert_eq ! (
67- SshId :: Raw ( "SSH-2.0-raw\n " . to_string ( ) ) . as_kex_hash_bytes( ) ,
68+ SshId :: Raw ( "SSH-2.0-raw\n " . into ( ) ) . as_kex_hash_bytes( ) ,
6869 b"SSH-2.0-raw"
6970 ) ;
7071}
You can’t perform that action at this time.
0 commit comments