Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 069c3b3

Browse files
committed
chore: fix compiler warnings & stability bugs, bump ver
fix: wasm build fix: move serial_number.rs to not be affected by types feature asfdfasdasdfasdf
1 parent 0ca0c3f commit 069c3b3

File tree

12 files changed

+82
-10
lines changed

12 files changed

+82
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "polyproto"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
edition = "2024"
55
license = "MPL-2.0"
66
description = "(Generic) Rust types and traits to quickly get a polyproto implementation up and running"
@@ -71,7 +71,6 @@ rand = "0.8.5"
7171
serde = { version = "1.0.219", features = ["derive"] }
7272
serde_json = { version = "1.0.140" }
7373
serde_test = "1.0.177"
74-
polyproto = { path = "./", features = ["types", "reqwest", "serde"] }
7574
env_logger = "0.11.7"
7675

7776
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]

examples/ed25519_basic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// This example is not complete and should not be copy-pasted into a production environment without
77
// further scrutiny and consideration.
88

9+
#![allow(clippy::unwrap_used)]
10+
911
use std::str::FromStr;
1012

1113
use der::asn1::BitString;

examples/ed25519_cert.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
#![allow(clippy::unwrap_used)]
6+
57
use std::str::FromStr;
68
use std::time::Duration;
79

examples/ed25519_from_der.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
#![allow(clippy::unwrap_used)]
6+
57
use std::str::FromStr;
68
use std::time::Duration;
79

examples/http_api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
#![allow(clippy::unwrap_used, clippy::arithmetic_side_effects)]
6+
57
use std::str::FromStr;
68

79
use der::asn1::BitString;

src/api/core/federated_identity.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ mod registration_required {
3232
match id_cert.full_verify_home_server(
3333
std::time::SystemTime::now()
3434
.duration_since(UNIX_EPOCH)
35-
.unwrap()
35+
.map_err(|e| RequestError::Custom {
36+
reason: e.to_string(),
37+
})?
3638
.as_secs(),
3739
) {
3840
Ok(_) => (),

src/api/core/migration.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ mod registration_not_required {
248248
}
249249
let request = request.build()?;
250250
let response = self.send_request(request).await?;
251+
#[allow(clippy::unwrap_used)] // HeaderValue::from_str("0") is always valid.
251252
let return_body_size_string = response
252253
.headers()
253254
.get("X-P2-Return-Body-Size-Limit")
@@ -350,3 +351,14 @@ mod registration_not_required {
350351
}
351352
}
352353
}
354+
355+
#[cfg(test)]
356+
mod test {
357+
use http::HeaderValue;
358+
359+
#[test]
360+
#[allow(clippy::unwrap_used)]
361+
fn header_value_zero() {
362+
HeaderValue::from_str("0").unwrap();
363+
}
364+
}

src/certs/capabilities/basic_constraints.rs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ impl TryFrom<Attribute> for BasicConstraints {
5959
.into());
6060
}
6161
let values = value.values;
62-
if values.len() != 1usize {
62+
let element = if let Some(item) = values.get(0) {
63+
item
64+
} else {
6365
return Err(CertificateConversionError::InvalidInput(
6466
InvalidInput::Length {
6567
min_length: 1,
6668
max_length: 1,
6769
actual_length: values.len().to_string(),
6870
},
6971
));
70-
}
71-
let element = values.get(0).expect("This should be infallible. Report this issue at https://github.com/polyphony-chat/polyproto");
72+
};
7273
if element.tag() != Tag::Sequence {
7374
return Err(CertificateConversionError::InvalidInput(
7475
InvalidInput::Malformed(format!(
@@ -86,6 +87,7 @@ impl TryFrom<Attribute> for BasicConstraints {
8687
match value.tag() {
8788
Tag::Boolean => {
8889
// Keep track of how many Boolean tags we encounter
90+
#[allow(clippy::arithmetic_side_effects)] // last i checked, 0 + 1 = 1 < 255
8991
if num_ca == 0 {
9092
num_ca += 1;
9193
ca = any_to_bool(value.clone())?;
@@ -99,6 +101,7 @@ impl TryFrom<Attribute> for BasicConstraints {
99101
}
100102
Tag::Integer => {
101103
// Keep track of how many Integer tags we encounter
104+
#[allow(clippy::arithmetic_side_effects)]
102105
if num_path_length == 0 {
103106
num_path_length += 1;
104107
path_length = Some(any_to_u64(value.clone())?);
@@ -218,16 +221,62 @@ impl TryFrom<Extension> for BasicConstraints {
218221
let mut path_length: Option<u64> = None;
219222
for item in sequence.iter() {
220223
match item.tag() {
224+
// TODO: lots of repetition. I do not like repetition.
221225
Tag::Boolean => {
222-
bool_encounters += 1;
226+
bool_encounters = match bool_encounters.checked_add(1) {
227+
Some(new) => new,
228+
None => return Err(CertificateConversionError::InvalidCert(
229+
crate::errors::InvalidCert::InvalidProperties(
230+
ConstraintError::OutOfBounds
231+
{
232+
lower: 0,
233+
upper: 255,
234+
actual: "> 255".to_owned(),
235+
reason:
236+
"Encountered a suspicious amount of tags in this certificate extension"
237+
.to_owned()
238+
})
239+
)
240+
),
241+
};
223242
ca = any_to_bool(item.clone())?;
224243
}
225244
Tag::Integer => {
226-
int_encounters += 1;
245+
int_encounters = match int_encounters.checked_add(1) {
246+
Some(new) => new,
247+
None => return Err(CertificateConversionError::InvalidCert(
248+
crate::errors::InvalidCert::InvalidProperties(
249+
ConstraintError::OutOfBounds
250+
{
251+
lower: 0,
252+
upper: 255,
253+
actual: "> 255".to_owned(),
254+
reason:
255+
"Encountered a suspicious amount of tags in this certificate extension"
256+
.to_owned()
257+
})
258+
)
259+
),
260+
};
227261
path_length = Some(any_to_u64(item.clone())?);
228262
}
229263
Tag::Null => {
230-
null_encounters += 1;
264+
null_encounters = match null_encounters.checked_add(1) {
265+
Some(new) => new,
266+
None => return Err(CertificateConversionError::InvalidCert(
267+
crate::errors::InvalidCert::InvalidProperties(
268+
ConstraintError::OutOfBounds
269+
{
270+
lower: 0,
271+
upper: 255,
272+
actual: "> 255".to_owned(),
273+
reason:
274+
"Encountered a suspicious amount of tags in this certificate extension"
275+
.to_owned()
276+
})
277+
)
278+
),
279+
};
231280
path_length = None;
232281
}
233282
_ => {
@@ -291,6 +340,7 @@ fn any_to_u64(value: Any) -> Result<u64, ConstraintError> {
291340
// into a u64.
292341
let mut buf = [0u8; 8];
293342
let len = 8.min(value.value().len());
343+
#[allow(clippy::indexing_slicing)] // This is fine as long as len <= 8, which is true.
294344
buf[..len].copy_from_slice(value.value());
295345
Ok(u64::from_be_bytes(buf))
296346
}

src/constraints/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
mod capabilities;
2323
mod certs;
2424
mod name;
25+
mod serial_number;
2526
mod session_id;
2627
#[cfg(feature = "types")]
2728
mod types;

0 commit comments

Comments
 (0)