mirror of
https://github.com/chatmail/core.git
synced 2026-05-21 15:56:30 +03:00
to_base64: operate on characters instead of bytes to avoid unsafe code
This commit is contained in:
committed by
Floris Bruynooghe
parent
c85f1b20ca
commit
99fababf0b
14
src/key.rs
14
src/key.rs
@@ -180,15 +180,15 @@ impl Key {
|
|||||||
|
|
||||||
let encoded = base64::encode(&buf);
|
let encoded = base64::encode(&buf);
|
||||||
encoded
|
encoded
|
||||||
.as_bytes()
|
.chars()
|
||||||
.chunks(break_every)
|
.enumerate()
|
||||||
.fold(String::new(), |mut res, buf| {
|
.fold(String::new(), |mut res, (i, c)| {
|
||||||
// safe because we are using a base64 encoded string
|
if i > 0 && i % break_every == 0 {
|
||||||
res += unsafe { std::str::from_utf8_unchecked(buf) };
|
res.push(' ')
|
||||||
res += " ";
|
}
|
||||||
|
res.push(c);
|
||||||
res
|
res
|
||||||
})
|
})
|
||||||
.trim()
|
|
||||||
.to_string()
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user