blob: 59a7aed7b5249d3806e574cf4fd71e35e9aa0389 [file] [log] [blame]
Alice Wang76a36a22023-07-27 12:11:01 +00001// Copyright 2023, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This module contains the main API for the request processing module.
16
Alice Wang33f4cae2023-09-05 09:27:39 +000017use super::rkp;
18use crate::error::Result;
Alice Wang76a36a22023-07-27 12:11:01 +000019use alloc::vec::Vec;
Alice Wang77639bf2023-09-21 06:57:12 +000020use diced_open_dice::DiceArtifacts;
Alice Wang76a36a22023-07-27 12:11:01 +000021use service_vm_comm::{Request, Response};
22
23/// Processes a request and returns the corresponding response.
24/// This function serves as the entry point for the request processing
25/// module.
Alice Wang77639bf2023-09-21 06:57:12 +000026pub fn process_request(request: Request, dice_artifacts: &dyn DiceArtifacts) -> Result<Response> {
Alice Wang33f4cae2023-09-05 09:27:39 +000027 let response = match request {
Alice Wang76a36a22023-07-27 12:11:01 +000028 Request::Reverse(v) => Response::Reverse(reverse(v)),
Alice Wang77639bf2023-09-21 06:57:12 +000029 Request::GenerateEcdsaP256KeyPair => rkp::generate_ecdsa_p256_key_pair(dice_artifacts)
Alice Wangd80e99e2023-09-15 13:26:01 +000030 .map_or_else(Response::Err, Response::GenerateEcdsaP256KeyPair),
Alice Wang77639bf2023-09-21 06:57:12 +000031 Request::GenerateCertificateRequest(p) => {
32 rkp::generate_certificate_request(p, dice_artifacts)
33 .map_or_else(Response::Err, Response::GenerateCertificateRequest)
34 }
Alice Wang33f4cae2023-09-05 09:27:39 +000035 };
36 Ok(response)
Alice Wang76a36a22023-07-27 12:11:01 +000037}
38
39fn reverse(payload: Vec<u8>) -> Vec<u8> {
40 payload.into_iter().rev().collect()
41}