From f274f3933e324b7ceb9b0b8da7168422cc5059fe Mon Sep 17 00:00:00 2001 From: Allan <6740989+allan2@users.noreply.github.com> Date: Fri, 25 Oct 2024 02:59:52 -0400 Subject: [PATCH] chore: rustc lint unreachable_pub --- devolutions-agent/src/updater/detect.rs | 2 +- devolutions-agent/src/updater/error.rs | 2 +- devolutions-agent/src/updater/integrity.rs | 2 +- devolutions-agent/src/updater/io.rs | 12 ++++++------ devolutions-agent/src/updater/mod.rs | 8 ++++---- devolutions-agent/src/updater/package.rs | 4 ++-- devolutions-agent/src/updater/product.rs | 8 ++++---- devolutions-agent/src/updater/productinfo/db.rs | 6 +++--- devolutions-agent/src/updater/productinfo/mod.rs | 8 ++++---- devolutions-agent/src/updater/security.rs | 4 ++-- devolutions-agent/src/updater/uuid.rs | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/devolutions-agent/src/updater/detect.rs b/devolutions-agent/src/updater/detect.rs index 1b55cd802..92eb25089 100644 --- a/devolutions-agent/src/updater/detect.rs +++ b/devolutions-agent/src/updater/detect.rs @@ -8,7 +8,7 @@ use crate::updater::{Product, UpdaterError}; const GATEWAY_UPDATE_CODE: &str = "{db3903d6-c451-4393-bd80-eb9f45b90214}"; /// Get the installed version of a product. -pub fn get_installed_product_version(product: Product) -> Result, UpdaterError> { +pub(crate) fn get_installed_product_version(product: Product) -> Result, UpdaterError> { match product { Product::Gateway => get_instaled_product_version_winreg(GATEWAY_UPDATE_CODE), } diff --git a/devolutions-agent/src/updater/error.rs b/devolutions-agent/src/updater/error.rs index a650f359c..f5398accf 100644 --- a/devolutions-agent/src/updater/error.rs +++ b/devolutions-agent/src/updater/error.rs @@ -4,7 +4,7 @@ use thiserror::Error; use crate::updater::Product; #[derive(Debug, Error)] -pub enum UpdaterError { +pub(crate) enum UpdaterError { #[error("queried `{product}` artifact hash has invalid format: `{hash}`")] HashEncoding { product: Product, hash: String }, #[error("integrity check for downloaded `{product}` artifact has failed, expected hash: `{expected_hash}`, actual hash: `{actual_hash}`")] diff --git a/devolutions-agent/src/updater/integrity.rs b/devolutions-agent/src/updater/integrity.rs index fbadee708..570a7903d 100644 --- a/devolutions-agent/src/updater/integrity.rs +++ b/devolutions-agent/src/updater/integrity.rs @@ -5,7 +5,7 @@ use sha2::{Digest as _, Sha256}; use crate::updater::{UpdaterCtx, UpdaterError}; /// Validate the hash of downloaded artifact (Hash should be provided in encoded hex string). -pub fn validate_artifact_hash(ctx: &UpdaterCtx, data: &[u8], hash: &str) -> Result<(), UpdaterError> { +pub(crate) fn validate_artifact_hash(ctx: &UpdaterCtx, data: &[u8], hash: &str) -> Result<(), UpdaterError> { let expected_hash_bytes = hex::decode(hash).map_err(|_| UpdaterError::HashEncoding { product: ctx.product, hash: hash.to_owned(), diff --git a/devolutions-agent/src/updater/io.rs b/devolutions-agent/src/updater/io.rs index 14e8bc369..8b1b702e9 100644 --- a/devolutions-agent/src/updater/io.rs +++ b/devolutions-agent/src/updater/io.rs @@ -8,7 +8,7 @@ use tokio::io::AsyncWriteExt; use crate::updater::UpdaterError; /// Download binary file to memory -pub async fn download_binary(url: &str) -> Result, UpdaterError> { +pub(crate) async fn download_binary(url: &str) -> Result, UpdaterError> { info!(%url, "Downloading file from network..."); let body = reqwest::get(url) @@ -22,13 +22,13 @@ pub async fn download_binary(url: &str) -> Result, UpdaterError> { } /// Download UTF-8 file to memory -pub async fn download_utf8(url: &str) -> Result { +pub(crate) async fn download_utf8(url: &str) -> Result { let bytes = download_binary(url).await?; String::from_utf8(bytes).map_err(|_| UpdaterError::Utf8) } /// Save data to a temporary file -pub async fn save_to_temp_file(data: &[u8], extension: Option<&str>) -> Result { +pub(crate) async fn save_to_temp_file(data: &[u8], extension: Option<&str>) -> Result { let uuid = uuid::Uuid::new_v4(); let file_name = match extension { @@ -49,12 +49,12 @@ pub async fn save_to_temp_file(data: &[u8], extension: Option<&str>) -> Result Result<(), UpdaterError> { +pub(crate) fn remove_file_on_reboot(file_path: &Utf8Path) -> Result<(), UpdaterError> { remove_file_on_reboot_impl(file_path) } #[cfg(windows)] -pub fn remove_file_on_reboot_impl(file_path: &Utf8Path) -> Result<(), UpdaterError> { +pub(crate) fn remove_file_on_reboot_impl(file_path: &Utf8Path) -> Result<(), UpdaterError> { use windows::core::HSTRING; use windows::Win32::Storage::FileSystem::{MoveFileExW, MOVEFILE_DELAY_UNTIL_REBOOT}; @@ -70,7 +70,7 @@ pub fn remove_file_on_reboot_impl(file_path: &Utf8Path) -> Result<(), UpdaterErr } #[cfg(not(windows))] -pub fn impl_remove_file_on_reboot_impl(_file_path: &Utf8Path) -> Result<(), UpdaterError> { +pub(crate) fn impl_remove_file_on_reboot_impl(_file_path: &Utf8Path) -> Result<(), UpdaterError> { // NOTE: On UNIX-like platforms /tmp folder is used which is cleared by OS automatically. Ok(()) } diff --git a/devolutions-agent/src/updater/mod.rs b/devolutions-agent/src/updater/mod.rs index f2177ebaa..88330b557 100644 --- a/devolutions-agent/src/updater/mod.rs +++ b/devolutions-agent/src/updater/mod.rs @@ -28,8 +28,8 @@ use package::{install_package, validate_package}; use productinfo::DEVOLUTIONS_PRODUCTINFO_URL; use security::set_file_dacl; -pub use error::UpdaterError; -pub use product::Product; +pub(crate) use error::UpdaterError; +pub(crate) use product::Product; const UPDATE_JSON_WATCH_INTERVAL: Duration = Duration::from_secs(3); @@ -48,12 +48,12 @@ struct UpdateOrder { hash: String, } -pub struct UpdaterTask { +pub(crate) struct UpdaterTask { conf_handle: ConfHandle, } impl UpdaterTask { - pub fn new(conf_handle: ConfHandle) -> Self { + pub(crate) fn new(conf_handle: ConfHandle) -> Self { Self { conf_handle } } } diff --git a/devolutions-agent/src/updater/package.rs b/devolutions-agent/src/updater/package.rs index 7509eb20e..07aa7e8dd 100644 --- a/devolutions-agent/src/updater/package.rs +++ b/devolutions-agent/src/updater/package.rs @@ -13,7 +13,7 @@ const DEVOLUTIONS_CERT_THUMBPRINTS: &[&str] = &[ "8db5a43bb8afe4d2ffb92da9007d8997a4cc4e13", ]; -pub async fn install_package(ctx: &UpdaterCtx, path: &Utf8Path) -> Result<(), UpdaterError> { +pub(crate) async fn install_package(ctx: &UpdaterCtx, path: &Utf8Path) -> Result<(), UpdaterError> { match ctx.product { Product::Gateway => install_msi(ctx, path).await, } @@ -100,7 +100,7 @@ fn ensure_enough_rights() -> Result<(), UpdaterError> { Ok(()) } -pub fn validate_package(ctx: &UpdaterCtx, path: &Utf8Path) -> Result<(), UpdaterError> { +pub(crate) fn validate_package(ctx: &UpdaterCtx, path: &Utf8Path) -> Result<(), UpdaterError> { match ctx.product { Product::Gateway => validate_msi(ctx, path), } diff --git a/devolutions-agent/src/updater/product.rs b/devolutions-agent/src/updater/product.rs index bbe661c4c..c8e5d93cf 100644 --- a/devolutions-agent/src/updater/product.rs +++ b/devolutions-agent/src/updater/product.rs @@ -7,7 +7,7 @@ use crate::updater::productinfo::GATEWAY_PRODUCT_ID; /// Product IDs to track updates for #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Product { +pub(crate) enum Product { Gateway, } @@ -31,19 +31,19 @@ impl FromStr for Product { } impl Product { - pub fn get_update_info(self, update_json: &UpdateJson) -> Option { + pub(crate) fn get_update_info(self, update_json: &UpdateJson) -> Option { match self { Product::Gateway => update_json.gateway.clone(), } } - pub const fn get_productinfo_id(self) -> &'static str { + pub(crate) const fn get_productinfo_id(self) -> &'static str { match self { Product::Gateway => GATEWAY_PRODUCT_ID, } } - pub const fn get_package_extension(self) -> &'static str { + pub(crate) const fn get_package_extension(self) -> &'static str { match self { Product::Gateway => "msi", } diff --git a/devolutions-agent/src/updater/productinfo/db.rs b/devolutions-agent/src/updater/productinfo/db.rs index dc6e4f8bc..7589a3a38 100644 --- a/devolutions-agent/src/updater/productinfo/db.rs +++ b/devolutions-agent/src/updater/productinfo/db.rs @@ -6,13 +6,13 @@ use std::str::FromStr; use crate::updater::UpdaterError; #[derive(Debug, Clone, Default)] -pub struct ProductInfo { +pub(crate) struct ProductInfo { pub version: String, pub hash: String, pub url: String, } -pub struct ProductInfoDb { +pub(crate) struct ProductInfoDb { pub records: HashMap, } @@ -51,7 +51,7 @@ impl FromStr for ProductInfoDb { impl ProductInfoDb { /// Get product information by product ID - pub fn get(&self, product_id: &str) -> Option<&ProductInfo> { + pub(crate) fn get(&self, product_id: &str) -> Option<&ProductInfo> { self.records.get(product_id) } } diff --git a/devolutions-agent/src/updater/productinfo/mod.rs b/devolutions-agent/src/updater/productinfo/mod.rs index 6d853257f..1a16ac8f5 100644 --- a/devolutions-agent/src/updater/productinfo/mod.rs +++ b/devolutions-agent/src/updater/productinfo/mod.rs @@ -1,10 +1,10 @@ mod db; -pub const DEVOLUTIONS_PRODUCTINFO_URL: &str = "https://devolutions.net/productinfo.htm"; +pub(crate) const DEVOLUTIONS_PRODUCTINFO_URL: &str = "https://devolutions.net/productinfo.htm"; #[cfg(windows)] -pub const GATEWAY_PRODUCT_ID: &str = "Gatewaybin"; +pub(crate) const GATEWAY_PRODUCT_ID: &str = "Gatewaybin"; #[cfg(not(windows))] -pub const GATEWAY_PRODUCT_ID: &str = "GatewaybinDebX64"; +pub(crate) const GATEWAY_PRODUCT_ID: &str = "GatewaybinDebX64"; -pub use db::ProductInfoDb; +pub(crate) use db::ProductInfoDb; diff --git a/devolutions-agent/src/updater/security.rs b/devolutions-agent/src/updater/security.rs index fa357cfb9..db0afb4e1 100644 --- a/devolutions-agent/src/updater/security.rs +++ b/devolutions-agent/src/updater/security.rs @@ -12,10 +12,10 @@ use crate::updater::UpdaterError; /// - NETWORK SERVICE: Write, Read (Allow Devolutions Gateway service to update the file) /// - Administrators: Full control /// - Users: Read -pub const UPDATE_JSON_DACL: &str = "D:PAI(A;;FA;;;SY)(A;;0x1201bf;;;NS)(A;;FA;;;BA)(A;;FR;;;BU)"; +pub(crate) const UPDATE_JSON_DACL: &str = "D:PAI(A;;FA;;;SY)(A;;0x1201bf;;;NS)(A;;FA;;;BA)(A;;FR;;;BU)"; /// Set DACL (Discretionary Access Control List) on a specified file. -pub fn set_file_dacl(file_path: &Utf8Path, acl: &str) -> Result<(), UpdaterError> { +pub(crate) fn set_file_dacl(file_path: &Utf8Path, acl: &str) -> Result<(), UpdaterError> { use windows::core::HSTRING; use windows::Win32::Foundation::{LocalFree, ERROR_SUCCESS, FALSE, HLOCAL}; use windows::Win32::Security::Authorization::{ diff --git a/devolutions-agent/src/updater/uuid.rs b/devolutions-agent/src/updater/uuid.rs index b56ed4a32..369742a66 100644 --- a/devolutions-agent/src/updater/uuid.rs +++ b/devolutions-agent/src/updater/uuid.rs @@ -14,7 +14,7 @@ const UUID_ALPHABET: &[char] = &[ /// for upgrade code table. /// /// e.g.: `{82318d3c-811f-4d5d-9a82-b7c31b076755}` => `C3D81328F118D5D4A9287B3CB1707655` -pub fn uuid_to_reversed_hex(uuid: &str) -> Result { +pub(crate) fn uuid_to_reversed_hex(uuid: &str) -> Result { const IGNORED_CHARS: &[char] = &['-', '{', '}']; let hex_chars = uuid @@ -48,7 +48,7 @@ pub fn uuid_to_reversed_hex(uuid: &str) -> Result { /// Converts reversed hex UUID back to standard Windows Registry format (upper case letters). /// /// e.g.: `C3D81328F118D5D4A9287B3CB1707655` => `{82318d3c-811f-4d5d-9a82-b7c31b076755}` -pub fn reversed_hex_to_uuid(mut hex: &str) -> Result { +pub(crate) fn reversed_hex_to_uuid(mut hex: &str) -> Result { if hex.len() != 32 || hex.chars().any(|ch| !UUID_ALPHABET.contains(&ch)) { return Err(UpdaterError::Uuid { uuid: hex.to_string() }); }