DTPM: upload files as stream and directory support #2
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -204,7 +204,6 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" | |||||||
| name = "detee-shared" | name = "detee-shared" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "base64", |  | ||||||
|  "bincode", |  "bincode", | ||||||
|  "prost", |  "prost", | ||||||
|  "serde", |  "serde", | ||||||
|  | |||||||
| @ -4,7 +4,6 @@ version = "0.1.0" | |||||||
| edition = "2021" | edition = "2021" | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| base64 = "0.22.1" |  | ||||||
| prost = "0.13.4" | prost = "0.13.4" | ||||||
| serde = { version = "1.0.216", features = ["derive"] } | serde = { version = "1.0.216", features = ["derive"] } | ||||||
| serde_yaml = "0.9.34" | serde_yaml = "0.9.34" | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ message DtpmConfigData { | |||||||
| message FileEntry { | message FileEntry { | ||||||
|   string path = 1; |   string path = 1; | ||||||
|   oneof content { |   oneof content { | ||||||
|     string data = 2; |     bytes data = 2; | ||||||
|     bytes archive = 3; |     bytes archive = 3; | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| use crate::sgx::pb::dtpm_proto; | use crate::sgx::pb::dtpm_proto; | ||||||
| use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; | use bincode::{Decode, Encode}; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use std::path::Path; | use std::path::Path; | ||||||
| use tar::{Archive, Builder}; | 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 struct FileEntry { | ||||||
|     pub path: String, |     pub path: String, | ||||||
|     pub content: FileContent, |     pub content: FileContent, | ||||||
| @ -51,8 +51,10 @@ impl From<dtpm_proto::FileEntry> for FileEntry { | |||||||
|             path: pb_val.path, |             path: pb_val.path, | ||||||
|             content: match pb_val.content { |             content: match pb_val.content { | ||||||
|                 Some(dtpm_proto::file_entry::Content::Data(data)) => FileContent::Data(data), |                 Some(dtpm_proto::file_entry::Content::Data(data)) => FileContent::Data(data), | ||||||
|                 Some(dtpm_proto::file_entry::Content::Archive(_)) => todo!(), |                 Some(dtpm_proto::file_entry::Content::Archive(archive_data)) => { | ||||||
|                 None => FileContent::Data("".to_string()), |                     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 { | pub enum FileContent { | ||||||
|     #[serde(rename = "path")] |     #[serde(rename = "path")] | ||||||
|     Path(String), |     Path(String), | ||||||
|     #[serde(rename = "data")] |     #[serde(rename = "data")] | ||||||
|     Data(String), |     Data(Vec<u8>), | ||||||
|     #[serde(rename = "directory")] |     #[serde(rename = "directory")] | ||||||
|     Archive(Vec<u8>), |     Archive(Vec<u8>), | ||||||
| } | } | ||||||
| @ -212,8 +214,7 @@ impl DtpmConfig { | |||||||
|                 } else { |                 } else { | ||||||
|                     let content = std::fs::read(content_path) |                     let content = std::fs::read(content_path) | ||||||
|                         .unwrap_or_else(|_| panic!("Unable to read file {content_path}")); |                         .unwrap_or_else(|_| panic!("Unable to read file {content_path}")); | ||||||
|                     let encoded = BASE64.encode(content); |                     file_entry.content = FileContent::Data(content); | ||||||
|                     file_entry.content = FileContent::Data(encoded); |  | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user