Loading trusty/libtrusty-rs/Android.bp +9 −0 Original line number Diff line number Diff line Loading @@ -26,3 +26,12 @@ rust_library { "libnix", ], } rust_test { name: "libtrusty-rs-tests", crate_name: "trusty_test", srcs: ["tests/test.rs"], rustlibs: [ "libtrusty-rs", ] } trusty/libtrusty-rs/src/lib.rs +6 −6 Original line number Diff line number Diff line Loading @@ -128,15 +128,15 @@ impl TipcChannel { /// Receives a message from the connected service. /// /// Returns the number of bytes in the received message, or any error that /// occurred when reading the message. A return value of 0 indicates that /// there were no incoming messages to receive. /// occurred when reading the message. Blocks until there is a message to /// receive if none is already ready to read. /// /// # Errors /// /// Returns an error with native error code 90 (`EMSGSIZE`) if `buf` isn't /// large enough to contain the incoming message. Use /// [`raw_os_error`][std::io::Error::raw_os_error] to check the error code /// to determine if you need to increase the size of `buf`. /// Returns an error with native error code 90 (`EMSGSIZE`) if `buf` isn't large /// enough to contain the incoming message. Use /// [`raw_os_error`][std::io::Error::raw_os_error] to check the error code to /// determine if you need to increase the size of `buf`. pub fn recv(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.read(buf) } Loading trusty/libtrusty-rs/tests/test.rs 0 → 100644 +26 −0 Original line number Diff line number Diff line use trusty::{TipcChannel, DEFAULT_DEVICE}; const ECHO_NAME: &str = "com.android.ipc-unittest.srv.echo"; #[test] fn echo() { let mut connection = TipcChannel::connect(DEFAULT_DEVICE, ECHO_NAME) .expect("Failed to connect to Trusty service"); // Send a message to the echo TA. let send_buf = [7u8; 32]; connection.send(send_buf.as_slice()).unwrap(); // Receive the response message from the TA. let mut recv_buf = [0u8; 32]; let read_len = connection.recv(&mut recv_buf).expect("Failed to read from connection"); assert_eq!( send_buf.len(), read_len, "Received data was wrong size (expected {} bytes, received {})", send_buf.len(), read_len, ); assert_eq!(send_buf, recv_buf, "Received data does not match sent data"); } Loading
trusty/libtrusty-rs/Android.bp +9 −0 Original line number Diff line number Diff line Loading @@ -26,3 +26,12 @@ rust_library { "libnix", ], } rust_test { name: "libtrusty-rs-tests", crate_name: "trusty_test", srcs: ["tests/test.rs"], rustlibs: [ "libtrusty-rs", ] }
trusty/libtrusty-rs/src/lib.rs +6 −6 Original line number Diff line number Diff line Loading @@ -128,15 +128,15 @@ impl TipcChannel { /// Receives a message from the connected service. /// /// Returns the number of bytes in the received message, or any error that /// occurred when reading the message. A return value of 0 indicates that /// there were no incoming messages to receive. /// occurred when reading the message. Blocks until there is a message to /// receive if none is already ready to read. /// /// # Errors /// /// Returns an error with native error code 90 (`EMSGSIZE`) if `buf` isn't /// large enough to contain the incoming message. Use /// [`raw_os_error`][std::io::Error::raw_os_error] to check the error code /// to determine if you need to increase the size of `buf`. /// Returns an error with native error code 90 (`EMSGSIZE`) if `buf` isn't large /// enough to contain the incoming message. Use /// [`raw_os_error`][std::io::Error::raw_os_error] to check the error code to /// determine if you need to increase the size of `buf`. pub fn recv(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.0.read(buf) } Loading
trusty/libtrusty-rs/tests/test.rs 0 → 100644 +26 −0 Original line number Diff line number Diff line use trusty::{TipcChannel, DEFAULT_DEVICE}; const ECHO_NAME: &str = "com.android.ipc-unittest.srv.echo"; #[test] fn echo() { let mut connection = TipcChannel::connect(DEFAULT_DEVICE, ECHO_NAME) .expect("Failed to connect to Trusty service"); // Send a message to the echo TA. let send_buf = [7u8; 32]; connection.send(send_buf.as_slice()).unwrap(); // Receive the response message from the TA. let mut recv_buf = [0u8; 32]; let read_len = connection.recv(&mut recv_buf).expect("Failed to read from connection"); assert_eq!( send_buf.len(), read_len, "Received data was wrong size (expected {} bytes, received {})", send_buf.len(), read_len, ); assert_eq!(send_buf, recv_buf, "Received data does not match sent data"); }