Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1N committed Mar 20, 2024
1 parent 0a928f6 commit adcc38d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ cargo run --release --example sign_file assets\memflow_coredump.x86_64.dll ec-se


$env:RUST_LOG="info"
$env:MEMFLOW_PUBLIC_KEY="ec-secp256k1-pub-key.pem"
$env:MEMFLOW_PUBLIC_KEY_FILE="ec-secp256k1-pub-key.pem"
9 changes: 9 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub type ResponseResult<T> = std::result::Result<T, (axum::http::StatusCode, Str
/// Library errors
#[derive(thiserror::Error, Debug, Clone, PartialEq)]
pub enum Error {
// Basic errors
#[error("IO error: {0}")]
IO(String),
#[error("Parse error: {0}")]
Expand All @@ -17,6 +18,8 @@ pub enum Error {
AlreadyExists(String),
#[error("Not implemented: {0}")]
NotImplemented(String),

// External crate error forwards
#[error("Goblin error: {0}")]
Goblin(String),
#[error("Signature error: {0}")]
Expand Down Expand Up @@ -58,3 +61,9 @@ impl From<std::num::ParseIntError> for Error {
Error::Parse(err.to_string())
}
}

impl From<serde_json::error::Error> for Error {
fn from(err: serde_json::error::Error) -> Self {
Error::Parse(err.to_string())
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn main() {
let mut storage = Storage::new(&root).expect("unable to create storage handler");

// use public key file if specified
if let Ok(public_key_file) = std::env::var("MEMFLOW_PUBLIC_KEY") {
if let Ok(public_key_file) = std::env::var("MEMFLOW_PUBLIC_KEY_FILE") {
let signature_verifier =
SignatureVerifier::new(public_key_file).expect("unable to load public key file");
storage = storage.with_signature_verifier(signature_verifier);
Expand Down
15 changes: 2 additions & 13 deletions src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ use pki::SignatureVerifier;
/// Metadata attached to each file
#[derive(Debug, Serialize, Deserialize)]
pub struct PluginMetadata {
// pub plugin: String,
// // TODO: plugin type
// pub tag: String,
// TODO: do we need more?
/// The sha256sum of the binary file
pub digest: String,

/// File signature of this binary
pub signature: String,

/// Timestamp at which the file was added
pub created_at: NaiveDateTime,

/// Timestamp at when this file was added
// TODO: can we simply use file timestamp?

/// The plugin descriptor
pub descriptors: Vec<PluginDescriptor>,
}
Expand All @@ -53,13 +43,12 @@ impl Storage {
// TODO: create path if not exists
let mut database = PluginDatabase::new();

let paths = std::fs::read_dir(&root).unwrap();
let paths = std::fs::read_dir(&root)?;
for path in paths.filter_map(|p| p.ok()) {
if let Some(extension) = path.path().extension() {
if extension.to_str().unwrap_or_default() == "meta" {
let metadata: PluginMetadata =
serde_json::from_str(&std::fs::read_to_string(path.path()).unwrap())
.unwrap();
serde_json::from_str(&std::fs::read_to_string(path.path())?)?;
database.insert_all(&metadata)?;
}
}
Expand Down

0 comments on commit adcc38d

Please sign in to comment.