aboutsummaryrefslogtreecommitdiff
path: root/core/src/utils
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2023-11-28 22:41:33 +0300
committerhozan23 <hozan23@proton.me>2023-11-28 22:41:33 +0300
commit98a1de91a2dae06323558422c239e5a45fc86e7b (patch)
tree38c640248824fcb3b4ca5ba12df47c13ef26ccda /core/src/utils
parentca2a5f8bbb6983d9555abd10eaaf86950b794957 (diff)
implement TLS for inbound and outbound connections
Diffstat (limited to 'core/src/utils')
-rw-r--r--core/src/utils/decode.rs10
-rw-r--r--core/src/utils/encode.rs15
-rw-r--r--core/src/utils/mod.rs19
-rw-r--r--core/src/utils/path.rs39
4 files changed, 0 insertions, 83 deletions
diff --git a/core/src/utils/decode.rs b/core/src/utils/decode.rs
deleted file mode 100644
index a8a6522..0000000
--- a/core/src/utils/decode.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-use bincode::Decode;
-
-use crate::Result;
-
-/// Decodes a given type `T` from the given slice. returns the decoded value
-/// along with the number of bytes read.
-pub fn decode<T: Decode>(src: &[u8]) -> Result<(T, usize)> {
- let (result, bytes_read) = bincode::decode_from_slice(src, bincode::config::standard())?;
- Ok((result, bytes_read))
-}
diff --git a/core/src/utils/encode.rs b/core/src/utils/encode.rs
deleted file mode 100644
index 7d1061b..0000000
--- a/core/src/utils/encode.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-use bincode::Encode;
-
-use crate::Result;
-
-/// Encode the given type `T` into a `Vec<u8>`.
-pub fn encode<T: Encode>(msg: &T) -> Result<Vec<u8>> {
- let vec = bincode::encode_to_vec(msg, bincode::config::standard())?;
- Ok(vec)
-}
-
-/// Encode the given type `T` into the given slice..
-pub fn encode_into_slice<T: Encode>(msg: &T, dst: &mut [u8]) -> Result<()> {
- bincode::encode_into_slice(msg, dst, bincode::config::standard())?;
- Ok(())
-}
diff --git a/core/src/utils/mod.rs b/core/src/utils/mod.rs
deleted file mode 100644
index a3c3f50..0000000
--- a/core/src/utils/mod.rs
+++ /dev/null
@@ -1,19 +0,0 @@
-mod decode;
-mod encode;
-mod path;
-
-pub use decode::decode;
-pub use encode::{encode, encode_into_slice};
-pub use path::{home_dir, tilde_expand};
-
-use rand::{rngs::OsRng, Rng};
-
-/// Generates and returns a random u32 using `rand::rngs::OsRng`.
-pub fn random_32() -> u32 {
- OsRng.gen()
-}
-
-/// Generates and returns a random u16 using `rand::rngs::OsRng`.
-pub fn random_16() -> u16 {
- OsRng.gen()
-}
diff --git a/core/src/utils/path.rs b/core/src/utils/path.rs
deleted file mode 100644
index 2cd900a..0000000
--- a/core/src/utils/path.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-use std::path::PathBuf;
-
-use crate::{error::Error, Result};
-
-/// Returns the user's home directory as a `PathBuf`.
-#[allow(dead_code)]
-pub fn home_dir() -> Result<PathBuf> {
- dirs::home_dir().ok_or(Error::PathNotFound("Home dir not found"))
-}
-
-/// Expands a tilde (~) in a path and returns the expanded `PathBuf`.
-#[allow(dead_code)]
-pub fn tilde_expand(path: &str) -> Result<PathBuf> {
- match path {
- "~" => home_dir(),
- p if p.starts_with("~/") => Ok(home_dir()?.join(&path[2..])),
- _ => Ok(PathBuf::from(path)),
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn test_tilde_expand() {
- let path = "~/src";
- let expanded_path = dirs::home_dir().unwrap().join("src");
- assert_eq!(tilde_expand(path).unwrap(), expanded_path);
-
- let path = "~";
- let expanded_path = dirs::home_dir().unwrap();
- assert_eq!(tilde_expand(path).unwrap(), expanded_path);
-
- let path = "";
- let expanded_path = PathBuf::from("");
- assert_eq!(tilde_expand(path).unwrap(), expanded_path);
- }
-}