From 7bdf7656ebd5f08d5bb10cbead22498d1131cb07 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 23 Oct 2021 12:24:32 +0200 Subject: [PATCH] parsers/hdrext: Parse the @id as u16 instead of String MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The specification says it can only be in the 1-256, 4096-4351 ranges, so use the closest type available. This doesn’t validate that the value is correct, but that will be done in a future commit. Thanks gst-meet for making me notice this issue! --- parsers/src/jingle_rtp_hdrext.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/parsers/src/jingle_rtp_hdrext.rs b/parsers/src/jingle_rtp_hdrext.rs index 199b4399..23326649 100644 --- a/parsers/src/jingle_rtp_hdrext.rs +++ b/parsers/src/jingle_rtp_hdrext.rs @@ -22,8 +22,10 @@ generate_element!( /// Header extensions to be used in a RTP description. RtpHdrext, "rtp-hdrext", JINGLE_RTP_HDREXT, attributes: [ - /// The ID of the extensions. - id: Required = "id", + /// The ID of the extensions. The allowed values are only in the 1-256, 4096-4351 ranges, + /// this isn’t enforced by xmpp-parsers yet! + // TODO: make it so. + id: Required = "id", /// The URI that defines the extension. uri: Required = "uri", @@ -35,7 +37,7 @@ generate_element!( impl RtpHdrext { /// Create a new RTP header extension element. - pub fn new(id: String, uri: String) -> RtpHdrext { + pub fn new(id: u16, uri: String) -> RtpHdrext { RtpHdrext { id, uri, @@ -60,14 +62,14 @@ mod tests { #[test] fn test_size() { assert_size!(Senders, 1); - assert_size!(RtpHdrext, 28); + assert_size!(RtpHdrext, 16); } #[cfg(target_pointer_width = "64")] #[test] fn test_size() { assert_size!(Senders, 1); - assert_size!(RtpHdrext, 56); + assert_size!(RtpHdrext, 32); } #[test] @@ -79,7 +81,7 @@ mod tests { .parse() .unwrap(); let rtp_hdrext = RtpHdrext::try_from(elem).unwrap(); - assert_eq!(rtp_hdrext.id, "1"); + assert_eq!(rtp_hdrext.id, 1); assert_eq!(rtp_hdrext.uri, "urn:ietf:params:rtp-hdrext:toffset"); assert_eq!(rtp_hdrext.senders, Senders::Both); }