Alice Wang | 76a36a2 | 2023-07-27 12:11:01 +0000 | [diff] [blame] | 1 | // 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 Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 17 | use super::rkp; |
| 18 | use crate::error::Result; |
Alice Wang | 76a36a2 | 2023-07-27 12:11:01 +0000 | [diff] [blame] | 19 | use alloc::vec::Vec; |
| 20 | use service_vm_comm::{Request, Response}; |
| 21 | |
| 22 | /// Processes a request and returns the corresponding response. |
| 23 | /// This function serves as the entry point for the request processing |
| 24 | /// module. |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 25 | pub fn process_request(request: Request) -> Result<Response> { |
| 26 | let response = match request { |
Alice Wang | 76a36a2 | 2023-07-27 12:11:01 +0000 | [diff] [blame] | 27 | Request::Reverse(v) => Response::Reverse(reverse(v)), |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 28 | Request::GenerateEcdsaP256KeyPair => { |
| 29 | let res = rkp::generate_ecdsa_p256_key_pair()?; |
| 30 | Response::GenerateEcdsaP256KeyPair(res) |
| 31 | } |
Alice Wang | 464e473 | 2023-09-06 12:25:22 +0000 | [diff] [blame^] | 32 | Request::GenerateCertificateRequest(p) => { |
| 33 | let res = rkp::generate_certificate_request(p)?; |
| 34 | Response::GenerateCertificateRequest(res) |
| 35 | } |
Alice Wang | 33f4cae | 2023-09-05 09:27:39 +0000 | [diff] [blame] | 36 | }; |
| 37 | Ok(response) |
Alice Wang | 76a36a2 | 2023-07-27 12:11:01 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | fn reverse(payload: Vec<u8>) -> Vec<u8> { |
| 41 | payload.into_iter().rev().collect() |
| 42 | } |