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 {
@@ -41,7 +42,10 @@ impl SshId {
4142
4243 pub ( crate ) fn write ( & self , buffer : & mut CryptoVec ) {
4344 match self {
44- Self :: Standard ( s) => buffer. extend ( format ! ( "{s}\r \n " ) . as_bytes ( ) ) ,
45+ Self :: Standard ( s) => {
46+ buffer. extend ( s. as_bytes ( ) ) ;
47+ buffer. extend ( b"\r \n " ) ;
48+ } ,
4549 Self :: Raw ( s) => buffer. extend ( s. as_bytes ( ) ) ,
4650 }
4751 }
@@ -50,19 +54,19 @@ impl SshId {
5054#[ test]
5155fn test_ssh_id ( ) {
5256 let mut buffer = CryptoVec :: new ( ) ;
53- SshId :: Standard ( "SSH-2.0-acme" . to_string ( ) ) . write ( & mut buffer) ;
57+ SshId :: Standard ( "SSH-2.0-acme" . into ( ) ) . write ( & mut buffer) ;
5458 assert_eq ! ( & buffer[ ..] , b"SSH-2.0-acme\r \n " ) ;
5559
5660 let mut buffer = CryptoVec :: new ( ) ;
57- SshId :: Raw ( "SSH-2.0-raw\n " . to_string ( ) ) . write ( & mut buffer) ;
61+ SshId :: Raw ( "SSH-2.0-raw\n " . into ( ) ) . write ( & mut buffer) ;
5862 assert_eq ! ( & buffer[ ..] , b"SSH-2.0-raw\n " ) ;
5963
6064 assert_eq ! (
61- SshId :: Standard ( "SSH-2.0-acme" . to_string ( ) ) . as_kex_hash_bytes( ) ,
65+ SshId :: Standard ( "SSH-2.0-acme" . into ( ) ) . as_kex_hash_bytes( ) ,
6266 b"SSH-2.0-acme"
6367 ) ;
6468 assert_eq ! (
65- SshId :: Raw ( "SSH-2.0-raw\n " . to_string ( ) ) . as_kex_hash_bytes( ) ,
69+ SshId :: Raw ( "SSH-2.0-raw\n " . into ( ) ) . as_kex_hash_bytes( ) ,
6670 b"SSH-2.0-raw"
6771 ) ;
6872}
0 commit comments