mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 06:56:29 +03:00
url-safe id generation (#3231)
* test dc_create_id() for invalid characters * create url-save ids (as documented)
This commit is contained in:
@@ -214,7 +214,10 @@ pub(crate) fn dc_create_id() -> String {
|
||||
rng.fill(&mut arr[..]);
|
||||
|
||||
// Take 11 base64 characters containing 66 random bits.
|
||||
base64::encode(&arr).chars().take(11).collect()
|
||||
base64::encode_config(&arr, base64::URL_SAFE)
|
||||
.chars()
|
||||
.take(11)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Function generates a Message-ID that can be used for a new outgoing message.
|
||||
@@ -762,6 +765,15 @@ Hop: From: hq5.example.org; By: hq5.example.org; Date: Mon, 27 Dec 2021 11:21:22
|
||||
assert_eq!(buf.len(), 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_create_id_invalid_chars() {
|
||||
for _ in 1..1000 {
|
||||
let buf = dc_create_id();
|
||||
assert!(!buf.contains('/')); // `/` must not be used to be URL-safe
|
||||
assert!(!buf.contains('.')); // `.` is used as a delimiter when extracting grpid from Message-ID
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dc_extract_grpid_from_rfc724_mid() {
|
||||
// Should return None if we pass invalid mid
|
||||
|
||||
Reference in New Issue
Block a user