Skip to content

Commit

Permalink
chore: rustc lint unreachable_pub
Browse files Browse the repository at this point in the history
  • Loading branch information
allan2 authored and CBenoit committed Oct 25, 2024
1 parent 3289e34 commit f274f39
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion devolutions-agent/src/updater/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<DateVersion>, UpdaterError> {
pub(crate) fn get_installed_product_version(product: Product) -> Result<Option<DateVersion>, UpdaterError> {
match product {
Product::Gateway => get_instaled_product_version_winreg(GATEWAY_UPDATE_CODE),
}
Expand Down
2 changes: 1 addition & 1 deletion devolutions-agent/src/updater/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`")]
Expand Down
2 changes: 1 addition & 1 deletion devolutions-agent/src/updater/integrity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
12 changes: 6 additions & 6 deletions devolutions-agent/src/updater/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>, UpdaterError> {
pub(crate) async fn download_binary(url: &str) -> Result<Vec<u8>, UpdaterError> {
info!(%url, "Downloading file from network...");

let body = reqwest::get(url)
Expand All @@ -22,13 +22,13 @@ pub async fn download_binary(url: &str) -> Result<Vec<u8>, UpdaterError> {
}

/// Download UTF-8 file to memory
pub async fn download_utf8(url: &str) -> Result<String, UpdaterError> {
pub(crate) async fn download_utf8(url: &str) -> Result<String, UpdaterError> {
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<Utf8PathBuf, UpdaterError> {
pub(crate) async fn save_to_temp_file(data: &[u8], extension: Option<&str>) -> Result<Utf8PathBuf, UpdaterError> {
let uuid = uuid::Uuid::new_v4();

let file_name = match extension {
Expand All @@ -49,12 +49,12 @@ pub async fn save_to_temp_file(data: &[u8], extension: Option<&str>) -> Result<U
}

/// Mark file to be removed on next reboot.
pub fn remove_file_on_reboot(file_path: &Utf8Path) -> 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};

Expand All @@ -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(())
}
8 changes: 4 additions & 4 deletions devolutions-agent/src/updater/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 }
}
}
Expand Down
4 changes: 2 additions & 2 deletions devolutions-agent/src/updater/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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),
}
Expand Down
8 changes: 4 additions & 4 deletions devolutions-agent/src/updater/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -31,19 +31,19 @@ impl FromStr for Product {
}

impl Product {
pub fn get_update_info(self, update_json: &UpdateJson) -> Option<ProductUpdateInfo> {
pub(crate) fn get_update_info(self, update_json: &UpdateJson) -> Option<ProductUpdateInfo> {
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",
}
Expand Down
6 changes: 3 additions & 3 deletions devolutions-agent/src/updater/productinfo/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ProductInfo>,
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
8 changes: 4 additions & 4 deletions devolutions-agent/src/updater/productinfo/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions devolutions-agent/src/updater/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
4 changes: 2 additions & 2 deletions devolutions-agent/src/updater/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, UpdaterError> {
pub(crate) fn uuid_to_reversed_hex(uuid: &str) -> Result<String, UpdaterError> {
const IGNORED_CHARS: &[char] = &['-', '{', '}'];

let hex_chars = uuid
Expand Down Expand Up @@ -48,7 +48,7 @@ pub fn uuid_to_reversed_hex(uuid: &str) -> Result<String, UpdaterError> {
/// 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<String, UpdaterError> {
pub(crate) fn reversed_hex_to_uuid(mut hex: &str) -> Result<String, UpdaterError> {
if hex.len() != 32 || hex.chars().any(|ch| !UUID_ALPHABET.contains(&ch)) {
return Err(UpdaterError::Uuid { uuid: hex.to_string() });
}
Expand Down

0 comments on commit f274f39

Please sign in to comment.