From 8589a3672fee145ca228ef3e8710807c80897b21 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Sun, 6 Nov 2022 23:38:19 +0800
Subject: [PATCH] Get rid of some .as_bytes()

---
 src/encrypt.rs |  8 ++++----
 src/ident.rs   | 10 +++++-----
 src/kex.rs     |  4 ++--
 3 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/encrypt.rs b/src/encrypt.rs
index 65a4a4c..d108cf3 100644
--- a/src/encrypt.rs
+++ b/src/encrypt.rs
@@ -800,7 +800,7 @@ mod tests {
                 // arbitrary keys
                 let h = SessId::from_slice(&Sha256::digest("some exchange hash".as_bytes())).unwrap();
                 let sess_id = SessId::from_slice(&Sha256::digest("some sessid".as_bytes())).unwrap();
-                let sharedkey = "hello".as_bytes();
+                let sharedkey = b"hello";
 
                 trace!("algos enc {algos:?}");
                 let newkeys = Keys::new_from(sharedkey, &h, &sess_id, &algos).unwrap();
@@ -835,9 +835,9 @@ mod tests {
             let mut keys = KeyState::new_cleartext();
             if let Some(algos) = algos {
                 // arbitrary keys
-                let h = SessId::from_slice(&Sha256::digest("some exchange hash".as_bytes())).unwrap();
-                let sess_id = SessId::from_slice(&Sha256::digest("some sessid".as_bytes())).unwrap();
-                let sharedkey = "hello".as_bytes();
+                let h = SessId::from_slice(&Sha256::digest(b"some exchange hash")).unwrap();
+                let sess_id = SessId::from_slice(&Sha256::digest(b"some sessid")).unwrap();
+                let sharedkey = b"hello";
                 let newkeys =
                     Keys::new_from(sharedkey, &h, &sess_id, &algos).unwrap();
 
diff --git a/src/ident.rs b/src/ident.rs
index c7852a8..1ee11e3 100644
--- a/src/ident.rs
+++ b/src/ident.rs
@@ -1,4 +1,4 @@
-use crate::error::{Error,TrapBug};
+use crate::error::{Error,TrapBug, Result};
 
 pub(crate) const OUR_VERSION: &[u8] = b"SSH-2.0-SunsetSSH-0.1";
 
@@ -81,7 +81,7 @@ impl<'a> RemoteVersion {
     /// Reads the initial SSH stream to find the version string and returns
     /// the number of bytes consumed.
     /// Behaviour is undefined if called later after an error.
-    pub fn consume(&mut self, buf: &[u8]) -> Result<usize, Error> {
+    pub fn consume(&mut self, buf: &[u8]) -> Result<usize> {
         // consume input byte by byte, feeding through the states
         let mut taken = 0;
         for &b in buf {
@@ -157,11 +157,11 @@ impl<'a> RemoteVersion {
 #[rustfmt::skip]
 mod tests {
     use crate::ident;
-    use crate::error::{Error,TrapBug};
+    use crate::error::{Error,TrapBug,Result};
     use crate::sunsetlog::init_test_log;
     use proptest::prelude::*;
 
-    fn test_version(v: &str, split: usize, expect: &str) -> Result<usize, Error> {
+    fn test_version(v: &str, split: usize, expect: &str) -> Result<usize> {
         let mut r = ident::RemoteVersion::new();
 
         let split = split.min(v.len());
@@ -187,7 +187,7 @@ mod tests {
 
     #[test]
     /// check round trip of packet enums is right
-    fn version() -> Result<(), Error> {
+    fn version() -> Result<()> {
         let long = core::str::from_utf8(&[60u8; 300]).unwrap();
         // split input at various positions
         let splits = [
diff --git a/src/kex.rs b/src/kex.rs
index 4dd6599..265719b 100644
--- a/src/kex.rs
+++ b/src/kex.rs
@@ -672,9 +672,9 @@ mod tests {
         let serv_conf = kex::AlgoConfig::new(false);
         let mut serv_version = RemoteVersion::new();
         // needs to be hardcoded because that's what we send.
-        serv_version.consume("SSH-2.0-sunset\r\n".as_bytes()).unwrap();
+        serv_version.consume(b"SSH-2.0-sunset\r\n").unwrap();
         let mut cli_version = RemoteVersion::new();
-        cli_version.consume("SSH-2.0-sunset\r\n".as_bytes()).unwrap();
+        cli_version.consume(b"SSH-2.0-sunset\r\n").unwrap();
 
         let mut sb = TestServBehaviour {
             // TODO: put keys in
-- 
GitLab