Skip to content

Commit

Permalink
[squash] change signature of get_current_time
Browse files Browse the repository at this point in the history
to appease clippy
  • Loading branch information
japaric committed Nov 14, 2023
1 parent 8e1b05c commit c804e50
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rustls/src/client/client_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl ClientConfig {
let now = self
.time_provider
.get_current_time()
.map_err(|_| Error::FailedToGetCurrentTime)?;
.ok_or(Error::FailedToGetCurrentTime)?;

Ok(now)
}
Expand Down
3 changes: 1 addition & 2 deletions rustls/src/client/hs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ fn find_session(
#[cfg(not(feature = "std"))]
let now = config
.time_provider
.get_current_time()
.ok()?;
.get_current_time()?;

let retrieved = persist::Retrieved::new(resuming, now);
match retrieved.has_expired() {
Expand Down
2 changes: 1 addition & 1 deletion rustls/src/server/server_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ impl ServerConfig {
let now = self
.time_provider
.get_current_time()
.map_err(|_| Error::FailedToGetCurrentTime)?;
.ok_or(Error::FailedToGetCurrentTime)?;

Ok(now)
}
Expand Down
2 changes: 1 addition & 1 deletion rustls/src/server/tls12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ impl State<ServerConnectionData> for ExpectFinished {
.config
.time_provider
.get_current_time()
.map_err(|_| Error::FailedToGetCurrentTime)?;
.ok_or(Error::FailedToGetCurrentTime)?;

emit_ticket(
&self.secrets,
Expand Down
6 changes: 3 additions & 3 deletions rustls/src/server/tls13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ mod client_hello {
.config
.time_provider
.get_current_time()
.map_err(|_| Error::FailedToGetCurrentTime)?;
.ok_or(Error::FailedToGetCurrentTime)?;

let resume = match self
.attempt_tls13_ticket_decryption(&psk_id.identity.0)
Expand Down Expand Up @@ -941,7 +941,7 @@ impl State<ServerConnectionData> for ExpectCertificate {
.config
.time_provider
.get_current_time()
.map_err(|_| Error::FailedToGetCurrentTime)?;
.ok_or(Error::FailedToGetCurrentTime)?;

self.config
.verifier
Expand Down Expand Up @@ -1119,7 +1119,7 @@ impl ExpectFinished {
let now = config
.time_provider
.get_current_time()
.map_err(|_| Error::FailedToGetCurrentTime)?;
.ok_or(Error::FailedToGetCurrentTime)?;

let plain =
get_server_session_value(transcript, suite, key_schedule, cx, &nonce, now, age_add)
Expand Down
12 changes: 7 additions & 5 deletions rustls/src/time_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@ impl TimeProvider {
Self::new(NoTimeProvider)
}

pub(crate) fn get_current_time(&self) -> Result<UnixTime, ()> {
pub(crate) fn get_current_time(&self) -> Option<UnixTime> {
self.inner.get_current_time()
}
}

/// Get current time
pub trait GetCurrentTime: Debug + Send + Sync {
/// Get current time
fn get_current_time(&self) -> Result<UnixTime, ()>;
/// Returns the current time
///
/// or `None` if unable to retrieve the current time
fn get_current_time(&self) -> Option<UnixTime>;
}

#[derive(Debug)]
struct NoTimeProvider;

impl GetCurrentTime for NoTimeProvider {
fn get_current_time(&self) -> Result<UnixTime, ()> {
Err(())
fn get_current_time(&self) -> Option<UnixTime> {
None
}
}

0 comments on commit c804e50

Please sign in to comment.