Skip to content

Commit ba492b5

Browse files
fix(psl): satisfy clippy::expect_used and rustfmt in DAFSA reader
Crate denies clippy::expect_used outside tests; the version parse now propagates BadMagic on UTF-8 failure even though the bytes were already validated as ASCII digits. Also rustfmt reflow of test code.
1 parent 99614e5 commit ba492b5

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

  • libwebauthn/src/ops/webauthn/psl

libwebauthn/src/ops/webauthn/psl/dafsa.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn parse_header(bytes: &[u8]) -> Result<Vec<u8>, DafsaFileLoadError> {
123123
return Err(DafsaFileLoadError::BadMagic);
124124
}
125125
let version: u32 = std::str::from_utf8(&version_field[..digit_count])
126-
.expect("ascii digits are valid utf-8")
126+
.map_err(|_| DafsaFileLoadError::BadMagic)?
127127
.parse()
128128
.map_err(|_| DafsaFileLoadError::BadMagic)?;
129129
if version != 0 {
@@ -257,7 +257,8 @@ mod tests {
257257
0x0a, // header
258258
0x05, 0x03, 0x0a, 0x07, 0x87, // root offset list
259259
0x6b, 0x77, 0x86, // kw, flag 6 = WILDCARD | ICANN
260-
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x69, 0x6f, 0x88, // github.io, flag 8 = PRIVATE
260+
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x69, 0x6f,
261+
0x88, // github.io, flag 8 = PRIVATE
261262
0x66, 0x6f, 0x6f, 0x2e, 0x6b, 0x77, 0x85, // foo.kw, flag 5 = EXCEPTION | ICANN
262263
0x63, 0xef, // c + end_char 'o'
263264
0x02, 0x82, // offsets for "com" and "co.uk" branches
@@ -317,7 +318,10 @@ mod tests {
317318
#[test]
318319
fn public_suffix_wildcard_synthesis() {
319320
let psl = loaded();
320-
assert_eq!(psl.public_suffix("anything.kw").as_deref(), Some("anything.kw"));
321+
assert_eq!(
322+
psl.public_suffix("anything.kw").as_deref(),
323+
Some("anything.kw")
324+
);
321325
assert_eq!(psl.public_suffix("a.b.kw").as_deref(), Some("b.kw"));
322326
}
323327

@@ -383,7 +387,10 @@ mod tests {
383387
fn parse_header_rejects_bad_magic() {
384388
let mut bad = FIXTURE.to_vec();
385389
bad[0] = b'X';
386-
assert!(matches!(parse_header(&bad), Err(DafsaFileLoadError::BadMagic)));
390+
assert!(matches!(
391+
parse_header(&bad),
392+
Err(DafsaFileLoadError::BadMagic)
393+
));
387394
}
388395

389396
#[test]
@@ -400,6 +407,9 @@ mod tests {
400407
fn parse_header_rejects_missing_newline() {
401408
let mut bad = FIXTURE.to_vec();
402409
bad[HEADER_LEN - 1] = b' ';
403-
assert!(matches!(parse_header(&bad), Err(DafsaFileLoadError::BadMagic)));
410+
assert!(matches!(
411+
parse_header(&bad),
412+
Err(DafsaFileLoadError::BadMagic)
413+
));
404414
}
405415
}

0 commit comments

Comments
 (0)