← Watch feed
test(core): add unittests for `StrBuffer` slicing
What changed, and why it matters
This commit only adds new unit tests for an existing string buffer slicing feature. It does not change any production code, fix a bug, or introduce new functionality. There is no security relevance.
Recommended action
No action needed. This is a test-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a Rust test module (#[cfg(test)] mod tests) in core/embed/rust/src/micropython/buffer.rs. It tests StrBuffer::prefix() and StrBuffer::skip_prefix() using a static string. No implementation code is modified.
Changed components
core/embed/rust/src/micropython/buffer.rsInspect captured patch +25 / −0
diff --git a/core/embed/rust/src/micropython/buffer.rs b/core/embed/rust/src/micropython/buffer.rs
index 5b9a6b8aa..9c807041b 100644
--- a/core/embed/rust/src/micropython/buffer.rs
+++ b/core/embed/rust/src/micropython/buffer.rs
@@ -282,3 +282,28 @@ pub fn hexlify_bytes(obj: Obj, offset: usize, max_len: usize) -> Result<StrBuffe
let result = StrBuffer::alloc_with(hex_len, move |buffer| hexlify(bin_slice, buffer))?;
Ok(result.skip_prefix(hex_off))
}
+
+#[cfg(test)]
+mod tests {
+
+ #[test]
+ fn test_slicing() {
+ use super::StrBuffer;
+
+ let data = "abcdef";
+ // SAFETY: data is static.
+ let buf = unsafe { StrBuffer::from_ptr_and_len(data.as_ptr(), data.len()) };
+
+ assert_eq!(buf.prefix(0).as_ref(), "");
+ assert_eq!(buf.prefix(3).as_ref(), "abc");
+ assert_eq!(buf.prefix(buf.len()).as_ref(), data);
+
+ assert_eq!(buf.skip_prefix(0).as_ref(), data);
+ assert_eq!(buf.skip_prefix(3).as_ref(), "def");
+ assert_eq!(buf.skip_prefix(1).skip_prefix(2).as_ref(), "def");
+ assert_eq!(buf.skip_prefix(buf.len()).as_ref(), "");
+
+ assert_eq!(buf.skip_prefix(2).prefix(2).as_ref(), "cd");
+ assert_eq!(buf.prefix(4).skip_prefix(2).as_ref(), "cd");
+ }
+}
Risk score
Our methodology →Why this scored 15/100
Human-validated context
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
No validated notes yet.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.