build: only sign if a gpg key able to sign is present
Some checks failed
CI / build (push) Failing after 1m50s
Some checks failed
CI / build (push) Failing after 1m50s
This commit is contained in:
32
src/utils/gpg.rs
Normal file
32
src/utils/gpg.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use gpgme::{Context, Protocol};
|
||||
|
||||
/// Check if a GPG key matching 'email' exists
|
||||
/// Returns the key ID if found, None otherwise
|
||||
pub fn find_signing_key_for_email(
|
||||
email: &str,
|
||||
) -> Result<Option<String>, Box<dyn std::error::Error>> {
|
||||
// Create a new GPG context
|
||||
let mut ctx = Context::from_protocol(Protocol::OpenPgp)?;
|
||||
|
||||
// List all secret keys
|
||||
let keys = ctx.secret_keys()?;
|
||||
|
||||
// Find a key that matches the email and can sign
|
||||
for key_result in keys {
|
||||
let key = key_result?;
|
||||
// Check if the key has signing capability
|
||||
if key.can_sign() {
|
||||
// Check user IDs for email match
|
||||
for user_id in key.user_ids() {
|
||||
if let Ok(userid_email) = user_id.email()
|
||||
&& userid_email.eq_ignore_ascii_case(email)
|
||||
&& let Ok(fingerprint) = key.fingerprint()
|
||||
{
|
||||
return Ok(Some(fingerprint.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
Reference in New Issue
Block a user