From ba9af4931c74e17830b0cb676039a1c31c5970a1 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 14 Sep 2026 12:43:36 -0700 Subject: [PATCH] Use lowercase hex literals --- src/encoder.rs | 2 +- src/flac_builder.rs | 2 +- src/flac_decoder.rs | 2 +- src/head.rs | 18 +++++++++--------- src/jpeg_builder.rs | 4 ++-- src/mp3_builder.rs | 10 +++++----- src/mp3_decoder.rs | 28 ++++++++++++++-------------- src/mp4_decoder.rs | 10 +++++----- src/orientation.rs | 10 +++++----- src/webm_builder.rs | 34 +++++++++++++++++----------------- src/webm_decoder.rs | 14 +++++++------- 11 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/encoder.rs b/src/encoder.rs index e64fbcd2..f018e47d 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -36,7 +36,7 @@ impl Encoder { for &byte in len.to_le_bytes()[..count].iter().rev() { self.buffer.push_front(byte); } - self.buffer.push_front((0xEF + count).try_into().unwrap()); + self.buffer.push_front((0xef + count).try_into().unwrap()); } Head::Reserved(value) => self.buffer.push_front(value), } diff --git a/src/flac_builder.rs b/src/flac_builder.rs index cd9f5315..eb490495 100644 --- a/src/flac_builder.rs +++ b/src/flac_builder.rs @@ -11,7 +11,7 @@ impl FlacBuilder { streaminfo.extend_from_slice(&4096u16.to_be_bytes()); streaminfo.extend_from_slice(&4096u16.to_be_bytes()); streaminfo.extend_from_slice(&[0; 6]); - streaminfo.extend_from_slice(&[0x0A, 0xC4, 0x42, 0xF0]); + streaminfo.extend_from_slice(&[0x0a, 0xc4, 0x42, 0xf0]); streaminfo.extend_from_slice(&self.samples.to_be_bytes()); streaminfo.extend_from_slice(&[0; 16]); diff --git a/src/flac_decoder.rs b/src/flac_decoder.rs index e9c2604f..a21d9701 100644 --- a/src/flac_decoder.rs +++ b/src/flac_decoder.rs @@ -54,7 +54,7 @@ impl<'a> Iterator for Blocks<'a> { Some(Ok(Block { body, end, - ty: header[0] & 0x7F, + ty: header[0] & 0x7f, })) } } diff --git a/src/head.rs b/src/head.rs index 01f77295..971594cd 100644 --- a/src/head.rs +++ b/src/head.rs @@ -54,7 +54,7 @@ impl Head { Self::Medium(len) => { if len == 1 { ensure! { - *buffer.get(1).context(decode_error::Truncated)? > 0x7F, + *buffer.get(1).context(decode_error::Truncated)? > 0x7f, decode_error::Overlong, } } @@ -76,7 +76,7 @@ impl Head { if count == 1 { ensure! { - len > 0x6F, + len > 0x6f, decode_error::Overlong, } } @@ -92,9 +92,9 @@ impl From for Head { fn from(head: u8) -> Self { match head { 0x00..0x80 => Self::Small, - 0x80..0xF0 => Self::Medium((head - 0x80).into()), - 0xF0..0xF8 => Self::Large((head - 0xEF).into()), - 0xF8..=0xFF => Self::Reserved(head), + 0x80..0xf0 => Self::Medium((head - 0x80).into()), + 0xf0..0xf8 => Self::Large((head - 0xef).into()), + 0xf8..=0xff => Self::Reserved(head), } } } @@ -130,13 +130,13 @@ mod tests { #[test] fn head_parse() { - for i in 0..=0xFF { + for i in 0..=0xff { let head = Head::from(i); match i { 0x00..0x80 => assert_eq!(head, Head::Small), - 0x80..0xF0 => assert_eq!(head, Head::Medium((i - 0x80).into())), - 0xF0..0xF8 => assert_eq!(head, Head::Large((i - 0xEF).into())), - 0xF8..=0xFF => assert_eq!(head, Head::Reserved(i)), + 0x80..0xf0 => assert_eq!(head, Head::Medium((i - 0x80).into())), + 0xf0..0xf8 => assert_eq!(head, Head::Large((i - 0xef).into())), + 0xf8..=0xff => assert_eq!(head, Head::Reserved(i)), } } } diff --git a/src/jpeg_builder.rs b/src/jpeg_builder.rs index 1cc32088..7a28038e 100644 --- a/src/jpeg_builder.rs +++ b/src/jpeg_builder.rs @@ -14,7 +14,7 @@ pub(crate) struct JpegBuilder { impl JpegBuilder { fn app1(header: &[u8], payload: &[u8]) -> Vec { - let mut segment = vec![0xFF, 0xE1]; + let mut segment = vec![0xff, 0xe1]; segment.extend_from_slice( &u16::try_from(header.len() + payload.len() + 2) .unwrap() @@ -39,7 +39,7 @@ impl JpegBuilder { let mut bytes = buffer.into_inner(); if let Some(sampling) = self.sampling { - let sof = bytes.windows(2).position(|w| w == [0xFF, 0xC0]).unwrap(); + let sof = bytes.windows(2).position(|w| w == [0xff, 0xc0]).unwrap(); bytes[sof + 11] = sampling; } diff --git a/src/mp3_builder.rs b/src/mp3_builder.rs index b0ecfbeb..f510716f 100644 --- a/src/mp3_builder.rs +++ b/src/mp3_builder.rs @@ -102,7 +102,7 @@ impl Mp3Builder { } fn standard() -> Vec { - let mut bytes = vec![0xFF, 0xFB, 0x90, 0x00]; + let mut bytes = vec![0xff, 0xfb, 0x90, 0x00]; bytes.resize(417, 0); bytes } @@ -110,10 +110,10 @@ impl Mp3Builder { fn syncsafe(n: usize) -> [u8; 4] { let n = u32::try_from(n).unwrap(); [ - u8::try_from((n >> 21) & 0x7F).unwrap(), - u8::try_from((n >> 14) & 0x7F).unwrap(), - u8::try_from((n >> 7) & 0x7F).unwrap(), - u8::try_from(n & 0x7F).unwrap(), + u8::try_from((n >> 21) & 0x7f).unwrap(), + u8::try_from((n >> 14) & 0x7f).unwrap(), + u8::try_from((n >> 7) & 0x7f).unwrap(), + u8::try_from(n & 0x7f).unwrap(), ] } diff --git a/src/mp3_decoder.rs b/src/mp3_decoder.rs index f83c0b3c..1e5d4b9a 100644 --- a/src/mp3_decoder.rs +++ b/src/mp3_decoder.rs @@ -86,7 +86,7 @@ impl<'a> Mp3Decoder<'a> { .unwrap(); ensure! { - header[0] == 0xFF && header[1] & 0xE0 == 0xE0, + header[0] == 0xff && header[1] & 0xe0 == 0xe0, mp3_error::Sync { offset }, } @@ -479,44 +479,44 @@ mod tests { ); case( - Mp3Builder::new().frame([0xFF, 0xEB, 0x90, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xeb, 0x90, 0x00], 417), Mp3Error::Version, ); case( - Mp3Builder::new().frame([0xFF, 0xF9, 0x90, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xf9, 0x90, 0x00], 417), Mp3Error::LayerInvalid, ); case( - Mp3Builder::new().frame([0xFF, 0xFD, 0x90, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xfd, 0x90, 0x00], 417), Mp3Error::LayerUnsupported { layer: 2 }, ); case( - Mp3Builder::new().frame([0xFF, 0xFF, 0x90, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xff, 0x90, 0x00], 417), Mp3Error::LayerUnsupported { layer: 1 }, ); case( - Mp3Builder::new().frame([0xFF, 0xFB, 0x00, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xfb, 0x00, 0x00], 417), Mp3Error::Bitrate { index: 0 }, ); case( - Mp3Builder::new().frame([0xFF, 0xFB, 0xF0, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xfb, 0xf0, 0x00], 417), Mp3Error::Bitrate { index: 15 }, ); case( - Mp3Builder::new().frame([0xFF, 0xFB, 0x9C, 0x00], 417), + Mp3Builder::new().frame([0xff, 0xfb, 0x9c, 0x00], 417), Mp3Error::SampleRate, ); case( Mp3Builder::new() .frames(1) - .frame([0xFF, 0xFB, 0x90, 0xC0], 417), + .frame([0xff, 0xfb, 0x90, 0xc0], 417), Mp3Error::ChannelsMismatch { actual: 1, expected: 2, @@ -526,7 +526,7 @@ mod tests { case( Mp3Builder::new() .frames(1) - .frame([0xFF, 0xFB, 0x94, 0x00], 384), + .frame([0xff, 0xfb, 0x94, 0x00], 384), Mp3Error::SampleRateMismatch { actual: 48000, expected: 44100, @@ -597,7 +597,7 @@ mod tests { case( Mp3Builder::new() - .frame([0xFF, 0xFB, 0x92, 0x00], 418) + .frame([0xff, 0xfb, 0x92, 0x00], 418) .frames(1), AudioProperties { channels: 2, @@ -608,7 +608,7 @@ mod tests { ); case( - Mp3Builder::new().frame([0xFF, 0xFB, 0x90, 0xC0], 417), + Mp3Builder::new().frame([0xff, 0xfb, 0x90, 0xc0], 417), AudioProperties { channels: 1, sample_rate: 44100, @@ -618,7 +618,7 @@ mod tests { ); case( - Mp3Builder::new().frame([0xFF, 0xF3, 0x90, 0x00], 261), + Mp3Builder::new().frame([0xff, 0xf3, 0x90, 0x00], 261), AudioProperties { channels: 2, sample_rate: 22050, @@ -628,7 +628,7 @@ mod tests { ); case( - Mp3Builder::new().frame([0xFF, 0xE3, 0x90, 0x00], 522), + Mp3Builder::new().frame([0xff, 0xe3, 0x90, 0x00], 522), AudioProperties { channels: 2, sample_rate: 11025, diff --git a/src/mp4_decoder.rs b/src/mp4_decoder.rs index ead12fff..40438235 100644 --- a/src/mp4_decoder.rs +++ b/src/mp4_decoder.rs @@ -311,11 +311,11 @@ mod tests { Some(config(8, ChromaSubsampling::Yuv420)), ); case( - &[0x67, 100, 0, 31, 0xA6], + &[0x67, 100, 0, 31, 0xa6], Some(config(10, ChromaSubsampling::Yuv420)), ); case( - &[0x67, 100, 0, 31, 0xB8], + &[0x67, 100, 0, 31, 0xb8], Some(config(8, ChromaSubsampling::Yuv422)), ); case( @@ -323,11 +323,11 @@ mod tests { Some(config(8, ChromaSubsampling::Yuv444)), ); case( - &[0x67, 100, 0, 31, 0xE0], + &[0x67, 100, 0, 31, 0xe0], Some(config(8, ChromaSubsampling::Yuv400)), ); case( - &[0x67, 100, 0, 0, 0x03, 0xA6], + &[0x67, 100, 0, 0, 0x03, 0xa6], Some(config(10, ChromaSubsampling::Yuv420)), ); case(&[0x67, 100, 0, 31], None); @@ -475,7 +475,7 @@ mod tests { assert_eq!( case( Mp4Builder::new() - .sps(&[0x67, 100, 0, 31, 0xA6]) + .sps(&[0x67, 100, 0, 31, 0xa6]) .video_track(2, 1), ) .unwrap() diff --git a/src/orientation.rs b/src/orientation.rs index c14373c7..26cd0864 100644 --- a/src/orientation.rs +++ b/src/orientation.rs @@ -168,7 +168,7 @@ mod tests { fn from_exif_big_endian() { assert_eq!( Orientation::from_exif(&[ - 0x4D, 0x4D, 0x00, 0x2A, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x12, 0x00, 0x03, 0x00, + 0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x01, 0x12, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]) .unwrap(), @@ -194,15 +194,15 @@ mod tests { case(b"foo", "invalid byte order"); case(b"II", "truncated EXIF data"); case( - &[0x49, 0x49, 0x2B, 0x00, 0x08, 0x00, 0x00, 0x00], + &[0x49, 0x49, 0x2b, 0x00, 0x08, 0x00, 0x00, 0x00], "expected magic 42 but found 43", ); case( - &[0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00], + &[0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00], "truncated EXIF data", ); case( - &[0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00], + &[0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00], "truncated EXIF data", ); case(&exif(0), "invalid orientation value 0"); @@ -226,7 +226,7 @@ mod tests { assert_eq!( Orientation::from_exif(&[ - 0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]) .unwrap(), Orientation::new(), diff --git a/src/webm_builder.rs b/src/webm_builder.rs index f951c4cd..68355b84 100644 --- a/src/webm_builder.rs +++ b/src/webm_builder.rs @@ -10,10 +10,10 @@ pub(crate) struct WebmBuilder { impl WebmBuilder { pub(crate) fn audio_settings(channels: u64, sampling_frequency: f64) -> Vec { Self::element( - &[0xE1], + &[0xe1], &[ - Self::unsigned(&[0x9F], channels), - Self::float(&[0xB5], sampling_frequency), + Self::unsigned(&[0x9f], channels), + Self::float(&[0xb5], sampling_frequency), ] .concat(), ) @@ -36,7 +36,7 @@ impl WebmBuilder { let info = [ self .timestamp_scale - .map(|timestamp_scale| Self::unsigned(&[0x2A, 0xD7, 0xB1], timestamp_scale)) + .map(|timestamp_scale| Self::unsigned(&[0x2a, 0xd7, 0xb1], timestamp_scale)) .unwrap_or_default(), self .duration @@ -45,22 +45,22 @@ impl WebmBuilder { self .title .as_deref() - .map(|title| Self::string(&[0x7B, 0xA9], title)) + .map(|title| Self::string(&[0x7b, 0xa9], title)) .unwrap_or_default(), - Self::string(&[0x4D, 0x80], "foo"), + Self::string(&[0x4d, 0x80], "foo"), Self::string(&[0x57, 0x41], "bar"), ] .concat(); let segment = [ - Self::element(&[0x15, 0x49, 0xA9, 0x66], &info), - Self::element(&[0x16, 0x54, 0xAE, 0x6B], &self.tracks.concat()), - Self::element(&[0x1F, 0x43, 0xB6, 0x75], &self.blocks.concat()), + Self::element(&[0x15, 0x49, 0xa9, 0x66], &info), + Self::element(&[0x16, 0x54, 0xae, 0x6b], &self.tracks.concat()), + Self::element(&[0x1f, 0x43, 0xb6, 0x75], &self.blocks.concat()), ] .concat(); [ - Self::element(&[0x1A, 0x45, 0xDF, 0xA3], &header), + Self::element(&[0x1a, 0x45, 0xdf, 0xa3], &header), Self::element(&[0x18, 0x53, 0x80, 0x67], &segment), ] .concat() @@ -97,7 +97,7 @@ impl WebmBuilder { payload.push(0x80); payload.extend_from_slice(data); - self.blocks.push(Self::element(&[0xA3], &payload)); + self.blocks.push(Self::element(&[0xa3], &payload)); self } @@ -140,15 +140,15 @@ impl WebmBuilder { let number = u64::try_from(self.tracks.len() + 1).unwrap(); let entry = [ - Self::unsigned(&[0xD7], number), - Self::unsigned(&[0x73, 0xC5], number), + Self::unsigned(&[0xd7], number), + Self::unsigned(&[0x73, 0xc5], number), Self::unsigned(&[0x83], ty), Self::string(&[0x86], codec_id), settings.to_vec(), ] .concat(); - self.tracks.push(Self::element(&[0xAE], &entry)); + self.tracks.push(Self::element(&[0xae], &entry)); self } @@ -159,10 +159,10 @@ impl WebmBuilder { pub(crate) fn video_settings(width: u64, height: u64) -> Vec { Self::element( - &[0xE0], + &[0xe0], &[ - Self::unsigned(&[0xB0], width), - Self::unsigned(&[0xBA], height), + Self::unsigned(&[0xb0], width), + Self::unsigned(&[0xba], height), ] .concat(), ) diff --git a/src/webm_decoder.rs b/src/webm_decoder.rs index bf374e14..7f379869 100644 --- a/src/webm_decoder.rs +++ b/src/webm_decoder.rs @@ -672,24 +672,24 @@ mod tests { Some(config(12, ChromaSubsampling::Yuv420)), ); case( - &[0xA2, 0x49, 0x83, 0x42, 0x08], + &[0xa2, 0x49, 0x83, 0x42, 0x08], Some(config(8, ChromaSubsampling::Yuv422)), ); case( - &[0xA2, 0x49, 0x83, 0x42, 0x04], + &[0xa2, 0x49, 0x83, 0x42, 0x04], Some(config(8, ChromaSubsampling::Yuv440)), ); case( - &[0xA2, 0x49, 0x83, 0x42, 0x00], + &[0xa2, 0x49, 0x83, 0x42, 0x00], Some(config(8, ChromaSubsampling::Yuv444)), ); case( - &[0xA2, 0x49, 0x83, 0x42, 0xE0], + &[0xa2, 0x49, 0x83, 0x42, 0xe0], Some(config(8, ChromaSubsampling::Yuv444)), ); - case(&[0xA2, 0x49, 0x83, 0x42, 0x0C], None); - case(&[0xA2, 0x49, 0x83, 0x42, 0x0A], None); - case(&[0x82, 0x49, 0x83, 0x42, 0xE0], None); + case(&[0xa2, 0x49, 0x83, 0x42, 0x0c], None); + case(&[0xa2, 0x49, 0x83, 0x42, 0x0a], None); + case(&[0x82, 0x49, 0x83, 0x42, 0xe0], None); case(&[0x82, 0x49, 0x83, 0x42], None); case(&[0x84, 0x49, 0x83, 0x42], None); case(&[0x88, 0x49, 0x83, 0x42], None);