// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // Copyright by contributors to this project. // SPDX-License-Identifier: (Apache-2.0 OR MIT)
/// Padding used when sending an encrypted group message. #[cfg_attr(all(feature = "ffi", not(test)), safer_ffi_gen::ffi_type)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] #[repr(u8)] pubenum PaddingMode { /// Step function based on the size of the message being sent. /// The amount of padding used will increase with the size of the original /// message. #[default]
StepFunction, /// No padding.
None,
}
impl PaddingMode { pub(super) fn padded_size(&self, content_size: usize) -> usize { matchself {
PaddingMode::StepFunction => { // The padding hides all but 2 most significant bits of `length`. The hidden bits are replaced // by zeros and then the next number is taken to make sure the message fits. let blind = 1
<< ((content_size + 1)
.next_power_of_two()
.max(256)
.trailing_zeros()
- 3);
// Short
assert_eq!(PaddingMode::StepFunction.padded_size(63), 64);
assert_eq!(PaddingMode::StepFunction.padded_size(64), 96);
assert_eq!(PaddingMode::StepFunction.padded_size(65), 96);
// Almost long and almost short
assert_eq!(PaddingMode::StepFunction.padded_size(127), 128);
assert_eq!(PaddingMode::StepFunction.padded_size(128), 160);
assert_eq!(PaddingMode::StepFunction.padded_size(129), 160);
// One length from each of the 4 buckets between 256 and 512
assert_eq!(PaddingMode::StepFunction.padded_size(260), 320);
assert_eq!(PaddingMode::StepFunction.padded_size(330), 384);
assert_eq!(PaddingMode::StepFunction.padded_size(390), 448);
assert_eq!(PaddingMode::StepFunction.padded_size(490), 512);
// All test cases let test_cases: Vec<TestCase> = load_test_cases(); for test_case in test_cases {
assert_eq!(
test_case.output,
PaddingMode::StepFunction.padded_size(test_case.input)
);
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.