Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename SettingValue to Setting #286

Merged
merged 1 commit into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub mod piv;
mod policy;
pub mod reader;
mod serialization;
mod settings;
mod setting;
mod transaction;
mod yubikey;

Expand All @@ -167,7 +167,7 @@ pub use crate::{
piv::Key,
policy::{PinPolicy, TouchPolicy},
reader::Context,
settings::{SettingSource, SettingValue},
setting::{Setting, SettingSource},
yubikey::{CachedPin, Serial, Version, YubiKey},
};

Expand Down
10 changes: 5 additions & 5 deletions src/piv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
error::{Error, Result},
policy::{PinPolicy, TouchPolicy},
serialization::*,
settings,
setting,
yubikey::YubiKey,
Buffer, ObjectId,
};
Expand Down Expand Up @@ -481,25 +481,25 @@ pub fn generate(
const SZ_ROCA_BLOCK_ADMIN: &str = "was blocked due to an administrator configuration setting.";
const SZ_ROCA_DEFAULT: &str = "was permitted by default, but is not recommended. The default behavior will change in a future Yubico release.";

let setting_roca: settings::SettingValue;
let setting_roca: setting::Setting;

match algorithm {
AlgorithmId::Rsa1024 | AlgorithmId::Rsa2048 => {
if yubikey.version.major == 4
&& (yubikey.version.minor < 3
|| yubikey.version.minor == 3 && (yubikey.version.patch < 5))
{
setting_roca = settings::SettingValue::get(SZ_SETTING_ROCA, true);
setting_roca = setting::Setting::get(SZ_SETTING_ROCA, true);

let psz_msg = match setting_roca.source {
settings::SettingSource::User => {
setting::SettingSource::User => {
if setting_roca.value {
SZ_ROCA_ALLOW_USER
} else {
SZ_ROCA_BLOCK_USER
}
}
settings::SettingSource::Admin => {
setting::SettingSource::Admin => {
if setting_roca.value {
SZ_ROCA_ALLOW_ADMIN
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/settings.rs → src/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ impl Default for SettingSource {
/// system administrator, or by the local user via `YUBIKEY_PIV_*` environment
/// variables.
#[derive(Copy, Clone, Debug)]
pub struct SettingValue {
pub struct Setting {
/// Boolean value
pub value: bool,

/// Source of the configuration setting (user, admin, or default)
pub source: SettingSource,
}

impl SettingValue {
impl Setting {
/// Get a [`SettingValue`] value by name.
pub fn get(key: &str, default: bool) -> Self {
Self::from_file(key)
Expand Down Expand Up @@ -109,7 +109,7 @@ impl SettingValue {
};

if name == key {
return Some(SettingValue {
return Some(Setting {
source: SettingSource::Admin,
value: value == "1" || value == "true",
});
Expand All @@ -124,14 +124,14 @@ impl SettingValue {
fn from_env(key: &str) -> Option<Self> {
env::var(format!("YUBIKEY_PIV_{}", key))
.ok()
.map(|value| SettingValue {
.map(|value| Setting {
source: SettingSource::User,
value: value == "1" || value == "true",
})
}
}

impl Default for SettingValue {
impl Default for Setting {
fn default() -> Self {
Self {
value: false,
Expand Down