summary history branches tags files
commit:6c2070dd6efd97cbd46f6352d720ca9d97e75f60
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Jan 28 00:06:05 2019 +0100
parents:9766787193cef7d74d5cc928448a2566ad29d0bd
Drop crypto_ prefix
diff --git a/benches/basic.rs b/benches/basic.rs
line changes: +12/-12
index 7e9191b..5f405a9
--- a/benches/basic.rs
+++ b/benches/basic.rs
@@ -14,10 +14,10 @@ fn bench_test(b: &mut Bencher) {
         let listener = TcpListener::bind("127.0.0.1:9987").unwrap();
         let mut server_stream = listener.incoming().next().unwrap().unwrap();
         let mut server_conn = ConnectionContext::new(ConnectionType::UnauthenticatedServer);
-        while server_conn.crypto_handshake_done().unwrap() == false {
-            if server_conn.crypto_send_handshake(&mut server_stream).is_ok() {
+        while server_conn.handshake_done().unwrap() == false {
+            if server_conn.send_handshake(&mut server_stream).is_ok() {
                 loop {
-                    match server_conn.crypto_recv_handshake(&mut server_stream) {
+                    match server_conn.recv_handshake(&mut server_stream) {
                         Ok(_) => break,
                         Err(OssuaryError::WouldBlock(_)) => {},
                         _ => panic!("Handshake failed"),
@@ -31,8 +31,8 @@ fn bench_test(b: &mut Bencher) {
         let start = std::time::SystemTime::now();
         loop {
             //std::thread::sleep(std::time::Duration::from_millis(100));
-            match server_conn.crypto_recv_data(&mut server_stream,
-                                               &mut plaintext) {
+            match server_conn.recv_data(&mut server_stream,
+                                        &mut plaintext) {
                 Ok((read, _written)) => bytes += read as u64,
                 Err(OssuaryError::WouldBlock(_)) => continue,
                 Err(e) => {
@@ -58,10 +58,10 @@ fn bench_test(b: &mut Bencher) {
     let mut client_stream = TcpStream::connect("127.0.0.1:9987").unwrap();
     client_stream.set_nonblocking(true).unwrap();
     let mut client_conn = ConnectionContext::new(ConnectionType::Client);
-    while client_conn.crypto_handshake_done().unwrap() == false {
-        if client_conn.crypto_send_handshake(&mut client_stream).is_ok() {
+    while client_conn.handshake_done().unwrap() == false {
+        if client_conn.send_handshake(&mut client_stream).is_ok() {
             loop {
-                match client_conn.crypto_recv_handshake(&mut client_stream) {
+                match client_conn.recv_handshake(&mut client_stream) {
                     Ok(_) => break,
                     Err(OssuaryError::WouldBlock(_)) => {},
                     Err(e) => {
@@ -78,8 +78,8 @@ fn bench_test(b: &mut Bencher) {
     let start = std::time::SystemTime::now();
     let mut plaintext: &[u8] = &[0xaa; 16384];
     b.iter(|| {
-        match client_conn.crypto_send_data(&mut plaintext,
-                                           &mut client_stream) {
+        match client_conn.send_data(&mut plaintext,
+                                    &mut client_stream) {
             Ok(b) => bytes += b as u64,
             Err(OssuaryError::WouldBlock(_)) => {},
             _ => panic!("send error"),
@@ -93,7 +93,7 @@ fn bench_test(b: &mut Bencher) {
     }
     let mut plaintext: &[u8] = &[0xde, 0xde, 0xbe, 0xbe];
     loop {
-        match client_conn.crypto_send_data(&mut plaintext, &mut client_stream) {
+        match client_conn.send_data(&mut plaintext, &mut client_stream) {
             Ok(w) => {
                 println!("wrote finish: {}", w);
                 break;
@@ -103,7 +103,7 @@ fn bench_test(b: &mut Bencher) {
         }
     }
 
-    while let Ok(w) = client_conn.crypto_flush(&mut client_stream) {
+    while let Ok(w) = client_conn.flush(&mut client_stream) {
         if w == 0 {
             break;
         }

diff --git a/src/clib.rs b/src/clib.rs
line changes: +6/-6
index e4dee8c..2031051
--- a/src/clib.rs
+++ b/src/clib.rs
@@ -76,7 +76,7 @@ pub extern "C" fn ossuary_recv_handshake(conn: *mut ConnectionContext,
     let inlen = unsafe { *in_buf_len as usize };
     let r_in_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, inlen) };
     let mut slice = r_in_buf;
-    let read: i32 = match conn.crypto_recv_handshake(&mut slice) {
+    let read: i32 = match conn.recv_handshake(&mut slice) {
         Ok(read) => {
             unsafe { *in_buf_len = read as u16; }
             read as i32
@@ -101,7 +101,7 @@ pub extern "C" fn ossuary_send_handshake(conn: *mut ConnectionContext,
     let outlen = unsafe { *out_buf_len as usize };
     let r_out_buf: &mut [u8] = unsafe { std::slice::from_raw_parts_mut(out_buf, outlen) };
     let mut slice = r_out_buf;
-    let wrote: i32 = match conn.crypto_send_handshake(&mut slice) {
+    let wrote: i32 = match conn.send_handshake(&mut slice) {
         Ok(w) => {
             unsafe { *out_buf_len = w as u16 };
             w as i32
@@ -122,7 +122,7 @@ pub extern "C" fn ossuary_handshake_done(conn: *const ConnectionContext) -> i32 
         return -1i32;
     }
     let conn = unsafe { &*conn };
-    let done = conn.crypto_handshake_done();
+    let done = conn.handshake_done();
     ::std::mem::forget(conn);
     match done {
         Ok(done) => done as i32,
@@ -145,7 +145,7 @@ pub extern "C" fn ossuary_send_data(conn: *mut ConnectionContext,
     let r_in_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, in_buf_len as usize) };
     let mut out_slice = r_out_buf;
     let in_slice = r_in_buf;
-    let bytes_written = match conn.crypto_send_data(&in_slice, &mut out_slice) {
+    let bytes_written = match conn.send_data(&in_slice, &mut out_slice) {
         Ok(w) => {
             unsafe { *out_buf_len = w as u16; }
             w as i32
@@ -175,7 +175,7 @@ pub extern "C" fn ossuary_recv_data(conn: *mut ConnectionContext,
     let r_in_buf: &[u8] = unsafe { std::slice::from_raw_parts(in_buf, *in_buf_len as usize) };
     let mut out_slice = r_out_buf;
     let mut in_slice = r_in_buf;
-    let bytes_read = match conn.crypto_recv_data(&mut in_slice, &mut out_slice) {
+    let bytes_read = match conn.recv_data(&mut in_slice, &mut out_slice) {
         Ok((read,written)) => {
             unsafe {
                 *in_buf_len = read as u16;
@@ -206,7 +206,7 @@ pub extern "C" fn ossuary_flush(conn: *mut ConnectionContext,
         std::slice::from_raw_parts_mut(out_buf, out_buf_len as usize)
     };
     let mut out_slice = r_out_buf;
-    let bytes_written = match conn.crypto_flush(&mut out_slice) {
+    let bytes_written = match conn.flush(&mut out_slice) {
         Ok(x) => x as i32,
         Err(OssuaryError::WouldBlock(_)) => ERROR_WOULD_BLOCK,
         Err(_) => -1i32,

diff --git a/src/lib.rs b/src/lib.rs
line changes: +12/-14
index ff07c15..c46f00a
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,9 +6,7 @@
 //!
 //
 // TODO:
-//  - move all the crypto_* functions into ConnectionContext
-//    - rename to OssuaryConnection
-//    - drop the crypto_ prefixes
+//  - rename to OssuaryConnection
 //  - server certificate
 //  - consider all unexpected packet types to be errors
 //  - ensure that a reset on one end always sends a reset to the other
@@ -572,7 +570,7 @@ impl ConnectionContext {
     ///
     ///
     /// On success, returns the number of bytes written to the output buffer.
-    pub fn crypto_send_handshake<T,U>(&mut self, mut buf: T) -> Result<usize, OssuaryError>
+    pub fn send_handshake<T,U>(&mut self, mut buf: T) -> Result<usize, OssuaryError>
     where T: std::ops::DerefMut<Target = U>,
           U: std::io::Write {
         // Try to send any unsent buffered data
@@ -769,7 +767,7 @@ impl ConnectionContext {
     /// Receive the next handshake packet from the input buffer
     ///
     /// On success, returns the number of bytes consumed from the input buffer.
-    pub fn crypto_recv_handshake<T,U>(&mut self, buf: T) -> Result<usize, OssuaryError>
+    pub fn recv_handshake<T,U>(&mut self, buf: T) -> Result<usize, OssuaryError>
     where T: std::ops::DerefMut<Target = U>,
           U: std::io::Read {
         let mut bytes_read: usize = 0;
@@ -1000,7 +998,7 @@ impl ConnectionContext {
     /// Returns whether the handshake process is complete.
     ///
     ///
-    pub fn crypto_handshake_done(&self) -> Result<bool, &OssuaryError> {
+    pub fn handshake_done(&self) -> Result<bool, &OssuaryError> {
         match self.state {
             ConnectionState::Encrypted => Ok(true),
             ConnectionState::Failed(ref e) => Err(e),
@@ -1008,9 +1006,9 @@ impl ConnectionContext {
         }
     }
 
-    pub fn crypto_send_data<T,U>(&mut self,
-                                 in_buf: &[u8],
-                                 mut out_buf: T) -> Result<usize, OssuaryError>
+    pub fn send_data<T,U>(&mut self,
+                          in_buf: &[u8],
+                          mut out_buf: T) -> Result<usize, OssuaryError>
     where T: std::ops::DerefMut<Target = U>,
           U: std::io::Write {
         // Try to send any unsent buffered data
@@ -1057,9 +1055,9 @@ impl ConnectionContext {
         Ok(written)
     }
 
-    pub fn crypto_recv_data<T,U,R,V>(&mut self,
-                                     in_buf: T,
-                                     mut out_buf: R) -> Result<(usize, usize), OssuaryError>
+    pub fn recv_data<T,U,R,V>(&mut self,
+                              in_buf: T,
+                              mut out_buf: R) -> Result<(usize, usize), OssuaryError>
     where T: std::ops::DerefMut<Target = U>,
           U: std::io::Read,
           R: std::ops::DerefMut<Target = V>,
@@ -1140,8 +1138,8 @@ impl ConnectionContext {
         Ok((bytes_read, bytes_written))
     }
 
-    pub fn crypto_flush<R,V>(&mut self,
-                             mut out_buf: R) -> Result<usize, OssuaryError>
+    pub fn flush<R,V>(&mut self,
+                      mut out_buf: R) -> Result<usize, OssuaryError>
     where R: std::ops::DerefMut<Target = V>,
           V: std::io::Write {
         return write_stored_packet(self, &mut out_buf);

diff --git a/tests/basic.rs b/tests/basic.rs
line changes: +5/-5
index b422754..d9c34a3
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -9,10 +9,10 @@ fn event_loop<T>(mut conn: ConnectionContext,
                  is_server: bool) -> Result<(), std::io::Error>
 where T: std::io::Read + std::io::Write {
     // Run the opaque handshake until the connection is established
-    while conn.crypto_handshake_done().unwrap() == false {
-        if conn.crypto_send_handshake(&mut stream).is_ok() {
+    while conn.handshake_done().unwrap() == false {
+        if conn.send_handshake(&mut stream).is_ok() {
             loop {
-                match conn.crypto_recv_handshake(&mut stream) {
+                match conn.recv_handshake(&mut stream) {
                     Ok(_) => break,
                     Err(OssuaryError::WouldBlock(_)) => {},
                     _ => panic!("Handshake failed."),
@@ -27,12 +27,12 @@ where T: std::io::Read + std::io::Write {
         true => (strings.0.as_bytes(), strings.1.as_bytes()),
         false => (strings.1.as_bytes(), strings.0.as_bytes()),
     };
-    let _ = conn.crypto_send_data(&mut plaintext, &mut stream);
+    let _ = conn.send_data(&mut plaintext, &mut stream);
 
     // Read a message from the other party
     let mut recv_plaintext = vec!();
     loop {
-        match conn.crypto_recv_data(&mut stream, &mut recv_plaintext) {
+        match conn.recv_data(&mut stream, &mut recv_plaintext) {
             Ok(_) => {
                 println!("(basic) received: {:?}",
                          String::from_utf8(recv_plaintext.clone()).unwrap());

diff --git a/tests/basic_auth.rs b/tests/basic_auth.rs
line changes: +5/-5
index e1aab10..336cadc
--- a/tests/basic_auth.rs
+++ b/tests/basic_auth.rs
@@ -9,10 +9,10 @@ fn event_loop<T>(mut conn: ConnectionContext,
                  is_server: bool) -> Result<(), std::io::Error>
 where T: std::io::Read + std::io::Write {
     // Run the opaque handshake until the connection is established
-    while conn.crypto_handshake_done().unwrap() == false {
-        if conn.crypto_send_handshake(&mut stream).is_ok() {
+    while conn.handshake_done().unwrap() == false {
+        if conn.send_handshake(&mut stream).is_ok() {
             loop {
-                match conn.crypto_recv_handshake(&mut stream) {
+                match conn.recv_handshake(&mut stream) {
                     Ok(_) => break,
                     Err(OssuaryError::WouldBlock(_)) => {},
                     _ => panic!("Handshake failed."),
@@ -27,12 +27,12 @@ where T: std::io::Read + std::io::Write {
         true => (strings.0.as_bytes(), strings.1.as_bytes()),
         false => (strings.1.as_bytes(), strings.0.as_bytes()),
     };
-    let _ = conn.crypto_send_data(&mut plaintext, &mut stream);
+    let _ = conn.send_data(&mut plaintext, &mut stream);
 
     // Read a message from the other party
     let mut recv_plaintext = vec!();
     loop {
-        match conn.crypto_recv_data(&mut stream, &mut recv_plaintext) {
+        match conn.recv_data(&mut stream, &mut recv_plaintext) {
             Ok(_) => {
                 println!("(basic_auth) received: {:?}",
                          String::from_utf8(recv_plaintext.clone()).unwrap());