Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit of a refactor #1

Merged
merged 10 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use AsRef<Path> instead of PathBuf
  • Loading branch information
Speykious committed Oct 24, 2022
commit f9eb5c2e605e39fbb3d0290811d2843a363413d4
8 changes: 5 additions & 3 deletions src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{Read, Write},
path::PathBuf,
path::Path,
result::Result,
};

Expand Down Expand Up @@ -36,7 +36,7 @@ impl Keys {
}
}

pub fn save_keypair(&self, filepath: PathBuf) {
pub fn save_keypair<P: AsRef<Path>>(&self, filepath: P) {
// Encode the keypair with bincode and write it to disk.
let encoded_keypair = bincode::serialize(&self).expect("Failed to serialise keyfile");
let mut keyfile =
Expand All @@ -46,7 +46,9 @@ impl Keys {
.expect("Failed to write the key to disk");
}

pub fn from(mut filepath: PathBuf) -> Self {
pub fn from<P: AsRef<Path>>(filepath: P) -> Self {
let mut filepath = filepath.as_ref().to_owned();

// Read the keypair, decode it with bincode and return a keypair object
if !filepath.ends_with(".sfkp") {
filepath.push(".sfkp");
Expand Down
4 changes: 2 additions & 2 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub struct FileData {
}

impl FileData {
fn new(file_path: PathBuf, len: usize, data: Vec<u8>, signature: Vec<u8>) -> Self {
fn new<P: AsRef<Path>>(file_path: P, len: usize, data: Vec<u8>, signature: Vec<u8>) -> Self {
FileData {
path: file_path,
path: file_path.as_ref().to_owned(),
len,
data,
signature,
Expand Down