DemesneGH commented on code in PR #278:
URL:
https://github.com/apache/teaclave-trustzone-sdk/pull/278#discussion_r2802019037
##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -68,16 +68,17 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) ->
Result<()> {
// Ensure the buffer is large enough to hold the serialized data.
let len = bytes.len();
- if len > buffer.len() {
+ if len > buffer.capacity() {
trace_println!("Buffer too small, cannot copy all bytes");
+ p.request_more_capacity(len).expect("infallible");
Review Comment:
Suggestions on `NotBiggerThanCapacityErr`:
- the name is a bit confusing, how about `ShortBufferErr` or any other you
prefer
- It should be converted into `ErrorKind::ShortBuffer`, as TA notifies CA
that it needs more capacity
Suggestions on `request_more_capacity()`, how about changing to:
```
pub fn ensure_capacity(&mut self, required_len: usize) -> Result<(),
ShortBufferErr> {
if required_len > self.capacity {
let memref = unsafe { self.raw.as_mut() };
memref.size = required_len;
return Err(ShortBufferErr);
}
Ok(())
}
```
In the example:
```
let len = bytes.len();
// no need to manually check the len
p.ensure_capacity(len)?
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]