in projects/web3/eth_wallet/host/src/main.rs [29:58]
fn invoke_command(command: proto::Command, input: &[u8]) -> optee_teec::Result<Vec<u8>> {
let mut ctx = Context::new()?;
let uuid = Uuid::parse_str(proto::UUID)
.map_err(|_| optee_teec::Error::new(optee_teec::ErrorKind::ItemNotFound))?;
let mut session = ctx.open_session(uuid)?;
println!("CA: command: {:?}", command);
// input buffer
let p0 = ParamTmpRef::new_input(input);
// output buffer
let mut output = vec![0u8; OUTPUT_MAX_SIZE];
let p1 = ParamTmpRef::new_output(output.as_mut_slice());
// output buffer size
let p2 = ParamValue::new(0, 0, ParamType::ValueInout);
let mut operation = Operation::new(0, p0, p1, p2, ParamNone);
match session.invoke_command(command as u32, &mut operation) {
Ok(()) => {
println!("CA: invoke_command success");
let output_len = operation.parameters().2.a() as usize;
Ok(output[..output_len].to_vec())
}
Err(e) => {
let output_len = operation.parameters().2.a() as usize;
let err_message = String::from_utf8_lossy(&output[..output_len]);
println!("CA: invoke_command failed: {:?}", err_message);
Err(e)
}
}
}