From 332dbab413442b0eaa349cbf523660311ef9a57e Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Wed, 28 Mar 2018 23:50:25 +0200 Subject: [PATCH] Move nonce generator to utils module --- src/models/command.rs | 4 ++-- src/models/handshake.rs | 4 ++-- src/utils.rs | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/models/command.rs b/src/models/command.rs index acfc4a3..61c414f 100644 --- a/src/models/command.rs +++ b/src/models/command.rs @@ -1,6 +1,6 @@ use serde::Serialize; -use uuid::Uuid; use super::Payload; +use utils::nonce; #[derive(Debug, Default, Serialize)] pub struct Command @@ -19,7 +19,7 @@ impl Command { Command { cmd: cmd.into(), - nonce: Uuid::new_v4().to_string(), + nonce: nonce(), args: args } } diff --git a/src/models/handshake.rs b/src/models/handshake.rs index b8ab667..8fa57e9 100644 --- a/src/models/handshake.rs +++ b/src/models/handshake.rs @@ -1,5 +1,5 @@ -use uuid::Uuid; use super::Payload; +use utils::nonce; #[derive(Debug, Default, Serialize)] pub struct Handshake { @@ -11,7 +11,7 @@ pub struct Handshake { impl Handshake { pub fn new(client_id: u64, version: u32) -> Self { Self { - nonce: Uuid::new_v4().to_string(), + nonce: nonce(), v: version, client_id: client_id.to_string() } diff --git a/src/utils.rs b/src/utils.rs index 2f52c64..ea4ec92 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,10 @@ use libc::getpid; +use uuid::Uuid; pub fn pid() -> i32 { unsafe { getpid() as i32 } } + +pub fn nonce() -> String { + Uuid::new_v4().to_string() +}