summary history branches tags files
commit:5ad6e4d9b3498745025b57ed39a414cdb2d54c6e
author:Trevor Bentley
committer:Trevor Bentley
date:Sun Apr 28 14:19:19 2019 +0200
parents:32b67e0cadba2e38bef1546db71ab58a7bdc2f4f
Rename OssuaryContext -> OssuaryConnection
diff --git a/examples/ffi.c b/examples/ffi.c
line changes: +2/-2
index 3e02309..3f84eff
--- a/examples/ffi.c
+++ b/examples/ffi.c
@@ -28,8 +28,8 @@ uint8_t *authorized_keys[] = {
 int main(int argc, char **argv) {
   int client_done, server_done;
   uint16_t client_bytes, server_bytes, bytes, out_len;
-  ConnectionContext *client_conn = NULL;
-  ConnectionContext *server_conn = NULL;
+  OssuaryConnection *client_conn = NULL;
+  OssuaryConnection *server_conn = NULL;
 
   client_conn = ossuary_create_connection(CONN_TYPE_CLIENT);
   ossuary_set_secret_key(client_conn, secret_key);

diff --git a/ffi/ossuary.h b/ffi/ossuary.h
line changes: +12/-12
index e62a10b..06a489c
--- a/ffi/ossuary.h
+++ b/ffi/ossuary.h
@@ -2,7 +2,7 @@
 
 #include <stdint.h>
 
-typedef struct ConnectionContext ConnectionContext;
+typedef struct OssuaryConnection OssuaryConnection;
 
 typedef enum {
   CONN_TYPE_CLIENT = 0x00,
@@ -10,21 +10,21 @@ typedef enum {
   CONN_TYPE_UNAUTHENTICATED_SERVER = 0x02,
 } connection_type_t;
 
-ConnectionContext *ossuary_create_connection(connection_type_t type);
-int32_t ossuary_destroy_connection(ConnectionContext **conn);
-int32_t ossuary_set_secret_key(ConnectionContext *conn, uint8_t key[32]);
-int32_t ossuary_set_authorized_keys(ConnectionContext *conn, uint8_t *key[], uint8_t count);
-int32_t ossuary_recv_handshake(ConnectionContext *conn,
+OssuaryConnection *ossuary_create_connection(connection_type_t type);
+int32_t ossuary_destroy_connection(OssuaryConnection **conn);
+int32_t ossuary_set_secret_key(OssuaryConnection *conn, uint8_t key[32]);
+int32_t ossuary_set_authorized_keys(OssuaryConnection *conn, uint8_t *key[], uint8_t count);
+int32_t ossuary_recv_handshake(OssuaryConnection *conn,
                                uint8_t *in_buf, uint16_t *in_buf_len);
-int32_t ossuary_send_handshake(ConnectionContext *conn,
+int32_t ossuary_send_handshake(OssuaryConnection *conn,
                                uint8_t *out_buf, uint16_t *out_buf_len);
-int32_t ossuary_handshake_done(ConnectionContext *conn);
-int32_t ossuary_send_data(ConnectionContext *conn,
+int32_t ossuary_handshake_done(OssuaryConnection *conn);
+int32_t ossuary_send_data(OssuaryConnection *conn,
                           uint8_t *in_buf, uint16_t in_buf_len,
                           uint8_t *out_buf, uint16_t *out_buf_len);
-int32_t ossuary_recv_data(ConnectionContext *conn,
-                  uint8_t *in_buf, uint16_t *in_buf_len,
-                  uint8_t *out_buf, uint16_t *out_buf_len);
+int32_t ossuary_recv_data(OssuaryConnection *conn,
+                          uint8_t *in_buf, uint16_t *in_buf_len,
+                          uint8_t *out_buf, uint16_t *out_buf_len);
 
 #define _OSSUARY_H
 #endif

diff --git a/src/clib.rs b/src/clib.rs
line changes: +13/-13
index d660b32..b72b3d9
--- a/src/clib.rs
+++ b/src/clib.rs
@@ -1,33 +1,33 @@
-use crate::{OssuaryContext, ConnectionType, OssuaryError};
+use crate::{OssuaryConnection, ConnectionType, OssuaryError};
 
 const ERROR_WOULD_BLOCK: i32 = -64;
 
 #[no_mangle]
-pub extern "C" fn ossuary_create_connection(conn_type: u8) -> *mut OssuaryContext {
+pub extern "C" fn ossuary_create_connection(conn_type: u8) -> *mut OssuaryConnection {
     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(OssuaryContext::new(conn_type));
+    let mut conn = Box::new(OssuaryConnection::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 OssuaryContext) {
+pub extern "C" fn ossuary_destroy_connection(conn: &mut *mut OssuaryConnection) {
     if conn.is_null() {
         return;
     }
-    let obj: Box<OssuaryContext> = unsafe { ::std::mem::transmute(*conn) };
+    let obj: Box<OssuaryConnection> = 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 OssuaryContext,
+pub extern "C" fn ossuary_set_authorized_keys(conn: *mut OssuaryConnection,
                                               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 OssuaryContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_set_secret_key(conn: *mut OssuaryContext,
+pub extern "C" fn ossuary_set_secret_key(conn: *mut OssuaryConnection,
                                          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 OssuaryContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_recv_handshake(conn: *mut OssuaryContext,
+pub extern "C" fn ossuary_recv_handshake(conn: *mut OssuaryConnection,
                                          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 OssuaryContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_send_handshake(conn: *mut OssuaryContext,
+pub extern "C" fn ossuary_send_handshake(conn: *mut OssuaryConnection,
                                          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 OssuaryContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_handshake_done(conn: *const OssuaryContext) -> i32 {
+pub extern "C" fn ossuary_handshake_done(conn: *const OssuaryConnection) -> i32 {
     if conn.is_null() {
         return -1i32;
     }
@@ -131,7 +131,7 @@ pub extern "C" fn ossuary_handshake_done(conn: *const OssuaryContext) -> i32 {
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_send_data(conn: *mut OssuaryContext,
+pub extern "C" fn ossuary_send_data(conn: *mut OssuaryConnection,
                                     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 OssuaryContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_recv_data(conn: *mut OssuaryContext,
+pub extern "C" fn ossuary_recv_data(conn: *mut OssuaryConnection,
                                     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 OssuaryContext,
 }
 
 #[no_mangle]
-pub extern "C" fn ossuary_flush(conn: *mut OssuaryContext,
+pub extern "C" fn ossuary_flush(conn: *mut OssuaryConnection,
                                 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/-28
index 5c17649..18c88f7
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -123,7 +123,6 @@
 //
 // TODO
 //  - Increment nonce on each encryption/decryption:
-//  - rename to OssuaryConnection
 //  - server certificate (TOFU)
 //  - consider all unexpected packet types to be errors
 //  - ensure that a reset on one end always sends a reset to the other
@@ -226,8 +225,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 [`OssuaryContext::set_authorized_keys`] or
-    /// [`OssuaryContext::set_secret_key`].  Both should be 32 bytes.
+    /// secret or public key in [`OssuaryConnection::set_authorized_keys`] or
+    /// [`OssuaryConnection::set_secret_key`].  Both should be 32 bytes.
     KeySize(usize, usize), // (expected, actual)
 
     /// An error occurred when parsing or using an encryption key.
@@ -640,7 +639,7 @@ impl NetworkPacket {
     }
 }
 
-/// Internal state of OssuaryContext state machine.
+/// Internal state of OssuaryConnection state machine.
 #[derive(Debug)]
 enum ConnectionState {
     /// Server is waiting for handshake packet from a client
@@ -711,7 +710,7 @@ impl Default for SessionKeyMaterial {
     }
 }
 
-/// Enum specifying the client or server role of a [`OssuaryContext`]
+/// Enum specifying the client or server role of a [`OssuaryConnection`]
 #[derive(Clone)]
 pub enum ConnectionType {
     /// This context is a client
@@ -720,9 +719,9 @@ pub enum ConnectionType {
     /// This context is a server that requires authentication.
     ///
     /// Authenticated servers only allow connections from clients with secret
-    /// keys set using [`OssuaryContext::set_secret_key`], and with the
+    /// keys set using [`OssuaryConnection::set_secret_key`], and with the
     /// matching public key registered with the server using
-    /// [`OssuaryContext::set_authorized_keys`].
+    /// [`OssuaryConnection::set_authorized_keys`].
     AuthenticatedServer,
 
     /// This context is a server that does not support authentication.
@@ -737,26 +736,26 @@ pub enum ConnectionType {
 /// Context for interacting with an encrypted communication channel
 ///
 /// All interaction with ossuary's encrypted channels is performed via a
-/// OssuaryContext instance.  It holds all of the state required to maintain
+/// OssuaryConnection instance.  It holds all of the state required to maintain
 /// one side of an encrypted connection.
 ///
-/// A context is created with [`OssuaryContext::new`], passing it a
+/// A context is created with [`OssuaryConnection::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
-/// [`OssuaryContext::set_authorized_keys`].  Clients, on the other hand,
+/// [`OssuaryConnection::set_authorized_keys`].  Clients, on the other hand,
 /// authenticate by setting their secret key with
-/// [`OssuaryContext::set_secret_key`].
+/// [`OssuaryConnection::set_secret_key`].
 ///
-/// A server must create one OssuaryContext per connected client.  Multiple
+/// A server must create one OssuaryConnection per connected client.  Multiple
 /// connections cannot be multiplexed in one context.
 ///
-/// A OssuaryContext keeps temporary buffers for both received and soon-to-be
+/// A OssuaryConnection 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 OssuaryContext {
+pub struct OssuaryConnection {
     state: ConnectionState,
     conn_type: ConnectionType,
     local_key: SessionKeyMaterial, // session key
@@ -773,9 +772,9 @@ pub struct OssuaryContext {
     write_buf: [u8; PACKET_BUF_SIZE],
     write_buf_used: usize,
 }
-impl Default for OssuaryContext {
+impl Default for OssuaryConnection {
     fn default() -> Self {
-        OssuaryContext {
+        OssuaryConnection {
             state: ConnectionState::ClientSendHandshake,
             conn_type: ConnectionType::Client,
             local_key: Default::default(),
@@ -792,12 +791,12 @@ impl Default for OssuaryContext {
         }
     }
 }
-impl OssuaryContext {
-    /// Allocate a new OssuaryContext.
+impl OssuaryConnection {
+    /// Allocate a new OssuaryConnection.
     ///
     /// `conn_type` is a [`ConnectionType`] indicating whether this instance
     /// is for a client or server.
-    pub fn new(conn_type: ConnectionType) -> OssuaryContext {
+    pub fn new(conn_type: ConnectionType) -> OssuaryConnection {
         //let mut rng = thread_rng();
         let mut rng = OsRng::new().expect("RNG not available.");
         let sec_key = EphemeralSecret::new(&mut rng);
@@ -820,7 +819,7 @@ impl OssuaryContext {
             public_key: None,
             secret_key: None,
         };
-        OssuaryContext {
+        OssuaryConnection {
             state: match conn_type {
                 ConnectionType::Client => ConnectionState::ClientSendHandshake,
                 _ => ConnectionState::ServerWaitHandshake(std::time::SystemTime::now()),
@@ -846,7 +845,7 @@ impl OssuaryContext {
     /// connection, such as when the client's key is not authorized.
     ///
     fn reset_state(&mut self, permanent_err: Option<OssuaryError>) {
-        let default = OssuaryContext::new(self.conn_type.clone());
+        let default = OssuaryConnection::new(self.conn_type.clone());
         *self = default;
         self.state = match permanent_err {
             None => {
@@ -934,7 +933,7 @@ impl OssuaryContext {
     }
     /// Get the client's authentication public verification key
     ///
-    /// When a secret key is set with [`OssuaryContext::set_secret_key`], the
+    /// When a secret key is set with [`OssuaryConnection::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.
     ///
@@ -1529,7 +1528,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 OssuaryContext,
+fn read_packet<T,U>(conn: &mut OssuaryConnection,
                     mut stream: T) ->Result<(NetworkPacket, usize), OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
       U: std::io::Read {
@@ -1575,13 +1574,13 @@ where T: std::ops::DerefMut<Target = U>,
     header_size + packet_len))
 }
 
-/// Write a packet from OssuaryContext's internal storage to the out buffer.
+/// Write a packet from OssuaryConnection'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 OssuaryContext,
+fn write_stored_packet<T,U>(conn: &mut OssuaryConnection,
                             stream: &mut T) -> Result<usize, OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
       U: std::io::Write {
@@ -1610,14 +1609,14 @@ where T: std::ops::DerefMut<Target = U>,
     Ok(written)
 }
 
-/// Write a packet to the OssuaryContext's internal packet buffer
+/// Write a packet to the OssuaryConnection'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 OssuaryContext,
+fn write_packet<T,U>(conn: &mut OssuaryConnection,
                      stream: &mut T, data: &[u8],
                      kind: PacketType) -> Result<usize, OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
@@ -1640,7 +1639,7 @@ mod tests {
 
     #[test]
     fn test_set_authorized_keys() {
-        let mut conn = OssuaryContext::new(ConnectionType::AuthenticatedServer);
+        let mut conn = OssuaryConnection::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 eed6691..8a0815f
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -1,10 +1,10 @@
-use ossuary::{OssuaryContext, ConnectionType};
+use ossuary::{OssuaryConnection, ConnectionType};
 use ossuary::OssuaryError;
 
 use std::thread;
 use std::net::{TcpListener, TcpStream};
 
-fn event_loop<T>(mut conn: OssuaryContext,
+fn event_loop<T>(mut conn: OssuaryConnection,
                  mut stream: T,
                  is_server: bool) -> Result<(), std::io::Error>
 where T: std::io::Read + std::io::Write {
@@ -50,7 +50,7 @@ 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 _ = stream.set_read_timeout(Some(std::time::Duration::from_millis(100u64)));
-    let conn = OssuaryContext::new(ConnectionType::UnauthenticatedServer);
+    let conn = OssuaryConnection::new(ConnectionType::UnauthenticatedServer);
     let _ = event_loop(conn, stream, true);
     Ok(())
 }
@@ -58,7 +58,7 @@ fn server() -> Result<(), std::io::Error> {
 fn client() -> Result<(), std::io::Error> {
     let stream = TcpStream::connect("127.0.0.1:9988").unwrap();
     let _ = stream.set_read_timeout(Some(std::time::Duration::from_millis(100u64)));
-    let conn = OssuaryContext::new(ConnectionType::Client);
+    let conn = OssuaryConnection::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 dc3645b..25c946a
--- a/tests/basic_auth.rs
+++ b/tests/basic_auth.rs
@@ -1,10 +1,10 @@
-use ossuary::{OssuaryContext, ConnectionType};
+use ossuary::{OssuaryConnection, ConnectionType};
 use ossuary::OssuaryError;
 
 use std::thread;
 use std::net::{TcpListener, TcpStream};
 
-fn event_loop<T>(mut conn: OssuaryContext,
+fn event_loop<T>(mut conn: OssuaryConnection,
                  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 = OssuaryContext::new(ConnectionType::AuthenticatedServer);
+    let mut conn = OssuaryConnection::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 = OssuaryContext::new(ConnectionType::Client);
+    let mut conn = OssuaryConnection::new(ConnectionType::Client);
     let _ = conn.set_secret_key(
         &[0x10, 0x86, 0x6e, 0xc4, 0x8a, 0x11, 0xf3, 0xc5,
           0x6d, 0x77, 0xa6, 0x4b, 0x2f, 0x54, 0xaa, 0x06,