Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signing: move default backend settings to config/misc.toml
Browse files Browse the repository at this point in the history
yuja committed Dec 24, 2024
1 parent ce6aaca commit 803c113
Showing 4 changed files with 16 additions and 18 deletions.
11 changes: 11 additions & 0 deletions lib/src/config/misc.toml
Original file line number Diff line number Diff line change
@@ -11,6 +11,17 @@ abandon-unreachable-commits = true
# hostname = <host>
# username = <user>

[signing]
backend = "none"

[signing.backends.gpg]
allow-expired-keys = false
program = "gpg"

[signing.backends.ssh]
# allowed-signers = <unknown>
program = "ssh-keygen"

[user]
email = ""
name = ""
11 changes: 2 additions & 9 deletions lib/src/gpg_signing.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ use std::str;
use thiserror::Error;

use crate::config::ConfigGetError;
use crate::config::ConfigGetResultExt as _;
use crate::settings::UserSettings;
use crate::signing::SigStatus;
use crate::signing::SignError;
@@ -147,14 +146,8 @@ impl GpgBackend {
}

pub fn from_settings(settings: &UserSettings) -> Result<Self, ConfigGetError> {
let program = settings
.get_string("signing.backends.gpg.program")
.optional()?
.unwrap_or_else(|| "gpg".into());
let allow_expired_keys = settings
.get_bool("signing.backends.gpg.allow-expired-keys")
.optional()?
.unwrap_or(false);
let program = settings.get_string("signing.backends.gpg.program")?;
let allow_expired_keys = settings.get_bool("signing.backends.gpg.allow-expired-keys")?;
Ok(Self::new(program.into(), allow_expired_keys))
}

7 changes: 2 additions & 5 deletions lib/src/settings.rs
Original file line number Diff line number Diff line change
@@ -257,11 +257,8 @@ impl UserSettings {
// separate from sign_settings as those two are needed in pretty different
// places
pub fn signing_backend(&self) -> Result<Option<String>, ConfigGetError> {
let maybe_backend = self.get_string("signing.backend").optional()?;
match maybe_backend.as_deref() {
Some("none") | None => Ok(None),
Some(_) => Ok(maybe_backend),
}
let backend = self.get_string("signing.backend")?;
Ok((backend != "none").then_some(backend))
}

pub fn sign_settings(&self) -> SignSettings {
5 changes: 1 addition & 4 deletions lib/src/ssh_signing.rs
Original file line number Diff line number Diff line change
@@ -120,10 +120,7 @@ impl SshBackend {
}

pub fn from_settings(settings: &UserSettings) -> Result<Self, ConfigGetError> {
let program = settings
.get_string("signing.backends.ssh.program")
.optional()?
.unwrap_or_else(|| "ssh-keygen".into());
let program = settings.get_string("signing.backends.ssh.program")?;
let allowed_signers = settings
.get_string("signing.backends.ssh.allowed-signers")
.optional()?;

0 comments on commit 803c113

Please sign in to comment.