refactor: remove base64 file encoding
read and send file as bytes update FileEntry grpc type to bytes fixed FileEntry From implementation
This commit is contained in:
parent
64d7a1c9e1
commit
20ba749427
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -204,7 +204,6 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
name = "detee-shared"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bincode",
|
||||
"prost",
|
||||
"serde",
|
||||
|
@ -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"
|
||||
|
@ -12,7 +12,7 @@ message DtpmConfigData {
|
||||
message FileEntry {
|
||||
string path = 1;
|
||||
oneof content {
|
||||
string data = 2;
|
||||
bytes data = 2;
|
||||
bytes archive = 3;
|
||||
}
|
||||
}
|
||||
|
@ -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<DtpmConfig> 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<dtpm_proto::FileEntry> 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<FileEntry> 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<u8>),
|
||||
#[serde(rename = "directory")]
|
||||
Archive(Vec<u8>),
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user