Pingap Util
A collection of utilities for the Pingap project.
Features
- Cryptography: AES-256-GCM-SIV encryption and decryption.
- Formatting: Human-readable formatting for durations and byte sizes.
- IP Rules: Check if an IP address matches a set of rules (IPs and CIDR networks).
- Path Manipulation: Resolve paths containing
~and join URL paths. - PEM Handling: Convert PEM-formatted certificates/keys from strings, files, or base64.
- TOML Manipulation: Remove empty tables from a TOML string.
- Version Information: Get package and rustc versions.
- Base64: Encode and decode base64 strings.
Installation
Add the following to your Cargo.toml:
[]
= "0.12.0"
Usage
Cryptography
use ;
let key = "a-very-secret-key-that-is-32-bytes";
let data = "hello world";
let encrypted = aes_encrypt.unwrap;
let decrypted = aes_decrypt.unwrap;
assert_eq!;
Formatting
use ;
let mut buf = Stringnew;
format_byte_size;
assert_eq!;
IP Rules
use IpRules;
let rules = new;
assert!;
assert!;
assert!;
Path Manipulation
use ;
// Note: This test depends on the user's home directory
// let home_path = dirs::home_dir().unwrap().to_string_lossy().to_string();
// assert_eq!(resolve_path("~/some/path"), format!("{}/some/path", home_path));
assert_eq!;
PEM Handling
use convert_pem;
use fs;
use ;
// Example with a PEM string
let pem_str = "-----BEGIN CERTIFICATE-----
...";
let cert_bytes = convert_pem.unwrap;
// Example with a file path
// fs::write("cert.pem", pem_str).unwrap();
// let cert_bytes_from_file = convert_pem("cert.pem").unwrap();
// Example with base64
// let pem_base64 = STANDARD.encode(pem_str);
// let cert_bytes_from_base64 = convert_pem(&pem_base64).unwrap();
TOML Manipulation
use toml_omit_empty_value;
let toml_str = r#"
[a]
foo = "bar"
[b]
"#;
let cleaned_toml = toml_omit_empty_value.unwrap;
assert_eq!;
License
This project is licensed under the Apache-2.0 License.