summary history branches tags files
commit:84309f8def0ce862cc9aae5d37426e9d8fbc81e5
author:Trevor Bentley
committer:Trevor Bentley
date:Fri Jan 18 10:59:18 2019 +0100
parents:dfaa9714f0c54c240a7c9e10a285a6dceface342
return usize instead of u16 in Rust API
diff --git a/src/clib.rs b/src/clib.rs
line changes: +5/-5
index d8ed02c..a7c467f
--- a/src/clib.rs
+++ b/src/clib.rs
@@ -128,15 +128,15 @@ 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: u16;
+    let bytes_written: i32;
     match crypto_send_data(&mut conn, &in_slice, &mut out_slice) {
         Ok(x) => {
-            bytes_written = x;
+            bytes_written = x as i32;
         }
         Err(_) => { return -1; },
     }
     ::std::mem::forget(conn);
-    bytes_written as i32
+    bytes_written
 }
 
 #[no_mangle]
@@ -154,8 +154,8 @@ pub extern "C" fn ossuary_recv_data(conn: *mut ConnectionContext,
     let bytes_read: u16;
     match crypto_recv_data(&mut conn, &mut in_slice, &mut out_slice) {
         Ok((read,written)) => {
-            unsafe { *out_buf_len = written };
-            bytes_read = read;
+            unsafe { *out_buf_len = written as u16 };
+            bytes_read = read as u16;
         },
         Err(_) => {
             return -1;

diff --git a/src/lib.rs b/src/lib.rs
line changes: +7/-7
index c3d4b3b..cddf3d1
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -838,7 +838,7 @@ pub fn crypto_handshake_done(conn: &ConnectionContext) -> Result<bool, &OssuaryE
     }
 }
 
-pub fn crypto_send_data<T,U>(conn: &mut ConnectionContext, in_buf: &[u8], mut out_buf: T) -> Result<u16, OssuaryError>
+pub fn crypto_send_data<T,U>(conn: &mut ConnectionContext, in_buf: &[u8], mut out_buf: T) -> Result<usize, OssuaryError>
 where T: std::ops::DerefMut<Target = U>,
       U: std::io::Write {
     match conn.state {
@@ -877,18 +877,18 @@ where T: std::ops::DerefMut<Target = U>,
     buf.extend(&tag);
     let _ = write_packet(&mut out_buf, &buf,
                          &mut next_msg_id, PacketType::EncryptedData);
-    bytes = (buf.len() + ::std::mem::size_of::<PacketHeader>()) as u16;
+    bytes = buf.len() + ::std::mem::size_of::<PacketHeader>();
     conn.local_msg_id = next_msg_id;
     Ok(bytes)
 }
 
-pub fn crypto_recv_data<T,U,R,V>(conn: &mut ConnectionContext, in_buf: T, mut out_buf: R) -> Result<(u16, u16), OssuaryError>
+pub fn crypto_recv_data<T,U,R,V>(conn: &mut ConnectionContext, 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>,
       V: std::io::Write {
-    let bytes_written: u16;
-    let mut bytes_read: u16 = 0u16;
+    let bytes_written: usize;
+    let mut bytes_read: usize = 0;
     match conn.state {
         ConnectionState::Encrypted => {},
         _ => {
@@ -898,7 +898,7 @@ where T: std::ops::DerefMut<Target = U>,
 
     match read_packet(conn, in_buf) {
         Ok((pkt, bytes)) => {
-            bytes_read += bytes as u16;
+            bytes_read += bytes;
             if pkt.header.msg_id != conn.remote_msg_id {
                 println!("Message gap detected.  Restarting connection.");
                 println!("Server: {}", conn.is_server());
@@ -933,7 +933,7 @@ where T: std::ops::DerefMut<Target = U>,
                                             &remote_nonce,
                                             &aad, &ciphertext, &tag, &mut plaintext);
                             let _ = out_buf.write(&plaintext);
-                            bytes_written = ciphertext.len() as u16;
+                            bytes_written = ciphertext.len();
                         },
                         Err(_) => {
                             conn.reset_state(None);