docs(irtt-proto): add runnable doctests for public API
Add executable doctests documenting the consumer-facing contract of irtt-proto: the directional request encode/decode/verify split, Params construction and round-trip, omitted-vs-explicit-zero presence, open and echo reply round trips, packet length calculation, and HMAC verification. No conventional tests are migrated: every existing irtt-proto test exercises wire vectors, flag matrices, malformed input, layout rules, HMAC error behavior, or encode/decode round trips, which the crate's AGENTS.md treats as durable compatibility coverage rather than documentation cleanup targets.
This commit is contained in:
8 files changed
+236
No files matched your search
@@ -68,6 +68,23 @@ pub fn verify_hmac(key: &[u8], packet: &[u8], hmac_offset: usize) -> Result<()>
|
||||
/// [`ProtoError::InvalidHmacOffset`] when the field is truncated, and
|
||||
/// [`ProtoError::BadHmac`] when the MAC does not match. The packet is never
|
||||
/// modified.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use irtt_proto::{encode_request, verify_packet_hmac, Params, RequestToEncode};
|
||||
///
|
||||
/// // Synthetic example key — use a real shared secret in production.
|
||||
/// let key = b"example key";
|
||||
/// let params = Params::with_protocol_defaults();
|
||||
/// let packet = encode_request(
|
||||
/// RequestToEncode::Open { params: ¶ms, no_test: false },
|
||||
/// Some(key),
|
||||
/// ).unwrap();
|
||||
///
|
||||
/// verify_packet_hmac(key, &packet).unwrap();
|
||||
/// assert!(verify_packet_hmac(b"wrong key", &packet).is_err());
|
||||
/// ```
|
||||
pub fn verify_packet_hmac(key: &[u8], packet: &[u8]) -> Result<()> {
|
||||
let envelope = envelope::decode_structural(packet)?;
|
||||
if !envelope.hmac_present {
|
||||
|
||||
Reference in new issue
Block a user