-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from benjamin-747/main
add dependency import rules and format code
- Loading branch information
Showing
38 changed files
with
349 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
use clap::{arg, Args, Subcommand}; | ||
|
||
use super::{ | ||
use crate::vault::{ | ||
crypt::{decrypt_blob, encrypt_blob, generate_key_full}, | ||
init_rv_core, | ||
pgp_key::{delete_key, list_keys}, | ||
|
@@ -42,6 +42,13 @@ enum VaultMode { | |
}, | ||
} | ||
|
||
/// Handles different modes for interacting with the Rusty Vault. | ||
/// | ||
/// It initializes the Rusty Vault Core and performs operations based on the specified mode. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `args` - A VaultArgs enum representing different modes of operation. | ||
pub fn handle(args: VaultArgs) { | ||
let (core, token) = init_rv_core(); | ||
// Match the mode with different functions | ||
|
@@ -79,7 +86,7 @@ pub fn handle(args: VaultArgs) { | |
#[cfg(test)] | ||
mod tests { | ||
|
||
use std::sync::{RwLock, Arc}; | ||
use std::sync::{Arc, RwLock}; | ||
|
||
use rusty_vault::core::Core; | ||
|
||
|
@@ -91,14 +98,14 @@ mod tests { | |
|
||
// Define a test function for generate-key-full mode | ||
// #[test] | ||
fn test_generate_key_full(core: Arc<RwLock<Core>>, token : &str) { | ||
fn test_generate_key_full(core: Arc<RwLock<Core>>, token: &str) { | ||
// generate a full key | ||
let _ = generate_key_full("Craft <[email protected]>", "secret/craft", core, token); | ||
} | ||
|
||
// Define a test function for encrypt mode | ||
// #[test] | ||
fn test_encrypt(core: Arc<RwLock<Core>>, token : &str) { | ||
fn test_encrypt(core: Arc<RwLock<Core>>, token: &str) { | ||
// generate key to crypt | ||
let _ = generate_key_full("User2 <[email protected]>", "secret/sci", core, token).unwrap(); | ||
// Create and run a new process to execute the encrypt_blob function | ||
|
@@ -131,7 +138,7 @@ mod tests { | |
|
||
// Define a test function for decrypt mode | ||
// #[test] | ||
fn test_decrypt(core: Arc<RwLock<Core>>, token : &str) { | ||
fn test_decrypt(core: Arc<RwLock<Core>>, token: &str) { | ||
// Generate a key pair for testing | ||
let _ = generate_key_full( | ||
"User3 <[email protected]>", | ||
|
@@ -205,16 +212,21 @@ mod tests { | |
|
||
// Define a test function for list-keys mode | ||
// #[test] | ||
fn test_list_keys(core: Arc<RwLock<Core>>, token : &str) { | ||
fn test_list_keys(core: Arc<RwLock<Core>>, token: &str) { | ||
let actual = list_keys("secret/", core, token).unwrap(); | ||
assert!(!actual.is_empty()); | ||
// Check if the output contains the expected key information | ||
} | ||
|
||
// Define a test function for delete-key mode | ||
// #[test] | ||
fn test_delete_key(core: Arc<RwLock<Core>>, token : &str) { | ||
let _ = generate_key_full("Delete <[email protected]>", "secret/delete", core.clone(), token); | ||
fn test_delete_key(core: Arc<RwLock<Core>>, token: &str) { | ||
let _ = generate_key_full( | ||
"Delete <[email protected]>", | ||
"secret/delete", | ||
core.clone(), | ||
token, | ||
); | ||
let _ = delete_key("secret/delete", core.clone(), token); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,16 @@ use std::{ | |
sync::{Arc, RwLock}, | ||
}; | ||
|
||
use anyhow::Ok; | ||
use pgp_key::{decrypt_message, encrypt_message, generate_key_pair}; | ||
use pgp_key::{ | ||
decrypt_message, delete_key, encrypt_message, generate_key_pair, list_keys, KeyPair, | ||
}; | ||
use rusty_vault::{ | ||
core::Core, | ||
logical::{Operation, Request}, | ||
}; | ||
use serde_json::json; | ||
|
||
use crate::vault::pgp_key::{self, delete_key, list_keys, KeyPair}; | ||
use crate::vault::pgp_key; | ||
|
||
// the trait and impl for KeyPair is a preparation for crate Tongsuo. | ||
// a trait for key | ||
|
@@ -58,7 +59,6 @@ impl Key for KeyPair { | |
} | ||
} | ||
|
||
|
||
// Generate full key with pubkey, seckey, primary id. | ||
// Arguments: primary_id, as &str, it should be written as "User <[email protected]>"; key_name, git-craft will keep ur key file as key_namepub.asc | ||
pub fn generate_key_full( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pub mod object_detail; | ||
pub mod query; | ||
pub mod query; |
Oops, something went wrong.