Harness the power of signify(1) to sign arbitrary git objects
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add util to open git repo

+13 -3
+1 -1
src/raw/sign.rs
··· 10 10 11 11 /// Execute the `sign` command. 12 12 pub fn command(key_path: PathBuf, rev: String) -> Result<()> { 13 - let repo = Repository::open(".").context("Failed to open git repository")?; 13 + let repo = utils::open_repository()?; 14 14 let secret_key = utils::get_secret_key(key_path)?; 15 15 let tree_oid = sign(&repo, &secret_key, &rev)?; 16 16 println!("{tree_oid}");
+1 -1
src/raw/verify.rs
··· 10 10 11 11 /// Execute the `verify` command. 12 12 pub fn command(key_path: PathBuf, recover: bool, tree_rev: String) -> Result<()> { 13 - let repo = Repository::open(".").context("Failed to open git repository")?; 13 + let repo = utils::open_repository()?; 14 14 let public_key = utils::get_public_key(key_path)?; 15 15 let recovered_oid = verify(&repo, &public_key, &tree_rev, recover)?; 16 16 if let Some(recovered_oid) = recovered_oid {
+11 -1
src/utils.rs
··· 5 5 use std::path::PathBuf; 6 6 7 7 use anyhow::{Context, Result}; 8 - use git2::{ObjectType, Oid}; 8 + use git2::{ObjectType, Oid, Repository, RepositoryOpenFlags}; 9 9 use libsignify::{Codeable, PrivateKey, PublicKey}; 10 10 use zeroize::Zeroizing; 11 11 ··· 73 73 74 74 Ok(secret_key) 75 75 } 76 + 77 + /// Try to find and open a git repository. 78 + pub fn open_repository() -> Result<Repository> { 79 + Repository::open_ext( 80 + ".", 81 + RepositoryOpenFlags::empty(), 82 + &[] as &[&std::ffi::OsStr], 83 + ) 84 + .context("Failed to open git repository") 85 + }