mirror of
https://github.com/euzu/tuliprox.git
synced 2026-10-28 17:52:50 +01:00
Resource rewrite secret key to ensure rewritten url validity
Fixed epg rewrite
This commit is contained in:
@@ -14,3 +14,11 @@ pub const fn default_connect_timeout_secs() -> u32 { 6 }
|
||||
pub const fn default_resource_retry_attempts() -> u32 { 3 }
|
||||
pub const fn default_resource_retry_backoff_ms() -> u64 { 250 }
|
||||
pub const fn default_resource_retry_backoff_multiplier() -> f64 { 1.0 }
|
||||
pub fn default_secret() -> String {
|
||||
let mut out = [0u8; 16];
|
||||
for x in &mut out {
|
||||
*x = fastrand::u8(..);
|
||||
}
|
||||
|
||||
out.iter().map(|b| format!("{:02X}", b)).collect()
|
||||
}
|
||||
@@ -111,3 +111,38 @@ where
|
||||
{
|
||||
ciborium::de::from_reader(value).map_err(to_io_error)
|
||||
}
|
||||
|
||||
|
||||
pub fn u8_16_to_hex(bytes: &[u8; 16]) -> String {
|
||||
bytes.iter().map(|b| format!("{:02X}", b)).collect()
|
||||
}
|
||||
|
||||
pub fn hex_to_u8_16(hex: &str) -> Result<[u8; 16], String> {
|
||||
if hex.len() != 32 {
|
||||
return Err("Hex string must be exactly 32 characters".into());
|
||||
}
|
||||
|
||||
let mut out = [0u8; 16];
|
||||
|
||||
for (i, chunk) in hex.as_bytes().chunks(2).enumerate() {
|
||||
let s = std::str::from_utf8(chunk).map_err(|_| "Invalid UTF-8")?;
|
||||
out[i] = u8::from_str_radix(s, 16).map_err(|_| "Invalid hex")?;
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn hex_to_secret<'de, D>(deserializer: D) -> Result<[u8; 16], D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let s: String = Deserialize::deserialize(deserializer)?;
|
||||
hex_to_u8_16(&s).map_err(serde::de::Error::custom)
|
||||
}
|
||||
|
||||
pub fn secret_to_hex<S>(bytes: &[u8; 16], serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&u8_16_to_hex(bytes))
|
||||
}
|
||||
Reference in New Issue
Block a user