fn update_size_from_raw()

in optee-utee/src/tee_parameter.rs [153:183]


    fn update_size_from_raw(&mut self, raw_param: &raw::TEE_Param) -> Result<()> {
        match &mut self.content {
            ParamContent::MemrefOutput { buffer, written } => {
                // SAFETY:
                // The caller must ensure this param is of memref type and properly initialized.
                // This is enforced by the variant match on `ParamContent::MemrefOutput`.
                // Accessing `raw_param.memref.size` is safe under these assumptions.
                let new_size = unsafe { raw_param.memref.size };
                if new_size > (*buffer).len() {
                    return Err(Error::new(ErrorKind::BadParameters));
                }
                *written = new_size;
                Ok(())
            }
            ParamContent::MemrefInout { buffer, written } => {
                // SAFETY:
                // The caller must ensure this param is of memref type and properly initialized.
                // This is enforced by the variant match on `ParamContent::MemrefOutput`.
                // Accessing `raw_param.memref.size` is safe under these assumptions.
                let new_size = unsafe { raw_param.memref.size };
                if new_size > (*buffer).len() {
                    return Err(Error::new(ErrorKind::BadParameters));
                }
                *written = new_size;
                Ok(())
            }
            _ => {
                return Err(Error::new(ErrorKind::BadFormat));
            }
        }
    }