Skip to content

Commit

Permalink
Fix and deprecate now_ms (#534)
Browse files Browse the repository at this point in the history
The simple conversion to nanoseconds was not compatible with the
accurate use of nanoseconds in other parts of ssi.

Also remove specific Rust version for test-each-feature tests in CI to bypass stack overflow issue
  • Loading branch information
sbihel committed Sep 28, 2023
1 parent 6d94132 commit 2e2d393
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ jobs:
with:
submodules: true

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: "1.68.0"
profile: minimal
override: true

- uses: taiki-e/install-action@cargo-hack

- uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 1 addition & 1 deletion examples/issue-revocation-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn main() {
more_properties: serde_json::Value::Null,
};
let mut vc = Credential::try_from(rl_vc).unwrap();
vc.issuance_date = Some(ssi::vc::VCDateTime::from(ssi::ldp::now_ms()));
vc.issuance_date = Some(ssi::vc::VCDateTime::from(ssi::ldp::now_ns()));
let mut proof_options = ssi::vc::LinkedDataProofOptions::default();
let verification_method = "did:example:foo#key1".to_string();
proof_options.verification_method = Some(ssi::vc::URI::String(verification_method));
Expand Down
2 changes: 1 addition & 1 deletion examples/issue-status-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn main() {
more_properties: serde_json::Value::Null,
};
let mut vc = Credential::try_from(rl_vc).unwrap();
vc.issuance_date = Some(ssi::vc::VCDateTime::from(ssi::ldp::now_ms()));
vc.issuance_date = Some(ssi::vc::VCDateTime::from(ssi::ldp::now_ns()));
let mut proof_options = ssi::vc::LinkedDataProofOptions::default();
let verification_method = "did:example:12345#key1".to_string();
proof_options.verification_method = Some(ssi::vc::URI::String(verification_method));
Expand Down
2 changes: 1 addition & 1 deletion examples/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn main() {
"@context": ["https://www.w3.org/2018/credentials/v1"],
"type": "VerifiableCredential",
"issuer": "did:example:foo",
"issuanceDate": ssi::ldp::now_ms(),
"issuanceDate": ssi::ldp::now_ns(),
"credentialSubject": {
"id": "urn:uuid:".to_string() + &uuid::Uuid::new_v4().to_string()
}
Expand Down
2 changes: 1 addition & 1 deletion ssi-ldp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ssi-ldp"
version = "0.3.1"
version = "0.3.2"
edition = "2021"
authors = ["Spruce Systems, Inc."]
license = "Apache-2.0"
Expand Down
9 changes: 7 additions & 2 deletions ssi-ldp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ impl From<Result<VerificationWarnings, Error>> for VerificationResult {
}

// Get current time to millisecond precision if possible
#[deprecated = "Use now_ns instead"]
pub fn now_ms() -> DateTime<Utc> {
now_ns()
}

// Get current time to nanosecond precision if possible
pub fn now_ns() -> DateTime<Utc> {
let datetime = Utc::now();
let ms = datetime.timestamp_subsec_millis();
let ns = ms * 1_000_000;
let ns = datetime.timestamp_subsec_nanos();
datetime.with_nanosecond(ns).unwrap_or(datetime)
}

Expand Down
6 changes: 3 additions & 3 deletions ssi-ldp/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Proof {
.map(|uri| uri.to_string()),
domain: options.domain.clone(),
challenge: options.challenge.clone(),
created: Some(options.created.unwrap_or_else(now_ms)),
created: Some(options.created.unwrap_or_else(now_ns)),
..self
}
}
Expand All @@ -114,7 +114,7 @@ impl Proof {
);
}
if let Some(created) = self.created {
assert_local!(options.created.unwrap_or_else(now_ms) >= created);
assert_local!(options.created.unwrap_or_else(now_ns) >= created);
} else {
return false;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ impl Default for LinkedDataProofOptions {
Self {
verification_method: None,
proof_purpose: Some(ProofPurpose::default()),
created: Some(crate::now_ms()),
created: Some(crate::now_ns()),
challenge: None,
domain: None,
checks: Some(vec![Check::Proof]),
Expand Down
1 change: 0 additions & 1 deletion ssi-vc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,6 @@ _:c14n0 <https://w3id.org/security#verificationMethod> <https://example.org/foo/
.await
.unwrap();
let vp_jwt_verify_options = LinkedDataProofOptions {
created: None,
checks: None,
proof_purpose: None,
..Default::default()
Expand Down

0 comments on commit 2e2d393

Please sign in to comment.