mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Big refactoring patch of the pv crate. The main reason behind this refactoring is to simplify testing and maintaining the pv crate while keeping OpenSSL/libcurl dependencies optional. Using crate features increases the number of targets that have to be tested. This refactoring eliminates the use of features by splitting the functionality of pv into a use OpenSSL and no-use-OpenSSL crate. Split off some code from the pv crate into a pv_core crate. pv requires pv_core and reexports all symbols. pv_base contains all code from former pv that does not use OpenSSL or libcurl functionalities. The refactored pv crate contains functionalities to generate requests and validate host key documents. All features from pv are dropped as they are not needed anymore and to streamline the codebase for easier use and testing. While at it fix some documentation issues. Users (pvsecret & pvapconfig) have next to no code change, besides the different import of the crate. Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
// SPDX-License-Identifier: MIT
|
|
//! Utils for s390-tools written in rust.
|
|
//! Not intened to be used outside of s390-tools.
|
|
//!
|
|
//! Copyright IBM Corp. 2023
|
|
|
|
/// Get the s390-tools release string
|
|
///
|
|
/// Provides the s390-tools release string.
|
|
/// For release builds this reqquires the environment variable
|
|
/// `S390_TOOLS_RELEASE` to be present at compile time.
|
|
/// For debug builds this value defaults to `DEBUG_BUILD`
|
|
/// if that variable is not present.
|
|
/// Should only be used by binary targets!!
|
|
///
|
|
/// Collapses to a compile time constant, that is likely to be inlined
|
|
/// by the compiler in release builds.
|
|
#[macro_export]
|
|
macro_rules! release_string {
|
|
() => {{
|
|
#[cfg(debug_assertions)]
|
|
match option_env!("S390_TOOLS_RELEASE") {
|
|
Some(ver) => ver,
|
|
None => "DEBUG BUILD",
|
|
}
|
|
#[cfg(not(debug_assertions))]
|
|
env!("S390_TOOLS_RELEASE", "env 'S390_TOOLS_RELEASE' must be set for release builds. Trigger build using the s390-tools build system or export the variable yourself")
|
|
}};
|
|
}
|
|
|
|
/// Asserts a constant expression evaluates to `true`.
|
|
///
|
|
/// If the expression is not evaluated to `true` the compilation will fail.
|
|
#[macro_export]
|
|
macro_rules! static_assert {
|
|
($condition:expr) => {
|
|
const _: () = core::assert!($condition);
|
|
};
|
|
}
|
|
|
|
/// Asserts that a type has a specific size.
|
|
///
|
|
/// Useful to validate structs that are passed to C code.
|
|
/// If the size has not the expected value the compilation will fail.
|
|
///
|
|
/// # Example
|
|
/// ```rust
|
|
/// # use utils::assert_size;
|
|
/// # fn main() {}
|
|
/// #[repr(C)]
|
|
/// struct c_struct {
|
|
/// v: u64,
|
|
/// }
|
|
/// assert_size!(c_struct, 8);
|
|
/// // assert_size!(c_struct, 7);//won't compile
|
|
/// ```
|
|
#[macro_export]
|
|
macro_rules! assert_size {
|
|
($t:ty, $sz:expr ) => {
|
|
$crate::static_assert!(::std::mem::size_of::<$t>() == $sz);
|
|
};
|
|
}
|