This is an automated email from the ASF dual-hosted git repository. ivila pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-trustzone-sdk.git
commit 205ba97a96ce9a926024874c933b5a282cfd3e14 Author: ivila <[email protected]> AuthorDate: Thu Jul 3 17:40:27 2025 +0800 doc: optee-utee: fix doctest Signed-off-by: Zehui Chen <[email protected]> Acked-by: Yuan Zhuang <[email protected]> --- optee-utee/src/crypto_op.rs | 138 +++++++++++++++++++++++++------------ optee-utee/src/error.rs | 4 +- optee-utee/src/extension.rs | 39 +++++++++-- optee-utee/src/macros.rs | 23 ++++--- optee-utee/src/net/optee_no_std.rs | 24 +++---- optee-utee/src/object.rs | 122 +++++++++++++++++++++++--------- optee-utee/src/tee_parameter.rs | 12 +++- optee-utee/src/time.rs | 21 ++++-- optee-utee/src/uuid.rs | 20 ++++-- 9 files changed, 288 insertions(+), 115 deletions(-) diff --git a/optee-utee/src/crypto_op.rs b/optee-utee/src/crypto_op.rs index 9e0a4f5..f5b8f3f 100644 --- a/optee-utee/src/crypto_op.rs +++ b/optee-utee/src/crypto_op.rs @@ -293,15 +293,17 @@ impl Digest { /// /// # Example /// - /// ```no_run - /// let chunk = [0u8;8]; - /// let chunk = [1u8;8]; - /// let hash = [0u8;32]; + /// ``` rust,no_run + /// # use optee_utee::{Digest, AlgorithmId}; + /// # fn main() -> optee_utee::Result<()> { + /// let chunk1 = [0u8;8]; + /// let chunk2 = [1u8;8]; + /// let mut hash = [0u8;32]; /// match Digest::allocate(AlgorithmId::Sha256) { /// Ok(operation) => /// { /// operation.update(&chunk1); - /// match operation.do_final(&chunk2, hash) { + /// match operation.do_final(&chunk2, &mut hash) { /// Ok(hash_len) => { /// // ... /// Ok(()) @@ -311,6 +313,7 @@ impl Digest { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -355,7 +358,9 @@ impl Digest { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{Digest, AlgorithmId}; + /// # fn main() -> optee_utee::Result<()> { /// match Digest::allocate(AlgorithmId::Sha256) { /// Ok(operation) => /// { @@ -364,6 +369,7 @@ impl Digest { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -386,8 +392,10 @@ impl Digest { /// /// # Example /// - /// ```no_run - /// match Digest::allocate(AlgorithmId::Md5, 128) { + /// ``` rust,no_run + /// # use optee_utee::{Digest, AlgorithmId}; + /// # fn main() -> optee_utee::Result<()> { + /// match Digest::allocate(AlgorithmId::Md5) { /// Ok(operation) => /// { /// let info = operation.info(); @@ -395,6 +403,7 @@ impl Digest { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Panics @@ -414,11 +423,13 @@ impl Digest { /// /// # Example /// - /// ```no_run - /// match Digest::allocate(AlgorithmId::Md5, 128) { + /// ``` rust,no_run + /// # use optee_utee::{Digest, AlgorithmId}; + /// # fn main() -> optee_utee::Result<()> { + /// match Digest::allocate(AlgorithmId::Md5) { /// Ok(operation) => /// { - /// let mut buffer = [0u32, 12]; + /// let mut buffer = [0u8, 12]; /// match operation.info_multiple(&mut buffer) { /// Ok(info_multiple) => { /// // ... @@ -429,6 +440,7 @@ impl Digest { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors: @@ -472,22 +484,25 @@ impl Digest { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{Digest, AlgorithmId}; + /// # fn main() -> optee_utee::Result<()> { /// match Digest::allocate(AlgorithmId::Sha256) { - /// Ok(operation) => + /// Ok(mut operation) => /// { /// match Digest::allocate(AlgorithmId::Sha256) { /// Ok(operation2) => /// { /// // ... - /// operation.copy(operation2); + /// operation.copy(&operation2); /// Ok(()) - /// } + /// }, /// Err(e) => Err(e), /// } - /// } + /// }, /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Panics @@ -555,16 +570,19 @@ impl Cipher { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{Cipher, AlgorithmId, TransientObject, TransientObjectType}; + /// # use optee_utee::{AttributeMemref, AttributeId, OperationMode}; + /// # fn main() -> optee_utee::Result<()> { /// let iv = [0u8, 16]; /// let key = [0u8, 16]; /// let src = [1u8; 4096]; /// let mut dest = [0u8; 4096]; - /// match Cipher::allocate(AlgorithmId::AesCtr, 128) { + /// match Cipher::allocate(AlgorithmId::AesCtr, OperationMode::Encrypt, 128) { /// Ok(operation) => /// { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { - /// Ok(object) => + /// Ok(mut object) => /// { /// let attr = AttributeMemref::from_ref(AttributeId::SecretValue, &key); /// object.populate(&[attr.into()])?; @@ -578,6 +596,7 @@ impl Cipher { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -802,7 +821,17 @@ impl Mac { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{ + /// TransientObject, + /// TransientObjectType, + /// Attribute, + /// AttributeMemref, + /// AttributeId, + /// Mac, + /// AlgorithmId, + /// }; + /// # fn main() -> optee_utee::Result<()> { /// let mut key: [u8; 20] = [ /// 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, /// 0x36, 0x37, 0x38, 0x39, 0x30,]; @@ -811,17 +840,20 @@ impl Mac { /// Err(e) => return Err(e), /// Ok(mac) => { /// match TransientObject::allocate(TransientObjectType::HmacSha1, key.len() * 8) { - /// Err(e) => return Err(e), - /// Ok(mut key_object) => { - /// let attr = Attribute::from_ref(AttributeId::SecretValue, &key); - /// key_object.populate(&[attr.into()])?; - /// mac.set_key(&key_object)?; + /// Err(e) => return Err(e), + /// Ok(mut key_object) => { + /// let attr = AttributeMemref::from_ref(AttributeId::SecretValue, &key); + /// key_object.populate(&[attr.into()])?; + /// mac.set_key(&key_object)?; + /// } /// } + /// mac.init(&[0u8; 0]); + /// mac.update(&[0u8; 8]); + /// mac.compute_final(&[0u8; 0], &mut out)?; + /// Ok(()) /// } - /// mac.init(&[0u8; 0]); - /// mac.update(&[0u8; 8]); - /// mac.compute_final(&[0u8; 0], &mut out)?; /// } + /// # } /// ``` /// /// # Errors @@ -1057,7 +1089,10 @@ impl AE { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{AE, AlgorithmId, OperationMode, AttributeMemref, AttributeId}; + /// # use optee_utee::{TransientObject, TransientObjectType}; + /// # fn main() -> optee_utee::Result<()> { /// let key = [0xa5u8; 16]; /// let nonce = [0x00u8; 16]; /// let aad = [0xffu8; 16]; @@ -1069,24 +1104,27 @@ impl AE { /// match AE::allocate(AlgorithmId::AesCcm, OperationMode::Encrypt, 128) { /// Ok(operation) => { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { - /// Ok(key_object) => { - /// let attr = Attributememref::from_ref(Attributeid::SecretValue, &key); - /// key_object.populat(&[attr.into()])?; + /// Ok(mut key_object) => { + /// let attr = AttributeMemref::from_ref(AttributeId::SecretValue, &key); + /// key_object.populate(&[attr.into()])?; /// operation.set_key(&key_object)?; /// operation.init(&nonce, 128, 16, 32)?; /// operation.update_aad(&aad); /// operation.update(&clear1, &mut ciph1)?; - /// match operation.encrypt_final(&clear2, &mut ciph2) { + /// match operation.encrypt_final(&clear2, &mut ciph2, &mut tag) { /// Ok((_ciph_len, _tag_len)) => { /// // ... - /// Ok(()), - /// } + /// Ok(()) + /// }, /// Err(e) => Err(e), /// } + /// }, /// Err(e) => Err(e), /// } + /// }, /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1229,7 +1267,10 @@ impl Asymmetric { /// 2) `src`: Input plaintext buffer. /// /// # Example - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType, Asymmetric}; + /// # use optee_utee::{AlgorithmId, OperationMode}; + /// # fn main() -> optee_utee::Result<()> { /// let clear = [1u8; 8]; /// match TransientObject::allocate(TransientObjectType::RsaKeypair, 256) { /// Ok(key) => { @@ -1254,6 +1295,7 @@ impl Asymmetric { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1485,17 +1527,26 @@ impl DeriveKey { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{AttributeMemref, AttributeId, TransientObject, TransientObjectType}; + /// # use optee_utee::{DeriveKey, AlgorithmId}; + /// # fn example1() -> optee_utee::Result<()> { + /// /// let attr_prime = AttributeMemref::from_ref(AttributeId::DhPrime, &[23u8]); /// let attr_base = AttributeMemref::from_ref(AttributeId::DhBase, &[5u8]); /// let mut public_1 = [0u8; 32]; /// match TransientObject::allocate(TransientObjectType::DhKeypair, 256) { /// Ok(key_pair_1) => { /// key_pair_1.generate_key(256, &[attr_prime.into(), attr_base.into()])?; - /// key_pair_1.ref_attribute(aTTRIBUTEiD::DhPublicValue, &mut public_1)?; - /// } + /// key_pair_1.ref_attribute(AttributeId::DhPublicValue, &mut public_1)?; + /// Ok(()) + /// }, /// Err(e) => Err(e), /// } + /// # } + /// + /// # fn example2() -> optee_utee::Result<()> { + /// # let mut public_1 = [0u8; 32]; /// /// let attr_prime = AttributeMemref::from_ref(AttributeId::DhPrime, &[23u8]); /// let attr_base = AttributeMemref::from_ref(AttributeId::DhBase, &[5u8]); @@ -1505,10 +1556,9 @@ impl DeriveKey { /// match DeriveKey::allocate(AlgorithmId::DhDeriveSharedSecret, 256) { /// Ok(operation) => { /// operation.set_key(&key_pair_2)?; - /// match TransientObject::allocate(TransientObjectType::GenericSecret, - /// 256) { + /// match TransientObject::allocate(TransientObjectType::GenericSecret, 256) { /// // Derived key is saved as an transient object - /// Ok(derived_key) => { + /// Ok(mut derived_key) => { /// let attr_public = AttributeMemref::from_ref(AttributeId::DhPublicValue, &public_1); /// operation.derive(&[attr_public.into()], &mut derived_key); /// // ... @@ -1522,6 +1572,7 @@ impl DeriveKey { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Panics @@ -1597,7 +1648,8 @@ impl Random { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::Random; /// let mut res = [0u8;16]; /// Random::generate(&mut res); /// ``` diff --git a/optee-utee/src/error.rs b/optee-utee/src/error.rs index 97ea941..de4e46a 100644 --- a/optee-utee/src/error.rs +++ b/optee-utee/src/error.rs @@ -27,7 +27,9 @@ use std::error; /// /// # Examples /// -/// ``` no_run +/// ``` rust,no_run +/// # use optee_utee::Parameters; +/// use optee_utee::Result; /// fn open_session(params: &mut Parameters) -> Result<()> { /// Ok(()) /// } diff --git a/optee-utee/src/extension.rs b/optee-utee/src/extension.rs index dd07905..9190b24 100644 --- a/optee-utee/src/extension.rs +++ b/optee-utee/src/extension.rs @@ -38,8 +38,17 @@ impl LoadablePlugin { Self { uuid: uuid.to_owned() } } /// Invoke plugin with given request data, use when you want to post something into REE. - /// ```no_run - /// let result = plugin.invoke(command_id, subcommand_id, request_data)?; + /// ``` rust,no_run + /// # use optee_utee::{LoadablePlugin, Uuid}; + /// # fn main() -> optee_utee::Result<()> { + /// # let uuid = Uuid::parse_str("").unwrap(); + /// # let command_id = 0; + /// # let subcommand_id = 0; + /// # let request_data = [0_u8; 0]; + /// let plugin = LoadablePlugin::new(&uuid); + /// let result = plugin.invoke(command_id, subcommand_id, &request_data)?; + /// # Ok(()) + /// # } /// ``` /// Caution: the size of the shared buffer is set to the len of data, you could get a /// ShortBuffer error if Plugin return more data than shared buffer, in that case, @@ -52,13 +61,29 @@ impl LoadablePlugin { /// Construct a command with shared buffer up to capacity size, write the buffer and call it /// manually, use when you need to control details of the invoking process. /// ```no_run + /// # use optee_utee::{Uuid, LoadablePlugin}; + /// # fn main() -> optee_utee::Result<()> { + /// # let plugin = LoadablePlugin::new(&Uuid::parse_str("").unwrap()); + /// # let request_data = [0_u8; 0]; + /// # let command_id = 0; + /// # let sub_command_id = 0; + /// # let capacity = 0; /// let mut cmd = plugin.invoke_with_capacity(command_id, sub_command_id, capacity); - /// cmd.write(request_data); + /// cmd.write_body(&request_data); /// let result = cmd.call()?; + /// # Ok(()) + /// # } /// ``` /// You can also imply a wrapper for performance, for example, imply a std::io::Write so /// serde_json can write to the buffer directly. /// ```no_run + /// # use optee_utee::{LoadablePluginCommand, Uuid, LoadablePlugin, trace_println}; + /// # use optee_utee::ErrorKind; + /// # fn main() -> optee_utee::Result<()> { + /// # let command_id = 0; + /// # let subcommand_id = 0; + /// # let capacity = 0; + /// # let plugin = LoadablePlugin::new(&Uuid::parse_str("").unwrap()); /// struct Wrapper<'a, 'b>(&'b mut LoadablePluginCommand<'a>); /// impl<'a, 'b> std::io::Write for Wrapper<'a, 'b> { /// fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { @@ -75,8 +100,14 @@ impl LoadablePlugin { /// "name": "name" /// }); /// let mut cmd = plugin.invoke_with_capacity(command_id, subcommand_id, capacity); - /// serde_json::to_writer(Wrapper(&mut plugin_cmd), &request_data)?; + /// serde_json::to_writer(Wrapper(&mut cmd), &request_data).map_err(|err| { + /// trace_println!("serde error: {:?}", err); + /// ErrorKind::Unknown + /// })?; /// let result = cmd.call()?; + /// + /// # Ok(()) + /// # } /// ``` /// Notice: the shared buffer could grow to fit the request data automatically. pub fn invoke_with_capacity<'a>( diff --git a/optee-utee/src/macros.rs b/optee-utee/src/macros.rs index 1021f78..5963bd0 100644 --- a/optee-utee/src/macros.rs +++ b/optee-utee/src/macros.rs @@ -22,15 +22,17 @@ /// /// # Examples /// -/// ``` no_run -/// trace_print!("this ") -/// trace_print!("will ") -/// trace_print!("be ") -/// trace_print!("on ") -/// trace_print!("the ") -/// trace_print!("same ") -/// trace_print!("line ") -/// print!("this string has a newline, why not choose println! instead?\n"); +/// ``` rust,no_run +/// # use optee_utee::trace_print; +/// +/// trace_print!("this "); +/// trace_print!("will "); +/// trace_print!("be "); +/// trace_print!("on "); +/// trace_print!("the "); +/// trace_print!("same "); +/// trace_print!("line "); +/// trace_print!("this string has a newline, why not choose println! instead?\n"); /// ``` #[macro_export] macro_rules! trace_print { @@ -43,7 +45,8 @@ macro_rules! trace_print { /// /// # Examples /// -/// ``` no_run +/// ``` rust,no_run +/// # use optee_utee::trace_println; /// trace_println!("Hello, World!"); /// trace_println!("format {} arguments", "some"); /// ``` diff --git a/optee-utee/src/net/optee_no_std.rs b/optee-utee/src/net/optee_no_std.rs index dff4648..8ed9af6 100644 --- a/optee-utee/src/net/optee_no_std.rs +++ b/optee-utee/src/net/optee_no_std.rs @@ -20,8 +20,8 @@ use super::{Setup, Socket, SocketAdapter, SocketError}; /// with the std version (with the only difference being the return error type). /// /// Take TcpStream as example: -/// ```no_run -/// use optee_utee::net::TcpStream; +/// ``` rust,no_run +/// use optee_utee::net::{Setup, TcpStream, SocketError}; /// /// fn connect_without_compact_trait(host: &str, port: u16) -> Result<TcpStream, SocketError> { /// let setup = Setup::new_v4(host, port)?; @@ -46,12 +46,12 @@ pub trait StdCompatConnect: Sized { /// with the std version (with the only difference being the return error type). /// /// Take TcpStream as example: -/// ```no_run -/// use optee_utee::net::TcpStream; +/// ``` rust,no_run +/// use optee_utee::net::{TcpStream, SocketError}; /// -/// fn write_without_compact_trait(stream: &mut Stream, mut buf: &[u8]) -> Result<usize, SocketError> { +/// fn write_without_compact_trait(stream: &mut TcpStream, mut buf: &[u8]) -> Result<(), SocketError> { /// use optee_utee::ErrorKind; -/// +/// /// while !buf.is_empty() { /// match stream.send(buf) { /// Ok(0) => return Err(SocketError::Tee(ErrorKind::Generic)), @@ -62,7 +62,7 @@ pub trait StdCompatConnect: Sized { /// Ok(()) /// } /// -/// fn write_with_compact_trait(stream: &mut Stream, buf: &[u8]) -> Result<usize, SocketError> { +/// fn write_with_compact_trait(stream: &mut TcpStream, buf: &[u8]) -> Result<(), SocketError> { /// use optee_utee::net::StdCompatWrite; /// /// stream.write_all(buf) @@ -85,15 +85,15 @@ pub trait StdCompatWrite { /// with the std version (with the only difference being the return error type). /// /// Take TcpStream as example: -/// ```no_run -/// use optee_utee::net::TcpStream; +/// ``` rust,no_run +/// use optee_utee::net::{TcpStream, SocketError}; /// -/// fn read_without_compact_trait(stream: &mut Stream, mut buf: &mut [u8]) -> Result<usize, SocketError> { +/// fn read_without_compact_trait(stream: &mut TcpStream, mut buf: &mut [u8]) -> Result<(), SocketError> { /// use optee_utee::ErrorKind; /// /// while !buf.is_empty() { /// match stream.recv(buf) { -/// Ok(0) => break; +/// Ok(0) => break, /// Ok(n) => buf = &mut buf[n..], /// Err(e) => return Err(e), /// } @@ -104,7 +104,7 @@ pub trait StdCompatWrite { /// Ok(()) /// } /// -/// fn read_with_compact_trait(stream: &mut Stream, buf: &mut [u8]) -> Result<usize, SocketError> { +/// fn read_with_compact_trait(stream: &mut TcpStream, buf: &mut [u8]) -> Result<(), SocketError> { /// use optee_utee::net::StdCompatRead; /// /// stream.read_exact(buf) diff --git a/optee-utee/src/object.rs b/optee-utee/src/object.rs index 71998bd..1dfdad0 100644 --- a/optee-utee/src/object.rs +++ b/optee-utee/src/object.rs @@ -89,7 +89,8 @@ impl<'attrref> AttributeMemref<'attrref> { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{AttributeMemref, AttributeId}; /// let mut attr = AttributeMemref::from_ref(AttributeId::SecretValue, &mut [0u8;1]); /// ``` pub fn from_ref(id: AttributeId, buffer: &'attrref [u8]) -> Self { @@ -136,7 +137,8 @@ impl AttributeValue { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{AttributeValue, AttributeId}; /// let mut attr = AttributeValue::from_value(AttributeId::SecretValue, 0, 0); /// ``` pub fn from_value(id: AttributeId, a: u32, b: u32) -> Self { @@ -550,7 +552,9 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType}; + /// # fn main() -> optee_utee::Result<()> { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { /// Ok(object) => /// { @@ -559,6 +563,7 @@ impl TransientObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -603,16 +608,24 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{ + /// # TransientObject, + /// # TransientObjectType, + /// # AttributeMemref, + /// # AttributeId, + /// # }; + /// # fn main() -> optee_utee::Result<()> { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { - /// Ok(object) => + /// Ok(mut object) => /// { - /// let attrs = [AttributeMemref::from_ref(AttributeId::SecretValue, &[0u8;1])]; + /// let attrs = [AttributeMemref::from_ref(AttributeId::SecretValue, &[0u8;1]).into()]; /// object.populate(&attrs); /// Ok(()) /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -642,7 +655,9 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType}; + /// # fn main() -> optee_utee::Result<()> { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { /// Ok(object) => { /// match object.info() { @@ -650,10 +665,12 @@ impl TransientObject { /// // ... /// Ok(()) /// } - /// Err(e) => Err(e), + /// Err(e) => Err(e), + /// } /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Panics @@ -675,15 +692,18 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType, UsageFlag}; + /// # fn main() -> optee_utee::Result<()> { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { - /// Ok(object) => + /// Ok(mut object) => /// { /// object.restrict_usage(UsageFlag::ENCRYPT)?; /// Ok(()) /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Panics @@ -704,7 +724,10 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType, AttributeId}; + /// # fn main() -> optee_utee::Result<()> { + /// # let id = AttributeId::SecretValue; /// match TransientObject::allocate(TransientObjectType::Aes, 128) { /// Ok(object) => { /// let mut attr = [0u8; 16]; @@ -718,6 +741,7 @@ impl TransientObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -743,11 +767,14 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType}; + /// # fn main() -> optee_utee::Result<()> { + /// # let id = 0_u32; /// match TransientObject::allocate(TransientObjectType::Aes, 128) { /// Ok(object) => { /// match object.value_attribute(id) { - /// Ok(a,b) => { + /// Ok((a,b)) => { /// // ... /// Ok(()) /// } @@ -756,6 +783,7 @@ impl TransientObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -783,13 +811,15 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType}; + /// # fn main() -> optee_utee::Result<()> { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { - /// Ok(object1) => + /// Ok(mut object1) => /// { /// match TransientObject::allocate(TransientObjectType::Aes, 256) { /// Ok(object2) => { - /// object1.copy_attribute_from(object2); + /// object1.copy_attribute_from(&object2); /// Ok(()) /// } /// Err(e) => Err(e), @@ -797,6 +827,7 @@ impl TransientObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -828,7 +859,9 @@ impl TransientObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{TransientObject, TransientObjectType}; + /// # fn main() -> optee_utee::Result<()> { /// match TransientObject::allocate(TransientObjectType::Aes, 128) { /// Ok(object) => /// { @@ -837,6 +870,7 @@ impl TransientObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -912,9 +946,11 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; - /// match PersistentObject::open ( + /// match PersistentObject::open( /// ObjectStorageConstants::Private, /// &obj_id, /// DataFlag::ACCESS_READ) { @@ -925,6 +961,7 @@ impl PersistentObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -986,13 +1023,15 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// let mut init_data: [u8; 0] = [0; 0]; - /// match PersistentObject::open ( + /// match PersistentObject::create( /// ObjectStorageConstants::Private, /// &obj_id, - /// DataFlag::ACCESS_READ | DataFlag::ACCESS_WRITE + /// DataFlag::ACCESS_READ | DataFlag::ACCESS_WRITE, /// None, /// &mut init_data) { /// Ok(object) => @@ -1002,6 +1041,7 @@ impl PersistentObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1063,13 +1103,15 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// match PersistentObject::open ( /// ObjectStorageConstants::Private, /// &obj_id, /// DataFlag::ACCESS_READ) { - /// Ok(object) => + /// Ok(mut object) => /// { /// object.close_and_delete()?; /// std::mem::forget(object); @@ -1077,6 +1119,7 @@ impl PersistentObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1108,20 +1151,23 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// let new_obj_id = [2u8;1]; /// match PersistentObject::open ( /// ObjectStorageConstants::Private, /// &obj_id, /// DataFlag::ACCESS_WRITE_META) { - /// Ok(object) => + /// Ok(mut object) => /// { /// object.rename(&new_obj_id)?; /// Ok(()) /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1207,7 +1253,9 @@ impl PersistentObject { /// 2) `count`: The returned value contains the number of bytes read. /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// match PersistentObject::open ( /// ObjectStorageConstants::Private, @@ -1215,12 +1263,13 @@ impl PersistentObject { /// DataFlag::ACCESS_READ) { /// Ok(object) => /// { - /// let read_buf = [0u8;16]; + /// let mut read_buf = [0u8;16]; /// object.read(&mut read_buf)?; /// Ok(()) /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1257,13 +1306,15 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// match PersistentObject::open ( /// ObjectStorageConstants::Private, /// &obj_id, /// DataFlag::ACCESS_WRITE) { - /// Ok(object) => + /// Ok(mut object) => /// { /// let write_buf = [1u8;16]; /// object.write(& write_buf)?; @@ -1271,6 +1322,7 @@ impl PersistentObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1301,7 +1353,9 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// match PersistentObject::open ( /// ObjectStorageConstants::Private, @@ -1314,6 +1368,7 @@ impl PersistentObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors @@ -1345,7 +1400,9 @@ impl PersistentObject { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{PersistentObject, ObjectStorageConstants, DataFlag, Whence}; + /// # fn main() -> optee_utee::Result<()> { /// let obj_id = [1u8;1]; /// match PersistentObject::open( /// ObjectStorageConstants::Private, @@ -1358,6 +1415,7 @@ impl PersistentObject { /// } /// Err(e) => Err(e), /// } + /// # } /// ``` /// /// # Errors diff --git a/optee-utee/src/tee_parameter.rs b/optee-utee/src/tee_parameter.rs index 7c91d19..55a00e6 100644 --- a/optee-utee/src/tee_parameter.rs +++ b/optee-utee/src/tee_parameter.rs @@ -232,7 +232,11 @@ impl<'a> TeeParams<'a> { /// - `with_value_inout`: Sets a value inout parameter. /// /// Example usage: - /// ``` no_run + /// ``` rust,no_run + /// # use optee_utee::{TeeParams, ParamIndex}; + /// # let input_buffer = [0_u8; 0]; + /// # let mut output_buffer = [0_u8; 0]; + /// /// let params = TeeParams::new() /// .with_memref_in(ParamIndex::Arg0, &input_buffer) /// .with_memref_out(ParamIndex::Arg1, &mut output_buffer) @@ -272,7 +276,11 @@ impl<'a> TeeParams<'a> { /// These methods allow the user to set the content at a specific index. /// /// Example usage: - /// ``` no_run + /// ``` rust,no_run + /// # use optee_utee::{TeeParams, ParamIndex}; + /// # let input_buffer = [0_u8; 0]; + /// # let mut output_buffer = [0_u8; 0]; + /// /// let mut params = TeeParams::new(); /// params.set_memref_in(ParamIndex::Arg0, &input_buffer); /// params.set_memref_out(ParamIndex::Arg1, &mut output_buffer); diff --git a/optee-utee/src/time.rs b/optee-utee/src/time.rs index 6d41f87..47d64c7 100644 --- a/optee-utee/src/time.rs +++ b/optee-utee/src/time.rs @@ -44,9 +44,10 @@ impl Time { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::Time; /// let mut time = Time::new(); - /// time.system_time()?; + /// time.system_time(); /// ``` /// /// # Panics @@ -67,8 +68,12 @@ impl Time { /// /// # Example /// - /// ```no_run + /// ``` rust,no_run + /// # use optee_utee::{Time, Result}; + /// # fn main() -> Result<()> { /// Time::wait(1000)?; + /// # Ok(()) + /// # } /// ``` /// /// # Errors @@ -93,11 +98,15 @@ impl Time { /// /// # Example /// - /// ```no_run - /// let mut time = Time()?; - /// time.system_time()?; + /// ``` rust,no_run + /// # use optee_utee::{Time, Result}; + /// # fn main() -> Result<()> { + /// let mut time = Time::new(); + /// time.system_time(); /// time.set_ta_time()?; /// time.ta_time()?; + /// # Ok(()) + /// # } /// ``` /// /// # Errors diff --git a/optee-utee/src/uuid.rs b/optee-utee/src/uuid.rs index 99c4930..909263b 100644 --- a/optee-utee/src/uuid.rs +++ b/optee-utee/src/uuid.rs @@ -32,8 +32,13 @@ impl Uuid { /// /// # Examples /// - /// ``` - /// let uuid = Uuid::parse_str("8abcf200-2450-11e4-abe2-0002a5d5c51b").unwrap(); + /// ``` rust,no_run + /// # use optee_utee::Uuid; + /// # fn main() -> Result<(), uuid::Error> { + /// + /// let uuid = Uuid::parse_str("8abcf200-2450-11e4-abe2-0002a5d5c51b")?; + /// # Ok(()) + /// # } /// ``` pub fn parse_str(input: &str) -> Result<Uuid, uuid_crate::Error> { let uuid = uuid_crate::Uuid::parse_str(input)?; @@ -50,7 +55,8 @@ impl Uuid { /// /// # Examples /// - /// ``` + /// ``` rust,no_run + /// # use optee_utee::Uuid; /// let bytes: [u8; 16] = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62,]; /// let uuid = Uuid::from_bytes(bytes); /// ``` @@ -64,9 +70,13 @@ impl Uuid { /// /// # Examples /// - /// ``` + /// ``` rust,no_run + /// # use optee_utee::Uuid; + /// # fn main() -> Result<(), uuid::Error> { /// let bytes: &[u8; 16] = &[70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62,]; - /// let uuid = Uuid::from_slice(bytes); + /// let uuid = Uuid::from_slice(bytes)?; + /// # Ok(()) + /// # } /// ``` pub fn from_slice(b: &[u8]) -> Result<Uuid, uuid_crate::Error> { let uuid = uuid_crate::Uuid::from_slice(b)?; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
