Skip to content

Commit d0b9638

Browse files
committed
Replace time crate with jiff
1 parent 35cf085 commit d0b9638

File tree

9 files changed

+20
-27
lines changed

9 files changed

+20
-27
lines changed

Cargo.lock

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ignore = "0.4.23"
5959
im-rc = "15.1.0"
6060
indexmap = "2.7.1"
6161
itertools = "0.14.0"
62-
jiff = { version = "0.2.3", default-features = false, features = [ "std" ] }
62+
jiff = { version = "0.2.3", default-features = false, features = [ "std", "serde" ] }
6363
jobserver = "0.1.32"
6464
lazycell = "1.3.0"
6565
libc = "0.2.169"
@@ -102,7 +102,6 @@ snapbox = { version = "0.6.21", features = ["diff", "dir", "term-svg", "regex",
102102
tar = { version = "0.4.43", default-features = false }
103103
tempfile = "3.16.0"
104104
thiserror = "2.0.11"
105-
time = { version = "0.3.37", features = ["parsing", "formatting", "serde"] }
106105
toml = "0.8.20"
107106
toml_edit = { version = "0.22.23", features = ["serde"] }
108107
tracing = { version = "0.1.41", default-features = false, features = ["std"] } # be compatible with rustc_log: https://github.com/rust-lang/rust/blob/e51e98dde6a/compiler/rustc_log/Cargo.toml#L9
@@ -208,7 +207,6 @@ supports-unicode.workspace = true
208207
tar.workspace = true
209208
tempfile.workspace = true
210209
thiserror.workspace = true
211-
time.workspace = true
212210
toml.workspace = true
213211
toml_edit.workspace = true
214212
tracing = { workspace = true, features = ["attributes"] }

crates/cargo-test-support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ flate2.workspace = true
2020
git2.workspace = true
2121
glob.workspace = true
2222
itertools.workspace = true
23+
jiff.workspace = true
2324
pasetors.workspace = true
2425
regex.workspace = true
2526
serde = { workspace = true, features = ["derive"] }
2627
serde_json.workspace = true
2728
snapbox.workspace = true
2829
tar.workspace = true
29-
time.workspace = true
3030
toml.workspace = true
3131
url.workspace = true
3232
walkdir.workspace = true

crates/cargo-test-support/src/registry.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use cargo_util::paths::append;
4949
use cargo_util::Sha256;
5050
use flate2::write::GzEncoder;
5151
use flate2::Compression;
52+
use jiff::{SignedDuration, Timestamp};
5253
use pasetors::keys::{AsymmetricPublicKey, AsymmetricSecretKey};
5354
use pasetors::paserk::FormatAsPaserk;
5455
use pasetors::token::UntrustedToken;
@@ -58,10 +59,9 @@ use std::fs::{self, File};
5859
use std::io::{BufRead, BufReader, Read, Write};
5960
use std::net::{SocketAddr, TcpListener, TcpStream};
6061
use std::path::{Path, PathBuf};
62+
use std::str::FromStr;
6163
use std::thread::{self, JoinHandle};
6264
use tar::{Builder, Header};
63-
use time::format_description::well_known::Rfc3339;
64-
use time::{Duration, OffsetDateTime};
6565
use url::Url;
6666

6767
/// Path to the local index for psuedo-crates.io.
@@ -910,9 +910,9 @@ impl HttpServer {
910910
v: Option<u8>,
911911
}
912912
let message: Message<'_> = t!(serde_json::from_str(trusted_token.payload()).ok());
913-
let token_time = t!(OffsetDateTime::parse(message.iat, &Rfc3339).ok());
914-
let now = OffsetDateTime::now_utc();
915-
if (now - token_time) > Duration::MINUTE {
913+
let token_time = t!(Timestamp::from_str(message.iat).ok());
914+
let now = Timestamp::now();
915+
if now.duration_since(token_time) > SignedDuration::from_mins(1) {
916916
return false;
917917
}
918918
if private_key_subject.as_deref() != message.sub {

credential/cargo-credential/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ description = "A library to assist writing Cargo credential helpers."
1010

1111
[dependencies]
1212
anyhow.workspace = true
13+
jiff.workspace = true
1314
serde = { workspace = true, features = ["derive"] }
1415
serde_json.workspace = true
1516
thiserror.workspace = true
16-
time.workspace = true
1717

1818
[target.'cfg(unix)'.dependencies]
1919
libc.workspace = true

credential/cargo-credential/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
#![allow(clippy::print_stderr)]
4444
#![allow(clippy::print_stdout)]
4545

46+
use jiff::Timestamp;
4647
use serde::{Deserialize, Serialize};
4748
use std::{fmt::Display, io};
48-
use time::OffsetDateTime;
4949

5050
mod error;
5151
mod secret;
@@ -201,10 +201,7 @@ pub enum CacheControl {
201201
/// Do not cache this result.
202202
Never,
203203
/// Cache this result and use it for subsequent requests in the current Cargo invocation until the specified time.
204-
Expires {
205-
#[serde(with = "time::serde::timestamp")]
206-
expiration: OffsetDateTime,
207-
},
204+
Expires { expiration: Timestamp },
208205
/// Cache this result and use it for all subsequent requests in the current Cargo invocation.
209206
Session,
210207
#[serde(other)]
@@ -320,7 +317,7 @@ mod tests {
320317
#[test]
321318
fn cache_control() {
322319
let cc = CacheControl::Expires {
323-
expiration: OffsetDateTime::from_unix_timestamp(1693928537).unwrap(),
320+
expiration: Timestamp::from_second(1693928537).unwrap(),
324321
};
325322
let json = serde_json::to_string(&cc).unwrap();
326323
assert_eq!(json, r#"{"cache":"expires","expiration":1693928537}"#);

src/cargo/util/auth/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use cargo_credential::{
1111
};
1212

1313
use core::fmt;
14+
use jiff::Timestamp;
1415
use serde::Deserialize;
1516
use std::error::Error;
16-
use time::{Duration, OffsetDateTime};
17+
use std::time::Duration;
1718
use url::Url;
1819

1920
use crate::core::SourceId;
@@ -619,7 +620,7 @@ fn auth_token_optional(
619620
if let Some(cached_token) = cache.get(url) {
620621
if cached_token
621622
.expiration
622-
.map(|exp| OffsetDateTime::now_utc() + Duration::minutes(1) < exp)
623+
.map(|exp| Timestamp::now() + Duration::from_secs(60) < exp)
623624
.unwrap_or(true)
624625
{
625626
if cached_token.operation_independent || matches!(operation, Operation::Read) {

src/cargo/util/context/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ use cargo_credential::Secret;
8585
use cargo_util::paths;
8686
use cargo_util_schemas::manifest::RegistryName;
8787
use curl::easy::Easy;
88+
use jiff::Timestamp;
8889
use lazycell::LazyCell;
8990
use serde::de::IntoDeserializer as _;
9091
use serde::Deserialize;
9192
use serde_untagged::UntaggedEnumVisitor;
92-
use time::OffsetDateTime;
9393
use toml_edit::Item;
9494
use url::Url;
9595

@@ -155,7 +155,7 @@ enum WhyLoad {
155155
#[derive(Debug)]
156156
pub struct CredentialCacheValue {
157157
pub token_value: Secret<String>,
158-
pub expiration: Option<OffsetDateTime>,
158+
pub expiration: Option<Timestamp>,
159159
pub operation_independent: bool,
160160
}
161161

src/cargo/util/credential/paseto.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use pasetors::{
99
keys::{AsymmetricKeyPair, AsymmetricPublicKey, AsymmetricSecretKey, Generate},
1010
paserk::FormatAsPaserk,
1111
};
12-
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
1312
use url::Url;
1413

1514
use crate::{
@@ -103,10 +102,10 @@ impl<'a> Credential for PasetoCredential<'a> {
103102
.expose();
104103
let kip: pasetors::paserk::Id = (&public).into();
105104

106-
let iat = OffsetDateTime::now_utc();
105+
let iat = jiff::Timestamp::now();
107106

108107
let message = Message {
109-
iat: &iat.format(&Rfc3339).unwrap(),
108+
iat: &iat.to_string(),
110109
sub: secret_key_subject.as_deref(),
111110
mutation: match operation {
112111
Operation::Publish { .. } => Some("publish"),

0 commit comments

Comments
 (0)