securedrop_protocol_minimal/primitives/pad.rs
1use alloc::vec::Vec;
2
3/// Fixed-length padded message length.
4///
5/// Note: I made this up. We should pick something based on actual reasons.
6pub const PADDED_MESSAGE_LEN: usize = 100000;
7
8/// Pad a message to a fixed length
9pub fn pad_message(message: &[u8]) -> Vec<u8> {
10 if message.len() > PADDED_MESSAGE_LEN {
11 // TODO: Handle message truncation or error outside of this function
12 panic!("Message too long for padding");
13 }
14
15 let mut padded = Vec::with_capacity(PADDED_MESSAGE_LEN);
16 padded.extend_from_slice(message);
17
18 // Pad with zeros to reach the fixed length
19 let padding_needed = PADDED_MESSAGE_LEN - message.len();
20 for _ in 0..padding_needed {
21 padded.push(0u8);
22 }
23
24 padded
25}