Skip to content

Commit 563aacd

Browse files
committed
Replace as_nanos and use from_mins
1 parent 8b45676 commit 563aacd

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

src/pam/converse.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use std::time::Duration;
44

55
use crate::cutils::string_from_ptr;
66
use crate::pam::rpassword::Hidden;
7-
use crate::system::{
8-
signal::{self, SignalSet},
9-
};
7+
use crate::system::signal::{self, SignalSet};
108

119
use super::sys::*;
1210

src/pam/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use std::{
77
time::Duration,
88
};
99

10-
use crate::system::{
11-
signal::{self, SignalSet},
12-
};
10+
use crate::system::signal::{self, SignalSet};
1311

1412
use converse::ConverserData;
1513
use error::pam_err;

src/sudo/pam.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::{ffi::OsString, time::Duration};
1+
use std::ffi::OsString;
2+
use std::time::Duration;
23

34
use crate::common::context::LaunchType;
45
use crate::common::error::Error;

src/sudoers/policy.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use crate::system::{Hostname, User};
1212
///
1313
/// The trait definitions can be part of some global crate in the future, if we support more
1414
/// than just the sudoers file.
15-
use std::{collections::HashSet, time::Duration};
15+
use std::collections::HashSet;
16+
use std::time::Duration;
1617

1718
#[must_use]
1819
#[cfg_attr(test, derive(Debug, PartialEq))]
@@ -191,7 +192,7 @@ mod test {
191192
Authentication {
192193
must_authenticate: true,
193194
allowed_attempts: 3,
194-
prior_validity: Duration::from_secs(15 * 60),
195+
prior_validity: Duration::from_mins(15),
195196
credential: AuthenticatingUser::InvokingUser,
196197
pwfeedback: false,
197198
password_timeout: Some(Duration::from_secs(300)),
@@ -208,7 +209,7 @@ mod test {
208209
Authentication {
209210
must_authenticate: false,
210211
allowed_attempts: 3,
211-
prior_validity: Duration::from_secs(15 * 60),
212+
prior_validity: Duration::from_mins(15 * 60),
212213
credential: AuthenticatingUser::InvokingUser,
213214
pwfeedback: false,
214215
password_timeout: Some(Duration::from_secs(300)),

src/system/time.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ impl SystemTime {
5454
}
5555

5656
#[inline]
57-
pub fn checked_add(self, rhs: Duration) -> Option<SystemTime> {
58-
let rhs_secs = rhs.as_nanos().div_euclid(1_000_000_000).try_into().ok()?;
59-
let rhs_nsecs = rhs.as_nanos().rem_euclid(1_000_000_000).try_into().ok()?;
57+
fn checked_add(self, rhs: Duration) -> Option<SystemTime> {
58+
let rhs_secs = rhs.as_secs().try_into().ok()?;
59+
let rhs_nsecs = rhs.subsec_nanos().try_into().ok()?;
6060

6161
let secs = self.secs.checked_add(rhs_secs)?;
6262
let nsecs = self.nsecs.checked_add(rhs_nsecs)?;
@@ -65,9 +65,9 @@ impl SystemTime {
6565
}
6666

6767
#[inline]
68-
pub fn checked_sub(self, rhs: Duration) -> Option<SystemTime> {
69-
let rhs_secs = rhs.as_nanos().div_euclid(1_000_000_000).try_into().ok()?;
70-
let rhs_nsecs = rhs.as_nanos().rem_euclid(1_000_000_000).try_into().ok()?;
68+
fn checked_sub(self, rhs: Duration) -> Option<SystemTime> {
69+
let rhs_secs = rhs.as_secs().try_into().ok()?;
70+
let rhs_nsecs = rhs.subsec_nanos().try_into().ok()?;
7171

7272
let secs = self.secs.checked_sub(rhs_secs)?;
7373
let nsecs = self.nsecs.checked_sub(rhs_nsecs)?;

0 commit comments

Comments
 (0)