[rialto] Refactor process_request API return type
To facilitate the separation of the requests module into a
standalone library, thereby enabling unit testing of the
request processing functionality.
Bug: 301068421
Test: atest rialto_test
Change-Id: I0e5b55decf0a431a5dabef34d257212d93d999e4
diff --git a/rialto/src/main.rs b/rialto/src/main.rs
index 43215a0..ebc16a9 100644
--- a/rialto/src/main.rs
+++ b/rialto/src/main.rs
@@ -28,6 +28,7 @@
use crate::communication::VsockStream;
use crate::error::{Error, Result};
use crate::fdt::read_dice_range_from;
+use crate::requests::process_request;
use alloc::boxed::Box;
use bssl_ffi::CRYPTO_library_init;
use ciborium_io::Write;
@@ -178,7 +179,7 @@
let mut vsock_stream = VsockStream::new(socket_device, host_addr())?;
while let ServiceVmRequest::Process(req) = vsock_stream.read_request()? {
- let response = requests::process_request(req, bcc_handover.as_ref())?;
+ let response = process_request(req, bcc_handover.as_ref());
vsock_stream.write_response(&response)?;
vsock_stream.flush()?;
}
diff --git a/rialto/src/requests/api.rs b/rialto/src/requests/api.rs
index 59a7aed..ca60f85 100644
--- a/rialto/src/requests/api.rs
+++ b/rialto/src/requests/api.rs
@@ -15,7 +15,6 @@
//! This module contains the main API for the request processing module.
use super::rkp;
-use crate::error::Result;
use alloc::vec::Vec;
use diced_open_dice::DiceArtifacts;
use service_vm_comm::{Request, Response};
@@ -23,8 +22,8 @@
/// Processes a request and returns the corresponding response.
/// This function serves as the entry point for the request processing
/// module.
-pub fn process_request(request: Request, dice_artifacts: &dyn DiceArtifacts) -> Result<Response> {
- let response = match request {
+pub fn process_request(request: Request, dice_artifacts: &dyn DiceArtifacts) -> Response {
+ match request {
Request::Reverse(v) => Response::Reverse(reverse(v)),
Request::GenerateEcdsaP256KeyPair => rkp::generate_ecdsa_p256_key_pair(dice_artifacts)
.map_or_else(Response::Err, Response::GenerateEcdsaP256KeyPair),
@@ -32,8 +31,7 @@
rkp::generate_certificate_request(p, dice_artifacts)
.map_or_else(Response::Err, Response::GenerateCertificateRequest)
}
- };
- Ok(response)
+ }
}
fn reverse(payload: Vec<u8>) -> Vec<u8> {