Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
disallowed-methods = [
{ path = "std::slice::from_raw_parts", reason = "see null_safe_slice" }
{ path = "std::slice::from_raw_parts", reason = "see null_safe_slice" },
{ path = "std::time::Instant::now", reason = "time should be provided externally" }
]
disallowed-macros = [
{ path = "std::dbg" }
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn build_nss(dir: PathBuf) {
String::from("--static"),
];
let target = env::var("TARGET").unwrap();
if target.strip_prefix("aarch64-").is_some() {
if target.starts_with("aarch64-") {
build_nss.push(String::from("--target=arm64"));
}
let status = Command::new(get_bash())
Expand Down
8 changes: 4 additions & 4 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ impl SecretAgentPreInfo {
}

#[must_use]
pub const fn alpn(&self) -> Option<&String> {
self.alpn.as_ref()
pub fn alpn(&self) -> Option<&str> {
self.alpn.as_deref()
}
}

Expand Down Expand Up @@ -428,8 +428,8 @@ impl SecretAgentInfo {
self.ech_accepted
}
#[must_use]
pub const fn alpn(&self) -> Option<&String> {
self.alpn.as_ref()
pub fn alpn(&self) -> Option<&str> {
self.alpn.as_deref()
}
#[must_use]
pub const fn signature_scheme(&self) -> SignatureScheme {
Expand Down
4 changes: 2 additions & 2 deletions src/agentio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ impl RecordList {
}

impl Deref for RecordList {
type Target = Vec<Record>;
fn deref(&self) -> &Vec<Record> {
type Target = [Record];
fn deref(&self) -> &[Record] {
&self.records
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ impl CertificateInfo {
}

#[must_use]
pub const fn stapled_ocsp_responses(&self) -> Option<&Vec<Vec<u8>>> {
self.stapled_ocsp_responses.as_ref()
pub fn stapled_ocsp_responses(&self) -> Option<&[Vec<u8>]> {
self.stapled_ocsp_responses.as_deref()
}

#[must_use]
pub const fn signed_cert_timestamp(&self) -> Option<&Vec<u8>> {
self.signed_cert_timestamp.as_ref()
pub fn signed_cert_timestamp(&self) -> Option<&[u8]> {
self.signed_cert_timestamp.as_deref()
}
}
10 changes: 10 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl TimeZero {
/// To avoid that, we make sure that this sets the base time using the first value
/// it sees if it is in the past. If it is not, then use `Instant::now()` instead.
pub fn baseline(t: Instant) -> Self {
#[expect(
clippy::disallowed_methods,
reason = "Special handling for NSPR time conversion"
)]
let now = Instant::now();
let prnow = unsafe { PR_Now() };

Expand All @@ -75,6 +79,10 @@ static BASE_TIME: OnceCell<TimeZero> = OnceCell::new();

fn get_base() -> &'static TimeZero {
BASE_TIME.get_or_init(|| TimeZero {
#[expect(
clippy::disallowed_methods,
reason = "Special handling for NSPR time conversion"
)]
instant: Instant::now(),
prtime: unsafe { PR_Now() },
})
Expand Down Expand Up @@ -256,13 +264,15 @@ mod test {
}

#[test]
#[expect(clippy::disallowed_methods, reason = "Test for special time handling")]
fn timezero_baseline_future() {
let tz = TimeZero::baseline(Instant::now() + Duration::from_secs(10));
let now = Instant::now();
assert!(tz.instant <= now && tz.instant + Duration::from_millis(100) > now);
}

#[test]
#[expect(clippy::disallowed_methods, reason = "Test for special time handling")]
fn timezero_baseline_past() {
let past = Instant::now().checked_sub(Duration::from_secs(5)).unwrap();
assert_eq!(TimeZero::baseline(past).instant, past);
Expand Down
12 changes: 6 additions & 6 deletions tests/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ fn alpn() {
connect(&mut client, &mut server);

let expected = Some(String::from("alpn"));
assert_eq!(expected.as_ref(), client.info().unwrap().alpn());
assert_eq!(expected.as_ref(), server.info().unwrap().alpn());
assert_eq!(expected.as_deref(), client.info().unwrap().alpn());
assert_eq!(expected.as_deref(), server.info().unwrap().alpn());
}

#[test]
Expand Down Expand Up @@ -308,8 +308,8 @@ fn alpn_multi() {
connect(&mut client, &mut server);

let expected = Some(String::from("alpn"));
assert_eq!(expected.as_ref(), client.info().unwrap().alpn());
assert_eq!(expected.as_ref(), server.info().unwrap().alpn());
assert_eq!(expected.as_deref(), client.info().unwrap().alpn());
assert_eq!(expected.as_deref(), server.info().unwrap().alpn());
}

#[test]
Expand All @@ -327,8 +327,8 @@ fn alpn_server_pref() {
connect(&mut client, &mut server);

let expected = Some(String::from("alpn"));
assert_eq!(expected.as_ref(), client.info().unwrap().alpn());
assert_eq!(expected.as_ref(), server.info().unwrap().alpn());
assert_eq!(expected.as_deref(), client.info().unwrap().alpn());
assert_eq!(expected.as_deref(), server.info().unwrap().alpn());
}

#[test]
Expand Down
Loading