Skip to content

Commit

Permalink
Fixed code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rnijveld committed Oct 9, 2024
1 parent beceda6 commit 28abb0a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 47 deletions.
11 changes: 9 additions & 2 deletions statime-linux/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ pub struct PresharedConfig {
}

#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "kebab-case", deny_unknown_fields, tag = "type", content = "data")]
#[serde(
rename_all = "kebab-case",
deny_unknown_fields,
tag = "type",
content = "data"
)]
pub enum KeyDataConfig {
Raw(Vec<u8>),
Bytes(String),
Expand All @@ -86,7 +91,9 @@ impl KeyDataConfig {
match self {
KeyDataConfig::Raw(data) => data.clone(),
KeyDataConfig::Bytes(data) => data.as_bytes().to_vec(),
KeyDataConfig::Base64(data) => base64::engine::general_purpose::STANDARD.decode(data).unwrap(),
KeyDataConfig::Base64(data) => base64::engine::general_purpose::STANDARD
.decode(data)
.unwrap(),
KeyDataConfig::Hex(data) => hex::decode(data).unwrap(),
}
}
Expand Down
3 changes: 1 addition & 2 deletions statime-linux/src/ke/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ use tokio::{
};
use tokio_rustls::{server::TlsStream, TlsAcceptor};

use crate::initialize_logging_parse_config;

use super::{
common::{load_certs, load_certs_from_files, load_private_key, Key},
record::*,
tls_utils::OnlyAllowedClients,
};
use crate::initialize_logging_parse_config;

struct KeySetStore {
current: Key,
Expand Down
1 change: 0 additions & 1 deletion statime-linux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub mod tracing;
use std::path::Path;

use config::Config;

pub use ke::main as ke_main;
pub use metrics::exporter::main as metrics_exporter_main;
use tracing::LogLevel;
Expand Down
14 changes: 9 additions & 5 deletions statime-linux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,17 @@ async fn actual_main() {
let (provider, spp) = match config.security {
SecurityConfig::None => (DynamicSecurityProvider::NoSecurity, None),
SecurityConfig::NTS(nts) => {
let (provider, spp) = NTSProvider::new(nts.server, nts.client_cert_key, nts.client_cert, nts.server_root)
.await
.unwrap();
let (provider, spp) = NTSProvider::new(
nts.server,
nts.client_cert_key,
nts.client_cert,
nts.server_root,
)
.await
.unwrap();
(DynamicSecurityProvider::NTS(provider), Some(spp))
},
}
SecurityConfig::Preshared(psk) => {

let provider = PresharedSecurityProvider::new(psk.spp, psk.key_id, psk.key.as_bytes());
(DynamicSecurityProvider::Preshared(provider), Some(psk.spp))
}
Expand Down
42 changes: 19 additions & 23 deletions statime-linux/src/securityprovider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::{collections::HashMap, error::Error, path::PathBuf, sync::Arc};
use rand::Rng;
use rustls::{ClientConfig, RootCertStore};
use statime::crypto::{
HmacSha256_128, SecurityAssociation, SecurityAssociationProvider, SecurityPolicy, SenderIdentificaton
HmacSha256_128, SecurityAssociation, SecurityAssociationProvider, SecurityPolicy,
SenderIdentificaton,
};

use crate::ke::{
Expand Down Expand Up @@ -292,7 +293,9 @@ pub struct PresharedSecurityAssociationInner {
sequence_ids: HashMap<(SenderIdentificaton, u32), u16>,
}

pub struct PresharedSecurityAssociation<'a>(std::sync::MutexGuard<'a, PresharedSecurityAssociationInner>);
pub struct PresharedSecurityAssociation<'a>(
std::sync::MutexGuard<'a, PresharedSecurityAssociationInner>,
);

impl<'a> SecurityAssociation for PresharedSecurityAssociation<'a> {
fn policy_data(&self) -> SecurityPolicy {
Expand Down Expand Up @@ -332,12 +335,7 @@ impl<'a> SecurityAssociation for PresharedSecurityAssociation<'a> {
}

fn signing_mac(&self) -> (u32, &dyn statime::crypto::Mac) {
(
self.0.key.0,
&self.0
.key
.1 as &dyn statime::crypto::Mac
)
(self.0.key.0, &self.0.key.1 as &dyn statime::crypto::Mac)
}
}

Expand All @@ -359,14 +357,14 @@ impl SecurityAssociationProvider for PresharedSecurityProvider {
impl PresharedSecurityProvider {
pub fn new(spp: u8, key_id: u32, key_data: [u8; 32]) -> PresharedSecurityProvider {
let mut data = HashMap::new();
data.insert(spp, Arc::new(std::sync::Mutex::new(PresharedSecurityAssociationInner {
key: (
key_id,
statime::crypto::HmacSha256_128::new(key_data),
),
ignore_correction: false,
sequence_ids: Default::default(),
})));
data.insert(
spp,
Arc::new(std::sync::Mutex::new(PresharedSecurityAssociationInner {
key: (key_id, statime::crypto::HmacSha256_128::new(key_data)),
ignore_correction: false,
sequence_ids: Default::default(),
})),
);

PresharedSecurityProvider {
associations: Arc::new(data),
Expand Down Expand Up @@ -404,12 +402,8 @@ impl<'a> SecurityAssociation for DynamicSecurityAssociation<'a> {
) -> bool {
use DynamicSecurityAssociation::*;
match self {
NTS(association) => {
association.register_sequence_id(key_id, sender, sequence_id)
}
Preshared(association) => {
association.register_sequence_id(key_id, sender, sequence_id)
}
NTS(association) => association.register_sequence_id(key_id, sender, sequence_id),
Preshared(association) => association.register_sequence_id(key_id, sender, sequence_id),
}
}

Expand Down Expand Up @@ -438,7 +432,9 @@ impl SecurityAssociationProvider for DynamicSecurityProvider {
match self {
NoSecurity => None,
NTS(provider) => provider.lookup(spp).map(DynamicSecurityAssociation::NTS),
Preshared(provider) => provider.lookup(spp).map(DynamicSecurityAssociation::Preshared),
Preshared(provider) => provider
.lookup(spp)
.map(DynamicSecurityAssociation::Preshared),
}
}
}
5 changes: 3 additions & 2 deletions statime/src/datastructures/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ fn base_header(
/// Checks whether message is of PTP revision compatible with Statime
pub fn is_compatible(buffer: &[u8]) -> bool {
// this ensures that versionPTP in the header is 2
// it will never happen in PTPv1 packets because this octet is the LSB of versionPTP there
(buffer.len() >= 2) && (buffer[1] & 0xF) == 2
// it will never happen in PTPv1 packets because this octet is the LSB of
// versionPTP there
(buffer.len() >= 2) && (buffer[1] & 0xf) == 2
}

impl<'a> Message<'a> {
Expand Down
12 changes: 8 additions & 4 deletions statime/src/overlay_clock.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::{time::Duration, time::Time, Clock};
use crate::{
time::{Duration, Time},
Clock,
};

/// An overlay over other, read-only clock, frequency-locked to it.
/// In other words, a virtual clock which can be tuned in software without affecting
/// the underlying system or hardware clock.
/// In other words, a virtual clock which can be tuned in software without
/// affecting the underlying system or hardware clock.
#[derive(Debug)]
pub struct OverlayClock<C: Clock> {
roclock: C,
Expand All @@ -23,7 +26,8 @@ impl<C: Clock> OverlayClock<C> {
}
}

/// Converts (shifts and scales) `Time` in underlying clock's timescale to overlay clock timescale
/// Converts (shifts and scales) `Time` in underlying clock's timescale to
/// overlay clock timescale
pub fn time_from_underlying(&self, roclock_time: Time) -> Time {
let elapsed = roclock_time - self.last_sync;
let corr = elapsed * self.freq_scale_ppm_diff / 1_000_000;
Expand Down
5 changes: 3 additions & 2 deletions statime/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use rand::Rng;
use state::PortState;

use self::sequence_id::SequenceIdGenerator;
pub use crate::datastructures::messages::is_compatible as is_message_buffer_compatible;
pub use crate::datastructures::messages::MAX_DATA_LEN;
pub use crate::datastructures::messages::{
is_compatible as is_message_buffer_compatible, MAX_DATA_LEN,
};
#[cfg(doc)]
use crate::PtpInstance;
use crate::{
Expand Down
14 changes: 8 additions & 6 deletions statime/src/shared_clock.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::time::Duration;
use crate::time::Time;
use crate::Clock;
use std::sync::Arc;
use std::sync::Mutex;
use std::sync::{Arc, Mutex};

use crate::{
time::{Duration, Time},
Clock,
};

/// A wrapper for stateful `statime::Clock` implementations to make them behave
/// like e.g. `statime_linux::LinuxClock` - clones share state with each other
Expand All @@ -19,7 +20,8 @@ impl<C: Clock> SharedClock<C> {
}

impl<C: Clock> Clone for SharedClock<C> {
/// Clone the shared reference to the clock (behaviour consistent with `statime_linux::LinuxClock`)
/// Clone the shared reference to the clock (behaviour consistent with
/// `statime_linux::LinuxClock`)
fn clone(&self) -> Self {
Self(self.0.clone())
}
Expand Down

0 comments on commit 28abb0a

Please sign in to comment.