Skip to content
Snippets Groups Projects
Commit de10fa7b authored by Sebastian Neuser's avatar Sebastian Neuser
Browse files

fix(lint): Follow remaining clippy suggestions

parent 3933fcb2
No related branches found
No related tags found
1 merge request!2CI pipeline
......@@ -283,7 +283,7 @@ pub fn interpret(command: &Command, cached_keys: &mut Vec<recipient::SshKeypair>
}
}
pub fn interpret_input(input: &String, cached_keys: &mut Vec<recipient::SshKeypair>) -> Vec<String> {
pub fn interpret_input(input: &str, cached_keys: &mut Vec<recipient::SshKeypair>) -> Vec<String> {
let mut tokens: Vec<String> = split(input).unwrap();
tokens.insert(0, String::from("trespass"));
......
......@@ -16,7 +16,7 @@ fn handle_client(mut stream: UnixStream, cached_keys: &mut Vec<SshKeypair>) -> R
stream.read_to_string(&mut incoming)?;
println!("Executing {}", incoming);
for line in incoming.lines() {
for output in cli::interpret_input(&line.to_owned(), cached_keys) {
for output in cli::interpret_input(line, cached_keys) {
stream.write_all(format!("{}\n", output).as_bytes())?;
}
}
......
......@@ -27,7 +27,7 @@ pub struct SshKeypair {
}
impl SshKeypair {
pub fn from(key: &String) -> Self {
pub fn from(key: &str) -> Self {
let mut tokens = key.split(' ');
let mut result = SshKeypair {
name: None,
......@@ -82,7 +82,7 @@ fn list_recipients(path: &PathBuf, verbose: bool) -> Result<Vec<SshKeypair>> {
}
pub fn add(path: &PathBuf, pubkey: &String, cached_keys: &mut Vec<SshKeypair>)
pub fn add(path: &PathBuf, pubkey: &str, cached_keys: &mut Vec<SshKeypair>)
-> Result<Vec<String>> {
let mut results = vec![];
let new_key = SshKeypair::from(pubkey);
......@@ -124,7 +124,7 @@ pub fn print(path: &PathBuf) -> Result<Vec<String>> {
return Ok(list_recipients(path, true)?.iter().map(|key| format!("{}", key)).collect())
}
pub fn remove(path: &PathBuf, pubkey: &String, cached_keys: &mut Vec<SshKeypair>)
pub fn remove(path: &PathBuf, pubkey: &str, cached_keys: &mut Vec<SshKeypair>)
-> Result<Vec<String>> {
let mut results = vec![];
let obsolete_key = SshKeypair::from(pubkey);
......
use std::process::Command;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use anyhow::{Result, anyhow};
use gix::progress::Discard;
......@@ -22,8 +22,8 @@ fn execute_command(args: &Vec<&str>, repo: Option<&PathBuf>) -> Result<Vec<Strin
return Ok(output.lines().map(String::from).collect());
}
fn resolve_submodule_path(path: &PathBuf) -> Result<(String, PathBuf)> {
let mut file_path = path.clone();
fn resolve_submodule_path(path: &Path) -> Result<(String, PathBuf)> {
let mut file_path = path.to_path_buf();
let mut repo_path = root_path();
if let Some(submodules) = gix::open(root_path())?.submodules()? {
for submodule in submodules {
......@@ -57,7 +57,7 @@ fn update_submodule(path: PathBuf) -> Result<()> {
// Public API
//
pub fn add(path: &PathBuf, url: &String) -> Result<Vec<String>> {
pub fn add(path: &Path, url: &String) -> Result<Vec<String>> {
let mut output = vec![];
// This appears to be unsupported - maybe check if it works later or implement it there:
// output.append(&mut execute_command(vec!["submodule", "add", url, path.to_str().unwrap()])?);
......@@ -111,7 +111,7 @@ pub fn path(path: &PathBuf) -> PathBuf {
root_path().join(path)
}
pub fn relative_path(path: &PathBuf) -> PathBuf {
pub fn relative_path(path: &Path) -> PathBuf {
return path.strip_prefix(root_path()).unwrap().to_path_buf();
}
......@@ -136,7 +136,7 @@ pub fn sync() -> Result<Vec<String>> {
Ok(output)
}
pub fn update_file(path: &PathBuf, message: String) -> Result<Vec<String>> {
pub fn update_file(path: &Path, message: String) -> Result<Vec<String>> {
let (file_path, repo_path) = resolve_submodule_path(path)?;
execute_command(&vec!["stage", &file_path], Some(&repo_path))?;
execute_command(&vec!["commit", "-m", message.as_str()], Some(&repo_path))?;
......
use std::env::var;
use std::fs::{File, read, create_dir_all, read_to_string, write};
use std::io::{BufReader, Read, Seek, SeekFrom, Write};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
use std::thread::spawn;
......@@ -58,8 +58,8 @@ fn copy_to_clipboard(target: LinuxClipboardKind, secret: String) -> Result<()> {
Ok(())
}
fn decrypt(path: &PathBuf, identities: &Vec<impl Identity>) -> Result<String> {
let encrypted = read(repository::path(path))?;
fn decrypt(path: &Path, identities: &[impl Identity]) -> Result<String> {
let encrypted = read(repository::path(&path.to_path_buf()))?;
let decryptor = match Decryptor::new(&encrypted[..])? {
Decryptor::Recipients(d) => d,
_ => unreachable!(),
......@@ -90,7 +90,7 @@ fn encrypt(path: &PathBuf, secret: &String, recipient_keys: &Vec<SshKeypair>, ms
Ok(())
}
fn fill_in_recipients(path: &PathBuf, cached_keys: &mut Vec<SshKeypair>) -> Result<()> {
fn fill_in_recipients(path: &Path, cached_keys: &mut Vec<SshKeypair>) -> Result<()> {
for rcpt in list_recipients(path)? {
let found = cached_keys.iter().find(|key|
rcpt.algorithm == key.algorithm && rcpt.pubkey == key.pubkey
......@@ -102,7 +102,7 @@ fn fill_in_recipients(path: &PathBuf, cached_keys: &mut Vec<SshKeypair>) -> Resu
Ok(())
}
fn get_ssh_identities(recipients: &mut Vec<SshKeypair>, limit: usize) -> Result<Vec<impl Identity>> {
fn get_ssh_identities(recipients: &mut [SshKeypair], limit: usize) -> Result<Vec<impl Identity>> {
let mut identities = vec![];
let pattern = config::get().ssh_path().join("id_ed25519*.pub");
for candidate in glob(pattern.to_str().unwrap()).expect("Could not find SSH keys") {
......@@ -146,12 +146,12 @@ fn get_ssh_identities(recipients: &mut Vec<SshKeypair>, limit: usize) -> Result<
Ok(identities)
}
fn list_recipients(path: &PathBuf) -> Result<Vec<SshKeypair>> {
fn list_recipients(path: &Path) -> Result<Vec<SshKeypair>> {
let collection = path.parent().unwrap().to_path_buf();
recipient::list(&collection)
}
fn load(path: &PathBuf, cached_keys: &mut Vec<SshKeypair>) -> Result<String> {
fn load(path: &Path, cached_keys: &mut Vec<SshKeypair>) -> Result<String> {
let num = if cached_keys.is_empty() { 1 } else { 0 };
fill_in_recipients(path, cached_keys)?;
let identities = get_ssh_identities(cached_keys, num)?;
......@@ -224,7 +224,7 @@ pub fn add(path: &PathBuf,
Ok(vec![])
}
pub fn clip(path: &PathBuf, both: &bool, part: &Option<String>, cached_keys: &mut Vec<SshKeypair>)
pub fn clip(path: &Path, both: &bool, part: &Option<String>, cached_keys: &mut Vec<SshKeypair>)
-> Result<Vec<String>> {
let mut feedback = vec![];
let mut secret = load(path, cached_keys)?;
......@@ -331,7 +331,7 @@ pub fn reencrypt(path: &PathBuf, recipients: Vec<SshKeypair>, cached_keys: &mut
Ok(())
}
pub fn show(path: &PathBuf, clip: &bool, cached_keys: &mut Vec<SshKeypair>) -> Result<Vec<String>> {
pub fn show(path: &Path, clip: &bool, cached_keys: &mut Vec<SshKeypair>) -> Result<Vec<String>> {
let secret = load(path, cached_keys)?;
if *clip {
copy_to_clipboard(LinuxClipboardKind::Clipboard, secret.clone())?;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment