[qtfm] feat #4: implement QingTingFM decipher

This commit is contained in:
鲁树人
2024-09-20 00:43:06 +01:00
parent 5748d92af4
commit 8f00373dbf
11 changed files with 303 additions and 0 deletions

View File

@@ -9,6 +9,12 @@ pub const ENGINE: Base64Engine = Base64Engine::new(
GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent),
);
/// Don't add padding when encoding, and require no padding when decoding.
pub const ENGINE_URL_SAFE: Base64Engine = Base64Engine::new(
&alphabet::URL_SAFE,
GeneralPurposeConfig::new().with_decode_padding_mode(DecodePaddingMode::Indifferent),
);
pub fn encode<T>(data: T) -> String
where
T: AsRef<[u8]>,
@@ -33,3 +39,17 @@ where
data[..len].copy_from_slice(&decoded);
Ok(&data[..len])
}
pub fn encode_url_safe<T>(data: T) -> String
where
T: AsRef<[u8]>,
{
ENGINE_URL_SAFE.encode(data)
}
pub fn decode_url_safe<T>(data: T) -> Result<Vec<u8>, DecodeError>
where
T: AsRef<[u8]>,
{
ENGINE_URL_SAFE.decode(data)
}