From 20ba749427ac4453a06bc8a8ef3fb8f0ec6bb592 Mon Sep 17 00:00:00 2001 From: Noor Date: Tue, 15 Apr 2025 15:04:37 +0000 Subject: [PATCH] refactor: remove base64 file encoding read and send file as bytes update FileEntry grpc type to bytes fixed FileEntry From implementation --- Cargo.lock | 1 - Cargo.toml | 1 - proto/sgx/dtpm.proto | 2 +- src/sgx/types/dtpm.rs | 17 +++++++++-------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7db0592..d2283a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,7 +204,6 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "detee-shared" version = "0.1.0" dependencies = [ - "base64", "bincode", "prost", "serde", diff --git a/Cargo.toml b/Cargo.toml index 379a588..f0e9d0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -base64 = "0.22.1" prost = "0.13.4" serde = { version = "1.0.216", features = ["derive"] } serde_yaml = "0.9.34" diff --git a/proto/sgx/dtpm.proto b/proto/sgx/dtpm.proto index 084a90f..45af42d 100644 --- a/proto/sgx/dtpm.proto +++ b/proto/sgx/dtpm.proto @@ -12,7 +12,7 @@ message DtpmConfigData { message FileEntry { string path = 1; oneof content { - string data = 2; + bytes data = 2; bytes archive = 3; } } diff --git a/src/sgx/types/dtpm.rs b/src/sgx/types/dtpm.rs index a50e95d..e272805 100644 --- a/src/sgx/types/dtpm.rs +++ b/src/sgx/types/dtpm.rs @@ -1,5 +1,5 @@ use crate::sgx::pb::dtpm_proto; -use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; +use bincode::{Decode, Encode}; use serde::{Deserialize, Serialize}; use std::path::Path; use tar::{Archive, Builder}; @@ -39,7 +39,7 @@ impl From for dtpm_proto::DtpmConfigData { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] pub struct FileEntry { pub path: String, pub content: FileContent, @@ -51,8 +51,10 @@ impl From for FileEntry { path: pb_val.path, content: match pb_val.content { Some(dtpm_proto::file_entry::Content::Data(data)) => FileContent::Data(data), - Some(dtpm_proto::file_entry::Content::Archive(_)) => todo!(), - None => FileContent::Data("".to_string()), + Some(dtpm_proto::file_entry::Content::Archive(archive_data)) => { + FileContent::Archive(archive_data) + } + _ => FileContent::Data(vec![]), }, } } @@ -72,12 +74,12 @@ impl From for dtpm_proto::FileEntry { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)] pub enum FileContent { #[serde(rename = "path")] Path(String), #[serde(rename = "data")] - Data(String), + Data(Vec), #[serde(rename = "directory")] Archive(Vec), } @@ -212,8 +214,7 @@ impl DtpmConfig { } else { let content = std::fs::read(content_path) .unwrap_or_else(|_| panic!("Unable to read file {content_path}")); - let encoded = BASE64.encode(content); - file_entry.content = FileContent::Data(encoded); + file_entry.content = FileContent::Data(content); } } }