summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2020-03-21 13:30:31 -0500
committerStuart Stock <stuart@int08h.com>2020-03-21 13:30:31 -0500
commit02212e266fbd69a17c1e7fe32b16b113fe0c1999 (patch)
tree79b20e0ea74753ebfebe669a283d81c5430367b8
parent407f12dc85f697a594c5364bdc024990ee26fc60 (diff)
downloadroughenough-02212e266fbd69a17c1e7fe32b16b113fe0c1999.zip
Switch to std::time and drop use of 'time' crate
-rw-r--r--src/key/online.rs14
-rw-r--r--src/server.rs5
2 files changed, 10 insertions, 9 deletions
diff --git a/src/key/online.rs b/src/key/online.rs
index a78ac91..4ce1332 100644
--- a/src/key/online.rs
+++ b/src/key/online.rs
@@ -15,14 +15,14 @@
use crate::message::RtMessage;
use crate::sign::Signer;
use crate::tag::Tag;
-use time::Timespec;
+
+use crate::SIGNED_RESPONSE_CONTEXT;
use byteorder::{LittleEndian, WriteBytesExt};
use std::fmt;
use std::fmt::Formatter;
-
-use crate::SIGNED_RESPONSE_CONTEXT;
+use std::time::{UNIX_EPOCH, SystemTime};
///
/// Represents the delegated Roughtime ephemeral online key.
@@ -60,7 +60,7 @@ impl OnlineKey {
/// Create an SREP response containing the provided time and Merkle root,
/// signed by this online key.
- pub fn make_srep(&mut self, now: Timespec, merkle_root: &[u8]) -> RtMessage {
+ pub fn make_srep(&mut self, now: SystemTime, merkle_root: &[u8]) -> RtMessage {
let mut radi = [0; 4];
let mut midp = [0; 8];
@@ -71,11 +71,13 @@ impl OnlineKey {
// current epoch time in microseconds
let midp_time = {
- let secs = (now.sec as u64) * 1_000_000;
- let nsecs = (now.nsec as u64) / 1_000;
+ let d = now.duration_since(UNIX_EPOCH).expect("duration since epoch");
+ let secs = d.as_secs() * 1_000_000;
+ let nsecs = (d.subsec_nanos() as u64) / 1_000;
secs + nsecs
};
+
(&mut midp as &mut [u8])
.write_u64::<LittleEndian>(midp_time)
.unwrap();
diff --git a/src/server.rs b/src/server.rs
index 8ae0641..ad08ff0 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -22,9 +22,8 @@ use std::net::SocketAddr;
use std::process;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
-use std::time::Duration;
+use std::time::{Duration, SystemTime};
use std::io::Write;
-use time;
use byteorder::{LittleEndian, WriteBytesExt};
@@ -363,7 +362,7 @@ impl Server {
let merkle_root = self.merkle.compute_root();
// The SREP tag is identical for each response
- let srep = self.online_key.make_srep(time::get_time(), &merkle_root);
+ let srep = self.online_key.make_srep(SystemTime::now(), &merkle_root);
for (i, &(ref nonce, ref src_addr)) in self.requests.iter().enumerate() {
let paths = self.merkle.get_paths(i);