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

Update time crate #200

Merged
merged 2 commits into from
Aug 16, 2024
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
37 changes: 33 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkcs11/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sha1 = { default-features = false, version = "0.10" }
digest = { default-features = false, version = "0.10" }
rayon = "1.8.0"
syslog = "6.1.0"
thiserror = "1.0.63"

[dev-dependencies]
hex-literal = "0.4.1"
2 changes: 1 addition & 1 deletion pkcs11/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub extern "C" fn C_Initialize(pInitArgs: CK_VOID_PTR) -> CK_RV {
match result {
Ok(()) => {}
Err(err) => {
error!("NetHSM PKCS#11: Failed to initialize configuration: {err:?}");
error!("NetHSM PKCS#11: Failed to initialize configuration: {err}");
return cryptoki_sys::CKR_FUNCTION_FAILED;
}
}
Expand Down
6 changes: 0 additions & 6 deletions pkcs11/src/backend/db/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ pub struct Object {
pub mechanisms: Vec<KeyMechanism>,
}

#[derive(Debug, Clone)]
pub struct KeyPair {
pub public_key: Object,
pub private_key: Object,
}

struct KeyData {
key_type: CK_KEY_TYPE,
key_size: Option<usize>,
Expand Down
2 changes: 1 addition & 1 deletion pkcs11/src/backend/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl SessionManager {
administrator: None,
retries: None,
db: Arc::new((Mutex::new(Db::new()), Condvar::new())),
description: None,
_description: None,
instances: vec![],
label: "test".to_string(),
operator: None,
Expand Down
3 changes: 0 additions & 3 deletions pkcs11/src/backend/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use super::{
};
use base64ct::{Base64, Encoding};
use der::Decode;
use digest::{FixedOutput, HashMarker};
use log::{debug, trace};
use nethsm_sdk_rs::{apis::default_api, models::SignMode};
use sha2::Digest;
Expand All @@ -22,8 +21,6 @@ pub struct SignCtx {
pub login_ctx: LoginCtx,
}

pub trait GenericDigest: HashMarker + FixedOutput {}

impl SignCtx {
pub fn init(mechanism: Mechanism, key: Object, login_ctx: LoginCtx) -> Result<Self, Error> {
trace!("key_type: {:?}", key.kind);
Expand Down
5 changes: 4 additions & 1 deletion pkcs11/src/config/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ use std::{io::Read, mem, net::SocketAddr, path::PathBuf};
use merge::Merge;
use serde::{Deserialize, Serialize};

#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum ConfigError {
#[error("Failed to load configuration file")]
Io(std::io::Error),
#[error("Failed to parse configuration file {0}")]
Yaml(serde_yaml::Error),
#[error("Config file not found")]
NoConfigFile,
}

Expand Down
13 changes: 2 additions & 11 deletions pkcs11/src/config/device.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
path::PathBuf,
sync::{Arc, Condvar, Mutex},
};
use std::sync::{Arc, Condvar, Mutex};

use nethsm_sdk_rs::apis::configuration::Configuration;

Expand All @@ -12,21 +9,15 @@ use super::config_file::{RetryConfig, UserConfig};
// stores the global configuration of the module
#[derive(Debug, Clone)]
pub struct Device {
pub log_file: Option<PathBuf>,
pub slots: Vec<Arc<Slot>>,
pub enable_set_attribute_value: bool,
}

#[derive(Debug, Clone)]
pub struct ClusterInstance {
pub api_config: nethsm_sdk_rs::apis::configuration::Configuration,
}

#[derive(Debug, Clone)]
pub struct Slot {
pub label: String,
pub retries: Option<RetryConfig>,
pub description: Option<String>,
pub _description: Option<String>,
pub instances: Vec<Configuration>,
pub operator: Option<UserConfig>,
pub administrator: Option<UserConfig>,
Expand Down
8 changes: 5 additions & 3 deletions pkcs11/src/config/initialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ use sha2::Digest;

const DEFAULT_USER_AGENT: &str = concat!("pkcs11-rs/", env!("CARGO_PKG_VERSION"));

#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum InitializationError {
#[error("Failed to load config")]
Config(crate::config::config_file::ConfigError),
#[error("Failed to load certificates")]
NoCerts,
#[error("No operator or administrator for slot: {0}")]
NoUser(String),
}

Expand Down Expand Up @@ -49,7 +52,6 @@ pub fn initialize_with_configs(
}
Ok(Device {
slots,
log_file: config.log_file,
enable_set_attribute_value: config.enable_set_attribute_value,
})
}
Expand Down Expand Up @@ -192,7 +194,7 @@ fn slot_from_config(slot: &SlotConfig) -> Result<Slot, InitializationError> {
}

Ok(Slot {
description: slot.description.clone(),
_description: slot.description.clone(),
label: slot.label.clone(),
instances,
administrator: slot.administrator.clone(),
Expand Down
Loading