summary history branches tags files
commit:d925cf879973298ec25c3853e468c473e8efcc12
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Jan 28 00:08:11 2019 +0100
parents:6c2070dd6efd97cbd46f6352d720ca9d97e75f60
Rename ConnectionContext -> OssuaryContext
diff --git a/benches/basic.rs b/benches/basic.rs
line changes: +3/-3
index 5f405a9..6a43a85
--- a/benches/basic.rs
+++ b/benches/basic.rs
@@ -4,7 +4,7 @@ use test::Bencher;
 use std::thread;
 use std::net::{TcpListener, TcpStream};
 
-use ossuary::{ConnectionContext, ConnectionType};
+use ossuary::{OssuaryContext, ConnectionType};
 use ossuary::OssuaryError;
 //use crate::*;
 
@@ -13,7 +13,7 @@ fn bench_test(b: &mut Bencher) {
     let server_thread = thread::spawn(move || {
         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);
+        let mut server_conn = OssuaryContext::new(ConnectionType::UnauthenticatedServer);
         while server_conn.handshake_done().unwrap() == false {
             if server_conn.send_handshake(&mut server_stream).is_ok() {
                 loop {
@@ -57,7 +57,7 @@ fn bench_test(b: &mut Bencher) {
     std::thread::sleep(std::time::Duration::from_millis(500));
     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);
+    let mut client_conn = OssuaryContext::new(ConnectionType::Client);
     while client_conn.handshake_done().unwrap() == false {
         if client_conn.send_handshake(&mut client_stream).is_ok() {
             loop {

diff --git a/src/clib.rs b/src/clib.rs
line changes: +13/-13
index 2031051..d660b32
--- a/src/clib.rs
+++ b/src/clib.rs
@@ -1,33 +1,33 @@
-use crate::{ConnectionContext, ConnectionType, OssuaryError};
+use crate::{OssuaryContext, ConnectionType, OssuaryError};
 
 const ERROR_WOULD_BLOCK: i32 = -64;
 
 #[no_mangle]
-pub extern "C" fn ossuary_create_connection(conn_type: u8) -> *mut ConnectionContext {
+pub extern "C" fn ossuary_create_connection(conn_type: u8) -> *mut OssuaryContext {
     let conn_type: ConnectionType = match conn_type {
         0 => ConnectionType::Client,
         1 => ConnectionType::AuthenticatedServer,
         2 => ConnectionType::UnauthenticatedServer,
         _ => { return ::std::ptr::null_mut(); }
     };
-    let mut conn = Box::new(ConnectionContext::new(conn_type));
+    let mut conn = Box::new(OssuaryContext::new(conn_type));
     let ptr: *mut _ = &mut *conn;
     ::std::mem::forget(conn);
     ptr
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_destroy_connection(conn: &mut *mut ConnectionContext) {
+pub extern "C" fn ossuary_destroy_connection(conn: &mut *mut OssuaryContext) {
     if conn.is_null() {
         return;
     }
-    let obj: Box<ConnectionContext> = unsafe { ::std::mem::transmute(*conn) };
+    let obj: Box<OssuaryContext> = unsafe { ::std::mem::transmute(*conn) };
     ::std::mem::drop(obj);
     *conn = ::std::ptr::null_mut();
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_set_authorized_keys(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_set_authorized_keys(conn: *mut OssuaryContext,
                                               keys: *const *const u8,
                                               key_count: u8) -> i32 {
     if conn.is_null() || keys.is_null() {
@@ -51,7 +51,7 @@ pub extern "C" fn ossuary_set_authorized_keys(conn: *mut ConnectionContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_set_secret_key(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_set_secret_key(conn: *mut OssuaryContext,
                                          key: *const u8) -> i32 {
     if conn.is_null() || key.is_null() {
         return -1 as i32;
@@ -67,7 +67,7 @@ pub extern "C" fn ossuary_set_secret_key(conn: *mut ConnectionContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_recv_handshake(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_recv_handshake(conn: *mut OssuaryContext,
                                          in_buf: *const u8, in_buf_len: *mut u16) -> i32 {
     if conn.is_null() || in_buf.is_null() || in_buf_len.is_null() {
         return -1i32;
@@ -92,7 +92,7 @@ pub extern "C" fn ossuary_recv_handshake(conn: *mut ConnectionContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_send_handshake(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_send_handshake(conn: *mut OssuaryContext,
                                          out_buf: *mut u8, out_buf_len: *mut u16) -> i32 {
     if conn.is_null() || out_buf.is_null() || out_buf_len.is_null() {
         return -1i32;
@@ -117,7 +117,7 @@ pub extern "C" fn ossuary_send_handshake(conn: *mut ConnectionContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_handshake_done(conn: *const ConnectionContext) -> i32 {
+pub extern "C" fn ossuary_handshake_done(conn: *const OssuaryContext) -> i32 {
     if conn.is_null() {
         return -1i32;
     }
@@ -131,7 +131,7 @@ pub extern "C" fn ossuary_handshake_done(conn: *const ConnectionContext) -> i32 
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_send_data(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_send_data(conn: *mut OssuaryContext,
                                     in_buf: *mut u8, in_buf_len: u16,
                                     out_buf: *mut u8, out_buf_len: *mut u16) -> i32 {
     if conn.is_null() || in_buf.is_null() ||
@@ -161,7 +161,7 @@ pub extern "C" fn ossuary_send_data(conn: *mut ConnectionContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_recv_data(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_recv_data(conn: *mut OssuaryContext,
                                     in_buf: *mut u8, in_buf_len: *mut u16,
                                     out_buf: *mut u8, out_buf_len: *mut u16) -> i32 {
     if conn.is_null() || in_buf.is_null() || out_buf.is_null() ||
@@ -196,7 +196,7 @@ pub extern "C" fn ossuary_recv_data(conn: *mut ConnectionContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_flush(conn: *mut ConnectionContext,
+pub extern "C" fn ossuary_flush(conn: *mut OssuaryContext,
                                 out_buf: *mut u8, out_buf_len: u16) -> i32 {
     if conn.is_null() || out_buf.is_null() {
         return -1i32;

diff --git a/src/lib.rs b/src/lib.rs
line changes: +27/-27
index c46f00a..23aa21b
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -101,8 +101,8 @@ pub enum OssuaryError {
     /// An invalid sized encryption key was encountered.
     ///
     /// This error is most likely caused by an attempt to register an invalid
-    /// secret or public key in [`ConnectionContext::set_authorized_keys`] or
-    /// [`ConnectionContext::set_secret_key`].  Both should be 32 bytes.
+    /// secret or public key in [`OssuaryContext::set_authorized_keys`] or
+    /// [`OssuaryContext::set_secret_key`].  Both should be 32 bytes.
     KeySize(usize, usize), // (expected, actual)
 
     /// An error occurred when parsing or using an encryption key.
@@ -290,7 +290,7 @@ impl NetworkPacket {
     }
 }
 
-/// Internal state of ConnectionContext state machine.
+/// Internal state of OssuaryContext state machine.
 enum ConnectionState {
     /// Idle server witing for a connection
     ServerNew,
@@ -338,7 +338,7 @@ impl Default for KeyMaterial {
     }
 }
 
-/// Enum specifying the client or server role of a [`ConnectionContext`]
+/// Enum specifying the client or server role of a [`OssuaryContext`]
 #[derive(Clone)]
 pub enum ConnectionType {
     /// This context is a client
@@ -347,9 +347,9 @@ pub enum ConnectionType {
     /// This context is a server that requires authentication.
     ///
     /// Authenticated servers only allow connections from clients with secret
-    /// keys set using [`ConnectionContext::set_secret_key`], and with the
+    /// keys set using [`OssuaryContext::set_secret_key`], and with the
     /// matching public key registered with the server using
-    /// [`ConnectionContext::set_authorized_keys`].
+    /// [`OssuaryContext::set_authorized_keys`].
     AuthenticatedServer,
 
     /// This context is a server that does not support authentication.
@@ -364,26 +364,26 @@ pub enum ConnectionType {
 /// Context for interacting with an encrypted communication channel
 ///
 /// All interaction with ossuary's encrypted channels is performed via a
-/// ConnectionContext instance.  It holds all of the state required to maintain
+/// OssuaryContext instance.  It holds all of the state required to maintain
 /// one side of an encrypted connection.
 ///
-/// A context is created with [`ConnectionContext::new`], passing it a
+/// A context is created with [`OssuaryContext::new`], passing it a
 /// [`ConnectionType`] identifying whether it is to act as a client or server.
 /// Server contexts can optionally require authentication, verified by providing
 /// a list of public keys of permitted clients with
-/// [`ConnectionContext::set_authorized_keys`].  Clients, on the other hand,
+/// [`OssuaryContext::set_authorized_keys`].  Clients, on the other hand,
 /// authenticate by setting their secret key with
-/// [`ConnectionContext::set_secret_key`].
+/// [`OssuaryContext::set_secret_key`].
 ///
-/// A server must create one ConnectionContext per connected client.  Multiple
+/// A server must create one OssuaryContext per connected client.  Multiple
 /// connections cannot be multiplexed in one context.
 ///
-/// A ConnectionContext keeps temporary buffers for both received and soon-to-be
+/// A OssuaryContext keeps temporary buffers for both received and soon-to-be
 /// transmitted data.  This means they are not particularly small objects, but
 /// in exchange they can read and write from/to streams set in non-blocking mode
 /// without blocking single-threaded applications.
 ///
-pub struct ConnectionContext {
+pub struct OssuaryContext {
     state: ConnectionState,
     conn_type: ConnectionType,
     local_key: KeyMaterial, // session key
@@ -400,9 +400,9 @@ pub struct ConnectionContext {
     write_buf: [u8; PACKET_BUF_SIZE],
     write_buf_used: usize,
 }
-impl Default for ConnectionContext {
+impl Default for OssuaryContext {
     fn default() -> Self {
-        ConnectionContext {
+        OssuaryContext {
             state: ConnectionState::ClientNew,
             conn_type: ConnectionType::Client,
             local_key: Default::default(),
@@ -421,12 +421,12 @@ impl Default for ConnectionContext {
         }
     }
 }
-impl ConnectionContext {
-    /// Allocate a new ConnectionContext.
+impl OssuaryContext {
+    /// Allocate a new OssuaryContext.
     ///
     /// `conn_type` is a [`ConnectionType`] indicating whether this instance
     /// is for a client or server.
-    pub fn new(conn_type: ConnectionType) -> ConnectionContext {
+    pub fn new(conn_type: ConnectionType) -> OssuaryContext {
         //let mut rng = thread_rng();
         let mut rng = OsRng::new().expect("RNG not available.");
         let sec_key = EphemeralSecret::new(&mut rng);
@@ -439,7 +439,7 @@ impl ConnectionContext {
             nonce: nonce,
             session: None,
         };
-        ConnectionContext {
+        OssuaryContext {
             state: match conn_type {
                 ConnectionType::Client => ConnectionState::ClientNew,
                 _ => ConnectionState::ServerNew,
@@ -464,7 +464,7 @@ impl ConnectionContext {
     /// connection, such as when the client's key is not authorized.
     ///
     fn reset_state(&mut self, permanent_err: Option<OssuaryError>) {
-        let default = ConnectionContext::new(self.conn_type.clone());
+        let default = OssuaryContext::new(self.conn_type.clone());
         *self = default;
         self.state = match permanent_err {
             None => {
@@ -552,7 +552,7 @@ impl ConnectionContext {
     }
     /// Get the client's authentication public verification key
     ///
-    /// When a secret key is set with [`ConnectionContext::set_secret_key`], the
+    /// When a secret key is set with [`OssuaryContext::set_secret_key`], the
     /// matching public key is calculated.  This function returns that public
     /// key, which can be shared with a remote server for future authentication.
     ///
@@ -1164,7 +1164,7 @@ fn interpret_packet_extra<'a, T>(pkt: &'a NetworkPacket)
 ///
 /// On success, returns a NetworkPacket struct containing the header and data,
 /// and a `usize` indicating how many bytes were consumed from the input buffer.
-fn read_packet<T,U>(conn: &mut ConnectionContext,
+fn read_packet<T,U>(conn: &mut OssuaryContext,
                     mut stream: T) ->Result<(NetworkPacket, usize), OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
       U: std::io::Read {
@@ -1210,13 +1210,13 @@ where T: std::ops::DerefMut<Target = U>,
     header_size + packet_len))
 }
 
-/// Write a packet from ConnectionContext's internal storage to the out buffer.
+/// Write a packet from OssuaryContext's internal storage to the out buffer.
 ///
 /// All packets are buffered to internal storage before writing, so this is
 /// the function responsible for putting all packets "on the wire".
 ///
 /// On success, returns the number of bytes written to the output buffer
-fn write_stored_packet<T,U>(conn: &mut ConnectionContext,
+fn write_stored_packet<T,U>(conn: &mut OssuaryContext,
                             stream: &mut T) -> Result<usize, OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
       U: std::io::Write {
@@ -1245,14 +1245,14 @@ where T: std::ops::DerefMut<Target = U>,
     Ok(written)
 }
 
-/// Write a packet to the ConnectionContext's internal packet buffer
+/// Write a packet to the OssuaryContext's internal packet buffer
 ///
 /// All packets are buffered internally because there is no guarantee that a
 /// complete packet can be written without blocking, and Ossuary is a non-
 /// blocking library.
 ///
 /// On success, returns the number of bytes written to the output buffer.
-fn write_packet<T,U>(conn: &mut ConnectionContext,
+fn write_packet<T,U>(conn: &mut OssuaryContext,
                      stream: &mut T, data: &[u8],
                      kind: PacketType) -> Result<usize, OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
@@ -1275,7 +1275,7 @@ mod tests {
 
     #[test]
     fn test_set_authorized_keys() {
-        let mut conn = ConnectionContext::new(ConnectionType::AuthenticatedServer);
+        let mut conn = OssuaryContext::new(ConnectionType::AuthenticatedServer);
 
         // Vec of slices
         let keys: Vec<&[u8]> = vec![

diff --git a/tests/basic.rs b/tests/basic.rs
line changes: +4/-4
index d9c34a3..4a1bec7
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -1,10 +1,10 @@
-use ossuary::{ConnectionContext, ConnectionType};
+use ossuary::{OssuaryContext, ConnectionType};
 use ossuary::OssuaryError;
 
 use std::thread;
 use std::net::{TcpListener, TcpStream};
 
-fn event_loop<T>(mut conn: ConnectionContext,
+fn event_loop<T>(mut conn: OssuaryContext,
                  mut stream: T,
                  is_server: bool) -> Result<(), std::io::Error>
 where T: std::io::Read + std::io::Write {
@@ -49,14 +49,14 @@ where T: std::io::Read + std::io::Write {
 fn server() -> Result<(), std::io::Error> {
     let listener = TcpListener::bind("127.0.0.1:9988").unwrap();
     let stream: TcpStream = listener.incoming().next().unwrap().unwrap();
-    let conn = ConnectionContext::new(ConnectionType::UnauthenticatedServer);
+    let conn = OssuaryContext::new(ConnectionType::UnauthenticatedServer);
     let _ = event_loop(conn, stream, true);
     Ok(())
 }
 
 fn client() -> Result<(), std::io::Error> {
     let stream = TcpStream::connect("127.0.0.1:9988").unwrap();
-    let conn = ConnectionContext::new(ConnectionType::Client);
+    let conn = OssuaryContext::new(ConnectionType::Client);
     let _ = event_loop(conn, stream, false);
     Ok(())
 }

diff --git a/tests/basic_auth.rs b/tests/basic_auth.rs
line changes: +4/-4
index 336cadc..dc3645b
--- a/tests/basic_auth.rs
+++ b/tests/basic_auth.rs
@@ -1,10 +1,10 @@
-use ossuary::{ConnectionContext, ConnectionType};
+use ossuary::{OssuaryContext, ConnectionType};
 use ossuary::OssuaryError;
 
 use std::thread;
 use std::net::{TcpListener, TcpStream};
 
-fn event_loop<T>(mut conn: ConnectionContext,
+fn event_loop<T>(mut conn: OssuaryContext,
                  mut stream: T,
                  is_server: bool) -> Result<(), std::io::Error>
 where T: std::io::Read + std::io::Write {
@@ -48,7 +48,7 @@ where T: std::io::Read + std::io::Write {
 fn server() -> Result<(), std::io::Error> {
     let listener = TcpListener::bind("127.0.0.1:9988").unwrap();
     let stream: TcpStream = listener.incoming().next().unwrap().unwrap();
-    let mut conn = ConnectionContext::new(ConnectionType::AuthenticatedServer);
+    let mut conn = OssuaryContext::new(ConnectionType::AuthenticatedServer);
     let keys: Vec<&[u8]> = vec![
         &[0xbe, 0x1c, 0xa0, 0x74, 0xf4, 0xa5, 0x8b, 0xbb,
           0xd2, 0x62, 0xa7, 0xf9, 0x52, 0x3b, 0x6f, 0xb0,
@@ -62,7 +62,7 @@ fn server() -> Result<(), std::io::Error> {
 
 fn client() -> Result<(), std::io::Error> {
     let stream = TcpStream::connect("127.0.0.1:9988").unwrap();
-    let mut conn = ConnectionContext::new(ConnectionType::Client);
+    let mut conn = OssuaryContext::new(ConnectionType::Client);
     let _ = conn.set_secret_key(
         &[0x10, 0x86, 0x6e, 0xc4, 0x8a, 0x11, 0xf3, 0xc5,
           0x6d, 0x77, 0xa6, 0x4b, 0x2f, 0x54, 0xaa, 0x06,