From f22351b64140ea6e276e1ad55133ab94fc4ef986 Mon Sep 17 00:00:00 2001 From: tristanmiller-spruceid <143444359+tristanmiller-spruceid@users.noreply.github.com> Date: Mon, 18 Sep 2023 08:43:26 -0600 Subject: [PATCH] Bump CI MSRV and fix new warnings (#530) Because time crate now requires v1.67 Also: - Fix new clippy warning uninlined-format-args - Replace deprecated chrono function with same implementation --------- Co-authored-by: Simon Bihel --- .github/workflows/build.yml | 2 +- did-ethr/src/lib.rs | 6 ++-- did-ion/src/sidetree.rs | 8 ++--- did-key/src/lib.rs | 2 +- did-onion/src/lib.rs | 13 +++----- did-pkh/src/lib.rs | 4 +-- did-sol/src/lib.rs | 2 +- did-test/src/main.rs | 10 +++--- did-tezos/src/explorer.rs | 4 +-- did-tezos/src/lib.rs | 4 +-- did-web/src/lib.rs | 5 ++- did-webkey/src/lib.rs | 13 +++----- ssi-core/src/uri.rs | 2 +- ssi-crypto/src/hashes/keccak.rs | 2 +- ssi-dids/src/did_resolve.rs | 56 +++++++++++---------------------- ssi-dids/src/lib.rs | 18 +++++------ ssi-json-ld/src/urdna2015.rs | 2 +- ssi-jws/src/lib.rs | 3 +- ssi-jwt/src/lib.rs | 6 +++- ssi-ldp/src/eip712.rs | 10 +++--- ssi-ucan/src/lib.rs | 12 ++++--- ssi-vc/src/lib.rs | 46 ++++++++++++--------------- ssi-vc/src/revocation.rs | 38 ++++++++++------------ vc-test/src/main.rs | 6 ++-- 24 files changed, 122 insertions(+), 152 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e8ca2d687..6d101f414 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: "1.66.0" + toolchain: "1.67.1" profile: minimal override: true components: rustfmt, clippy diff --git a/did-ethr/src/lib.rs b/did-ethr/src/lib.rs index 16f7b3e65..9749d0dd1 100644 --- a/did-ethr/src/lib.rs +++ b/did-ethr/src/lib.rs @@ -97,7 +97,7 @@ fn resolve_pk( Ok(pk_bytes) => pk_bytes, Err(e) => { return ( - ResolutionMetadata::from_error(&format!("Unable to parse key: {}", e)), + ResolutionMetadata::from_error(&format!("Unable to parse key: {e}")), None, None, ); @@ -107,7 +107,7 @@ fn resolve_pk( Ok(hash) => hash, Err(e) => { return ( - ResolutionMetadata::from_error(&format!("Unable to hash account address: {}", e)), + ResolutionMetadata::from_error(&format!("Unable to hash account address: {e}")), None, None, ) @@ -309,7 +309,7 @@ impl DIDMethod for DIDEthr { Ok(hash) => hash, _ => return None, }; - let did = format!("did:ethr:{}", hash); + let did = format!("did:ethr:{hash}"); Some(did) } diff --git a/did-ion/src/sidetree.rs b/did-ion/src/sidetree.rs index 6dfbb0b93..03ae864b6 100644 --- a/did-ion/src/sidetree.rs +++ b/did-ion/src/sidetree.rs @@ -1329,7 +1329,7 @@ impl fmt::Display for SidetreeDID { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "did:{}:", S::METHOD)?; if let Some(network) = S::NETWORK { - write!(f, "{}:", network)?; + write!(f, "{network}:")?; } match self { Self::Short { did_suffix } => f.write_str(&did_suffix.0), @@ -1395,7 +1395,7 @@ pub struct HTTPSidetreeDIDResolver { impl HTTPSidetreeDIDResolver { pub fn new(sidetree_api_url: &str) -> Self { - let identifiers_url = format!("{}identifiers/", sidetree_api_url); + let identifiers_url = format!("{sidetree_api_url}identifiers/"); Self { http_did_resolver: HTTPDIDResolver::new(&identifiers_url), _marker: PhantomData, @@ -1571,7 +1571,7 @@ impl fmt::Display for SidetreeAPIError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Sidetree error {}", self.code)?; if let Some(ref message) = self.message { - write!(f, ": {}", message)?; + write!(f, ": {message}")?; } Ok(()) } @@ -1621,7 +1621,7 @@ impl DIDMethod for SidetreeClient { .endpoint .as_ref() .ok_or_else(|| anyhow!("Missing Sidetree REST API endpoint"))?; - let url = format!("{}operations/", endpoint); + let url = format!("{endpoint}operations/"); let client = Client::builder().build().context("Build HTTP client")?; let resp = client .post(url) diff --git a/did-key/src/lib.rs b/did-key/src/lib.rs index 70113002e..57a582189 100644 --- a/did-key/src/lib.rs +++ b/did-key/src/lib.rs @@ -237,7 +237,7 @@ impl DIDResolver for DIDKey { ]), id: did.to_string(), verification_method: Some(vec![VerificationMethod::Map(VerificationMethodMap { - id: format!("{}#{}", did, method_specific_id), + id: format!("{did}#{method_specific_id}"), type_: vm_type, controller: did.to_string(), public_key_jwk: Some(jwk), diff --git a/did-onion/src/lib.rs b/did-onion/src/lib.rs index 5d0b9661a..7b72c07b5 100644 --- a/did-onion/src/lib.rs +++ b/did-onion/src/lib.rs @@ -22,7 +22,7 @@ pub struct DIDOnion { impl DIDOnion { fn with_port(port: usize) -> Self { Self { - proxy_url: format!("socks5h://127.0.0.1:{}", port), + proxy_url: format!("socks5h://127.0.0.1:{port}"), } } } @@ -51,7 +51,7 @@ fn did_onion_url(did: &str) -> Result { Some(_) => parts.collect::>().join("/"), None => ".well-known".to_string(), }; - let url = format!("http://{}.onion/{}/did.json", onion_address, path); + let url = format!("http://{onion_address}.onion/{path}/did.json"); Ok(url) } @@ -113,7 +113,7 @@ impl DIDResolver for DIDOnion { Ok(proxy) => client_builder.proxy(proxy), Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error constructing proxy: {}", err)), + ResolutionMetadata::from_error(&format!("Error constructing proxy: {err}")), Vec::new(), None, ) @@ -123,7 +123,7 @@ impl DIDResolver for DIDOnion { Ok(c) => c, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), Vec::new(), None, ) @@ -137,10 +137,7 @@ impl DIDResolver for DIDOnion { Ok(req) => req, Err(err) => { return ( - ResolutionMetadata::from_error(&format!( - "Error sending HTTP request : {}", - err - )), + ResolutionMetadata::from_error(&format!("Error sending HTTP request: {err}")), Vec::new(), None, ) diff --git a/did-pkh/src/lib.rs b/did-pkh/src/lib.rs index 987306598..9e222a948 100644 --- a/did-pkh/src/lib.rs +++ b/did-pkh/src/lib.rs @@ -631,7 +631,7 @@ fn generate_caip10_did(key: &JWK, name: &str) -> Result { "aleo" => generate_caip10_aleo(key, reference_opt)?, _ => return Err("Namespace not supported".to_string()), }; - Ok(format!("did:pkh:{}", account_id)) + Ok(format!("did:pkh:{account_id}")) } impl DIDMethod for DIDPKH { @@ -665,7 +665,7 @@ impl DIDMethod for DIDPKH { Some(addr) => addr, None => return None, }; - let did = format!("did:pkh:{}:{}", pkh_name, addr); + let did = format!("did:pkh:{pkh_name}:{addr}"); Some(did) } diff --git a/did-sol/src/lib.rs b/did-sol/src/lib.rs index d173eebf3..d2c162a40 100644 --- a/did-sol/src/lib.rs +++ b/did-sol/src/lib.rs @@ -182,7 +182,7 @@ impl DIDMethod for DIDSol { let did = match jwk.params { Params::OKP(ref params) if params.curve == "Ed25519" => { let addr = bs58::encode(¶ms.public_key.0).into_string(); - format!("did:sol:{}", addr) + format!("did:sol:{addr}") } _ => { dbg!(&jwk.params); diff --git a/did-test/src/main.rs b/did-test/src/main.rs index 37414795e..27b8c262f 100644 --- a/did-test/src/main.rs +++ b/did-test/src/main.rs @@ -372,7 +372,7 @@ impl ResolverOutcome { return Self::RepresentationNotSupportedErrorOutcome } ERROR_NOT_FOUND => return Self::NotFoundErrorOutcome, - _ => panic!("Unknown outcome for error: {}", error), + _ => panic!("Unknown outcome for error: {error}"), } } if deactivated == Some(true) { @@ -828,7 +828,7 @@ async fn report_method(mut args: Args) { "onion" => report_method_onion().await, "pkh" => report_method_pkh().await, "webkey" => report_method_webkey().await, - method => panic!("unknown method {}", method), + method => panic!("unknown method {method}"), } } @@ -842,7 +842,7 @@ async fn report_resolver(mut args: Args) { "onion" => report_resolver_onion().await, "pkh" => report_resolver_pkh().await, "webkey" => report_resolver_webkey().await, - method => panic!("unknown method {}", method), + method => panic!("unknown method {method}"), } } @@ -856,7 +856,7 @@ async fn report_dereferencer(mut args: Args) { "onion" => report_dereferencer_onion().await, "pkh" => report_dereferencer_pkh().await, "webkey" => report_dereferencer_webkey().await, - method => panic!("unknown method {}", method), + method => panic!("unknown method {method}"), } } @@ -869,6 +869,6 @@ async fn main() { "method" => report_method(args).await, "resolver" => report_resolver(args).await, "dereferencer" => report_dereferencer(args).await, - section => panic!("unknown section {}", section), + section => panic!("unknown section {section}"), } } diff --git a/did-tezos/src/explorer.rs b/did-tezos/src/explorer.rs index 886809e28..22083d526 100644 --- a/did-tezos/src/explorer.rs +++ b/did-tezos/src/explorer.rs @@ -54,7 +54,7 @@ pub async fn execute_service_view(tzkt_url: &str, did: &str, contract: &str) -> .build()?; let url = Url::parse(tzkt_url)?; let service_result: ServiceResult = client - .get(url.join(&format!("/v1/contracts/{}/storage", contract))?) + .get(url.join(&format!("/v1/contracts/{contract}/storage"))?) .send() .await? .json() @@ -78,7 +78,7 @@ pub async fn execute_auth_view(tzkt_url: &str, contract: &str) -> Result u.clone(), - None => format!("https://api.{}.tzkt.io", network), + None => format!("https://api.{network}.tzkt.io"), }; let mut tzkt_url = &default_url; if let Some(s) = &input_metadata.property_set { @@ -413,7 +413,7 @@ impl DIDTz { id: String::from(vm_didurl.clone()), type_: proof_type.to_string(), controller: did.to_string(), - blockchain_account_id: Some(format!("tezos:{}:{}", genesis_block_hash, address)), + blockchain_account_id: Some(format!("tezos:{genesis_block_hash}:{address}")), ..Default::default() })]), authentication: match public_key { diff --git a/did-web/src/lib.rs b/did-web/src/lib.rs index ff23c00e4..f50f51da3 100644 --- a/did-web/src/lib.rs +++ b/did-web/src/lib.rs @@ -118,7 +118,7 @@ impl DIDResolver for DIDWeb { Ok(c) => c, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), Vec::new(), None, ) @@ -133,8 +133,7 @@ impl DIDResolver for DIDWeb { Err(err) => { return ( ResolutionMetadata::from_error(&format!( - "Error sending HTTP request ({}): {}", - url, err + "Error sending HTTP request ({url}): {err}" )), Vec::new(), None, diff --git a/did-webkey/src/lib.rs b/did-webkey/src/lib.rs index 19bbbbf28..8da3da9d9 100644 --- a/did-webkey/src/lib.rs +++ b/did-webkey/src/lib.rs @@ -63,7 +63,7 @@ fn gpg_pk_to_vm(did: &str, pk: SignedPublicKey) -> Result<(VerificationMethodMap let fingerprint = pk .fingerprint() .iter() - .fold(String::new(), |acc, &x| format!("{}{:02X}", acc, x)); + .fold(String::new(), |acc, &x| format!("{acc}{x:02X}")); let vm_url = DIDURL { did: did.to_string(), fragment: Some(fingerprint.clone()), @@ -228,7 +228,7 @@ fn parse_did_webkey_url(did: &str) -> Result<(DIDWebKeyType, String), Resolution } }; #[allow(unused_mut)] - let mut url = format!("https://{}/{}", domain_name, path); + let mut url = format!("https://{domain_name}/{path}"); #[cfg(test)] PROXY.with(|proxy| { if let Some(ref proxy) = *proxy.borrow() { @@ -259,7 +259,7 @@ impl DIDResolver for DIDWebKey { Ok(c) => c, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), None, None, ) @@ -273,10 +273,7 @@ impl DIDResolver for DIDWebKey { Ok(req) => req, Err(err) => { return ( - ResolutionMetadata::from_error(&format!( - "Error sending HTTP request : {}", - err - )), + ResolutionMetadata::from_error(&format!("Error sending HTTP request : {err}")), None, None, ) @@ -312,7 +309,7 @@ impl DIDResolver for DIDWebKey { ), Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error parsing keys: {}", err)), + ResolutionMetadata::from_error(&format!("Error parsing keys: {err}")), None, None, ) diff --git a/ssi-core/src/uri.rs b/ssi-core/src/uri.rs index a48a24d4c..1b58651ba 100644 --- a/ssi-core/src/uri.rs +++ b/ssi-core/src/uri.rs @@ -51,7 +51,7 @@ impl FromStr for URI { impl std::fmt::Display for URI { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Self::String(ref string) => write!(f, "{}", string), + Self::String(ref string) => write!(f, "{string}"), } } } diff --git a/ssi-crypto/src/hashes/keccak.rs b/ssi-crypto/src/hashes/keccak.rs index 246248a4c..a5e4cdc77 100644 --- a/ssi-crypto/src/hashes/keccak.rs +++ b/ssi-crypto/src/hashes/keccak.rs @@ -4,7 +4,7 @@ pub fn bytes_to_lowerhex(bytes: &[u8]) -> String { "0x".to_string() + &bytes .iter() - .map(|byte| format!("{:02x}", byte)) + .map(|byte| format!("{byte:02x}")) .collect::() } diff --git a/ssi-dids/src/did_resolve.rs b/ssi-dids/src/did_resolve.rs index 47073a5de..523b28d2a 100644 --- a/ssi-dids/src/did_resolve.rs +++ b/ssi-dids/src/did_resolve.rs @@ -626,8 +626,7 @@ async fn dereference_primary_resource( Err(err) => { return ( DereferencingMetadata::from_error(&format!( - "Unable to construct service endpoint: {}", - err + "Unable to construct service endpoint: {err}" )), Content::Null, ContentMetadata::default(), @@ -715,8 +714,7 @@ async fn dereference_secondary_resource( Err(error) => { return ( DereferencingMetadata::from_error(&format!( - "Unable to find object in DID document: {}", - error + "Unable to find object in DID document: {error}" )), Content::Null, ContentMetadata::default(), @@ -761,10 +759,7 @@ async fn dereference_secondary_resource( ContentMetadata::default(), ), Some(content_type) => ( - DereferencingMetadata::from_error(&format!( - "Unsupported content type: {}", - content_type - )), + DereferencingMetadata::from_error(&format!("Unsupported content type: {content_type}")), Content::Null, ContentMetadata::default(), ), @@ -873,10 +868,7 @@ fn transform_resolution_result( Ok(result) => result, Err(err) => { return ( - ResolutionMetadata::from_error(&format!( - "Error parsing resolution result: {}", - err - )), + ResolutionMetadata::from_error(&format!("Error parsing resolution result: {err}")), None, None, ) @@ -949,7 +941,7 @@ impl DIDResolver for HTTPDIDResolver { Ok(client) => client, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error building HTTP client: {}", err)), + ResolutionMetadata::from_error(&format!("Error building HTTP client: {err}")), None, None, ); @@ -965,7 +957,7 @@ impl DIDResolver for HTTPDIDResolver { Ok(resp) => resp, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error sending HTTP request: {}", err)), + ResolutionMetadata::from_error(&format!("Error sending HTTP request: {err}")), None, None, ) @@ -979,8 +971,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return ( ResolutionMetadata::from_error(&format!( - "Error reading HTTP header: {}", - err + "Error reading HTTP header: {err}" )), None, None, @@ -1019,8 +1010,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return ( ResolutionMetadata::from_error(&format!( - "Error parsing resolution response: {}", - err + "Error parsing resolution response: {err}" )), None, None, @@ -1039,7 +1029,7 @@ impl DIDResolver for HTTPDIDResolver { Ok(doc) => doc, Err(err) => { return ( - ResolutionMetadata::from_error(&format!("Error parsing DID document: {}", err)), + ResolutionMetadata::from_error(&format!("Error parsing DID document: {err}")), None, None, ) @@ -1063,8 +1053,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Unable to serialize input metadata into query string: {}", - err + "Unable to serialize input metadata into query string: {err}" )), Content::Null, ContentMetadata::default(), @@ -1096,8 +1085,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error building HTTP client: {}", - err + "Error building HTTP client: {err}" )), Content::Null, ContentMetadata::default(), @@ -1115,8 +1103,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error sending HTTP request: {}", - err + "Error sending HTTP request: {err}" )), Content::Null, ContentMetadata::default(), @@ -1139,8 +1126,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error reading HTTP header: {}", - err + "Error reading HTTP header: {err}" )), Content::Null, ContentMetadata::default(), @@ -1154,8 +1140,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error reading HTTP response: {}", - err + "Error reading HTTP response: {err}" )), Content::Null, ContentMetadata::default(), @@ -1169,8 +1154,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error parsing DID document: {}", - err + "Error parsing DID document: {err}" )), Content::Null, ContentMetadata::default(), @@ -1187,8 +1171,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error parsing DID resolution result: {}", - err + "Error parsing DID resolution result: {err}" )), Content::Null, ContentMetadata::default(), @@ -1211,8 +1194,7 @@ impl DIDResolver for HTTPDIDResolver { Err(err) => { return Some(( DereferencingMetadata::from_error(&format!( - "Error parsing JSON: {}", - err + "Error parsing JSON: {err}" )), Content::Null, ContentMetadata::default(), @@ -1331,7 +1313,7 @@ pub async fn easy_resolve(did: &str, resolver: &dyn DIDResolver) -> Result fmt::Result { write!(f, "{}{}", self.did, self.path_abempty)?; if let Some(ref query) = self.query { - write!(f, "?{}", query)?; + write!(f, "?{query}")?; } if let Some(ref fragment) = self.fragment { - write!(f, "#{}", fragment)?; + write!(f, "#{fragment}")?; } Ok(()) } @@ -1038,10 +1038,10 @@ impl fmt::Display for RelativeDIDURL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.path.fmt(f)?; if let Some(ref query) = self.query { - write!(f, "?{}", query)?; + write!(f, "?{query}")?; } if let Some(ref fragment) = self.fragment { - write!(f, "#{}", fragment)?; + write!(f, "#{fragment}")?; } Ok(()) } @@ -1063,10 +1063,10 @@ impl fmt::Display for PrimaryDIDURL { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.did)?; if let Some(ref path) = self.path { - write!(f, "{}", path)?; + write!(f, "{path}")?; } if let Some(ref query) = self.query { - write!(f, "?{}", query)?; + write!(f, "?{query}")?; } Ok(()) } @@ -1083,7 +1083,7 @@ impl TryFrom for DIDURL { /// needed for #[serde(into = "String")] impl From for String { fn from(didurl: DIDURL) -> String { - format!("{}", didurl) + format!("{didurl}") } } @@ -1102,7 +1102,7 @@ impl From for DIDURL { /// needed for #[serde(into = "String")] impl From for String { fn from(didurl: PrimaryDIDURL) -> String { - format!("{}", didurl) + format!("{didurl}") } } @@ -1339,7 +1339,7 @@ impl Document { VerificationRelationship::KeyAgreement => &self.key_agreement, VerificationRelationship::CapabilityInvocation => &self.capability_invocation, VerificationRelationship::CapabilityDelegation => &self.capability_delegation, - rel => return Err(format!("Unsupported verification relationship: {:?}", rel)), + rel => return Err(format!("Unsupported verification relationship: {rel:?}")), }; let vm_ids = vms.iter().flatten().map(|vm| vm.get_id(did)).collect(); Ok(vm_ids) diff --git a/ssi-json-ld/src/urdna2015.rs b/ssi-json-ld/src/urdna2015.rs index 016cd68c4..c2d455a73 100644 --- a/ssi-json-ld/src/urdna2015.rs +++ b/ssi-json-ld/src/urdna2015.rs @@ -135,7 +135,7 @@ pub struct HashNDegreeQuadsOutput { fn digest_to_lowerhex(digest: &[u8]) -> String { digest .iter() - .map(|byte| format!("{:02x}", byte)) + .map(|byte| format!("{byte:02x}")) .collect::() } diff --git a/ssi-jws/src/lib.rs b/ssi-jws/src/lib.rs index ffbc67e39..628459295 100644 --- a/ssi-jws/src/lib.rs +++ b/ssi-jws/src/lib.rs @@ -350,8 +350,7 @@ pub fn verify_bytes_warnable( // For user convenience, output the normalized signature. let sig_normalized_b64 = base64::encode_config(s, base64::URL_SAFE_NO_PAD); warnings.push(format!( - "Non-normalized ES256K signature. Normalized: {}", - sig_normalized_b64 + "Non-normalized ES256K signature. Normalized: {sig_normalized_b64}" )); s } else { diff --git a/ssi-jwt/src/lib.rs b/ssi-jwt/src/lib.rs index 579719593..33bd3b6e1 100644 --- a/ssi-jwt/src/lib.rs +++ b/ssi-jwt/src/lib.rs @@ -138,7 +138,11 @@ impl TryFrom> for NumericDate { // Have to take seconds and nanoseconds separately in order to get the full allowable // range of microsecond-precision values as described above. let whole_seconds = dtu.timestamp() as f64; - let fractional_seconds = dtu.timestamp_nanos().rem_euclid(1_000_000_000) as f64 * 1.0e-9; + let fractional_seconds = dtu + .timestamp_nanos_opt() + .expect("value can not be represented in a timestamp with nanosecond precision.") + .rem_euclid(1_000_000_000) as f64 + * 1.0e-9; Self::try_from_seconds(whole_seconds + fractional_seconds) } } diff --git a/ssi-ldp/src/eip712.rs b/ssi-ldp/src/eip712.rs index a34d00e57..7a5fd18e0 100644 --- a/ssi-ldp/src/eip712.rs +++ b/ssi-ldp/src/eip712.rs @@ -240,19 +240,19 @@ impl fmt::Display for EIP712Type { match self { EIP712Type::Bytes => write!(f, "bytes"), EIP712Type::String => write!(f, "string"), - EIP712Type::BytesN(n) => write!(f, "bytes{}", n), - EIP712Type::UintN(n) => write!(f, "uint{}", n), - EIP712Type::IntN(n) => write!(f, "int{}", n), + EIP712Type::BytesN(n) => write!(f, "bytes{n}"), + EIP712Type::UintN(n) => write!(f, "uint{n}"), + EIP712Type::IntN(n) => write!(f, "int{n}"), EIP712Type::Bool => write!(f, "bool"), EIP712Type::Address => write!(f, "address"), EIP712Type::Array(type_) => { write!(f, "{}[]", *type_) } EIP712Type::ArrayN(type_, n) => { - write!(f, "{}[{}]", *type_, n) + write!(f, "{}[{n}]", *type_) } EIP712Type::Struct(name) => { - write!(f, "{}", name) + write!(f, "{name}") } } } diff --git a/ssi-ucan/src/lib.rs b/ssi-ucan/src/lib.rs index 9a2a2fb28..7ed2c2742 100644 --- a/ssi-ucan/src/lib.rs +++ b/ssi-ucan/src/lib.rs @@ -320,8 +320,8 @@ pub enum UcanResource { impl Display for UcanResource { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match &self { - Self::Proof(p) => write!(f, "{}", p), - Self::URI(u) => write!(f, "{}", u), + Self::Proof(p) => write!(f, "{p}"), + Self::URI(u) => write!(f, "{u}"), } } } @@ -398,7 +398,11 @@ pub struct Capability { } fn now() -> f64 { - (chrono::prelude::Utc::now().timestamp_nanos() as f64) / 1e+9_f64 + (chrono::prelude::Utc::now() + .timestamp_nanos_opt() + .expect("value can not be represented in a timestamp with nanosecond precision.") + as f64) + / 1e+9_f64 } #[serde_as] @@ -422,7 +426,7 @@ impl UcanRevocation { Ok(Self { issuer, revoke, - challenge: sign_bytes(algorithm, format!("REVOKE:{}", revoke).as_bytes(), jwk)?, + challenge: sign_bytes(algorithm, format!("REVOKE:{revoke}").as_bytes(), jwk)?, }) } pub async fn verify_signature( diff --git a/ssi-vc/src/lib.rs b/ssi-vc/src/lib.rs index e4eb6e932..e3410312b 100644 --- a/ssi-vc/src/lib.rs +++ b/ssi-vc/src/lib.rs @@ -768,7 +768,7 @@ impl Credential { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to split JWS: {}", err)), + VerificationResult::error(&format!("Unable to split JWS: {err}")), ); } }; @@ -782,7 +782,7 @@ impl Credential { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to decode JWS: {}", err)), + VerificationResult::error(&format!("Unable to decode JWS: {err}")), ); } }; @@ -791,7 +791,7 @@ impl Credential { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to decode JWS claims: {}", err)), + VerificationResult::error(&format!("Unable to decode JWS claims: {err}")), ); } }; @@ -801,8 +801,7 @@ impl Credential { return ( None, VerificationResult::error(&format!( - "Unable to convert JWT claims to VC: {}", - err + "Unable to convert JWT claims to VC: {err}" )), ); } @@ -810,7 +809,7 @@ impl Credential { if let Err(err) = vc.validate_unsigned() { return ( None, - VerificationResult::error(&format!("Invalid VC: {}", err)), + VerificationResult::error(&format!("Invalid VC: {err}")), ); } // TODO: error if any unconvertable claims @@ -823,7 +822,7 @@ impl Credential { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to filter proofs: {}", err)), + VerificationResult::error(&format!("Unable to filter proofs: {err}")), ); } }; @@ -838,7 +837,7 @@ impl Credential { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to resolve key for JWS: {}", err)), + VerificationResult::error(&format!("Unable to resolve key for JWS: {err}")), ); } }; @@ -852,7 +851,7 @@ impl Credential { } Err(err) => results .errors - .push(format!("Unable to verify signature: {}", err)), + .push(format!("Unable to verify signature: {err}")), } return (Some(vc), results); } @@ -995,7 +994,7 @@ impl Credential { let (proofs, _) = match self.filter_proofs(options, None, resolver).await { Ok(proofs) => proofs, Err(err) => { - return VerificationResult::error(&format!("Unable to filter proofs: {}", err)); + return VerificationResult::error(&format!("Unable to filter proofs: {err}")); } }; if proofs.is_empty() { @@ -1070,18 +1069,14 @@ impl Credential { Ok(status) => status, Err(e) => { return VerificationResult::error(&format!( - "Unable to convert credentialStatus: {}", - e + "Unable to convert credentialStatus: {e}" )) } }; let checkable_status: CheckableStatus = match serde_json::from_value(status_value) { Ok(checkable_status) => checkable_status, Err(e) => { - return VerificationResult::error(&format!( - "Unable to parse credentialStatus: {}", - e - )) + return VerificationResult::error(&format!("Unable to parse credentialStatus: {e}")) } }; let mut result = checkable_status.check(self, resolver, context_loader).await; @@ -1322,7 +1317,7 @@ impl Presentation { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to split JWS: {}", err)), + VerificationResult::error(&format!("Unable to split JWS: {err}")), ); } }; @@ -1336,7 +1331,7 @@ impl Presentation { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to decode JWS: {}", err)), + VerificationResult::error(&format!("Unable to decode JWS: {err}")), ); } }; @@ -1345,7 +1340,7 @@ impl Presentation { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to decode JWS claims: {}", err)), + VerificationResult::error(&format!("Unable to decode JWS claims: {err}")), ); } }; @@ -1355,8 +1350,7 @@ impl Presentation { return ( None, VerificationResult::error(&format!( - "Unable to convert JWT claims to VP: {}", - err + "Unable to convert JWT claims to VP: {err}" )), ); } @@ -1364,7 +1358,7 @@ impl Presentation { if let Err(err) = vp.validate_unsigned() { return ( None, - VerificationResult::error(&format!("Invalid VP: {}", err)), + VerificationResult::error(&format!("Invalid VP: {err}")), ); } let mut results = VerificationResult::new(); @@ -1378,7 +1372,7 @@ impl Presentation { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to filter proofs: {}", err)), + VerificationResult::error(&format!("Unable to filter proofs: {err}")), ); } }; @@ -1393,7 +1387,7 @@ impl Presentation { Err(err) => { return ( None, - VerificationResult::error(&format!("Unable to resolve key for JWS: {}", err)), + VerificationResult::error(&format!("Unable to resolve key for JWS: {err}")), ); } }; @@ -1406,7 +1400,7 @@ impl Presentation { } Err(err) => results .errors - .push(format!("Unable to filter proofs: {}", err)), + .push(format!("Unable to filter proofs: {err}")), } return (Some(vp), results); } @@ -1583,7 +1577,7 @@ impl Presentation { let (proofs, _) = match self.filter_proofs(options, None, resolver).await { Ok(proofs) => proofs, Err(err) => { - return VerificationResult::error(&format!("Unable to filter proofs: {}", err)); + return VerificationResult::error(&format!("Unable to filter proofs: {err}")); } }; if proofs.is_empty() { diff --git a/ssi-vc/src/revocation.rs b/ssi-vc/src/revocation.rs index 44b367d7f..79b104c82 100644 --- a/ssi-vc/src/revocation.rs +++ b/ssi-vc/src/revocation.rs @@ -346,8 +346,7 @@ impl CredentialStatus for RevocationList2020Status { { // TODO: support JSON-LD credentials defining the terms elsewhere. return result.with_error(format!( - "Missing expected context URI {} for credential using RevocationList2020", - REVOCATION_LIST_2020_V1_CONTEXT + "Missing expected context URI {REVOCATION_LIST_2020_V1_CONTEXT} for credential using RevocationList2020" )); } if self.id == URI::String(self.revocation_list_credential.clone()) { @@ -371,7 +370,7 @@ impl CredentialStatus for RevocationList2020Status { Ok(credential) => credential, Err(e) => { return result - .with_error(format!("Unable to fetch revocation list credential: {}", e)); + .with_error(format!("Unable to fetch revocation list credential: {e}")); } }; let list_issuer_id = match &revocation_list_credential.issuer { @@ -383,24 +382,21 @@ impl CredentialStatus for RevocationList2020Status { }; if issuer_id != list_issuer_id { return result.with_error(format!( - "Revocation list issuer mismatch. Credential: {}, Revocation list: {}", - issuer_id, list_issuer_id + "Revocation list issuer mismatch. Credential: {issuer_id}, Revocation list: {list_issuer_id}" )); } if let Err(e) = revocation_list_credential.validate() { - return result.with_error(format!("Invalid list credential: {}", e)); + return result.with_error(format!("Invalid list credential: {e}")); } let vc_result = revocation_list_credential .verify(None, resolver, context_loader) .await; for warning in vc_result.warnings { - result - .warnings - .push(format!("Revocation list: {}", warning)); + result.warnings.push(format!("Revocation list: {warning}")); } for error in vc_result.errors { - result.errors.push(format!("Revocation list: {}", error)); + result.errors.push(format!("Revocation list: {error}")); } if !result.errors.is_empty() { return result; @@ -412,7 +408,7 @@ impl CredentialStatus for RevocationList2020Status { Ok(credential) => credential, Err(e) => { return result - .with_error(format!("Unable to parse revocation list credential: {}", e)); + .with_error(format!("Unable to parse revocation list credential: {e}")); } }; if revocation_list_credential.id != URI::String(self.revocation_list_credential.to_string()) @@ -427,7 +423,7 @@ impl CredentialStatus for RevocationList2020Status { let list = match List::try_from(&revocation_list.encoded_list) { Ok(list) => list, - Err(e) => return result.with_error(format!("Unable to decode revocation list: {}", e)), + Err(e) => return result.with_error(format!("Unable to decode revocation list: {e}")), }; let credential_index = self.revocation_list_index.0; use bitvec::prelude::*; @@ -478,8 +474,7 @@ impl CredentialStatus for StatusList2021Entry { { // TODO: support JSON-LD credentials defining the terms elsewhere. return result.with_error(format!( - "Missing expected context URI {} for credential using StatusList2021", - STATUS_LIST_2021_V1_CONTEXT + "Missing expected context URI {STATUS_LIST_2021_V1_CONTEXT} for credential using StatusList2021" )); } if self.id == URI::String(self.status_list_credential.clone()) { @@ -501,7 +496,7 @@ impl CredentialStatus for StatusList2021Entry { let status_list_credential = match load_credential(&self.status_list_credential).await { Ok(credential) => credential, Err(e) => { - return result.with_error(format!("Unable to fetch status list credential: {}", e)); + return result.with_error(format!("Unable to fetch status list credential: {e}")); } }; let list_issuer_id = match &status_list_credential.issuer { @@ -512,22 +507,21 @@ impl CredentialStatus for StatusList2021Entry { }; if issuer_id != list_issuer_id { return result.with_error(format!( - "Status list issuer mismatch. Credential: {}, Status list: {}", - issuer_id, list_issuer_id + "Status list issuer mismatch. Credential: {issuer_id}, Status list: {list_issuer_id}" )); } if let Err(e) = status_list_credential.validate() { - return result.with_error(format!("Invalid list credential: {}", e)); + return result.with_error(format!("Invalid list credential: {e}")); } let vc_result = status_list_credential .verify(None, resolver, context_loader) .await; for warning in vc_result.warnings { - result.warnings.push(format!("Status list: {}", warning)); + result.warnings.push(format!("Status list: {warning}")); } if let Some(error) = vc_result.errors.into_iter().next() { - result.errors.push(format!("Status list: {}", error)); + result.errors.push(format!("Status list: {error}")); return result; } // Note: vc_result.checks is not checked here. It is assumed that default checks passed. @@ -537,7 +531,7 @@ impl CredentialStatus for StatusList2021Entry { Ok(credential) => credential, Err(e) => { return result - .with_error(format!("Unable to parse status list credential: {}", e)); + .with_error(format!("Unable to parse status list credential: {e}")); } }; if status_list_credential.id != URI::String(self.status_list_credential.to_string()) { @@ -551,7 +545,7 @@ impl CredentialStatus for StatusList2021Entry { let list = match List::try_from(&status_list.encoded_list) { Ok(list) => list, - Err(e) => return result.with_error(format!("Unable to decode status list: {}", e)), + Err(e) => return result.with_error(format!("Unable to decode status list: {e}")), }; let credential_index = self.status_list_index.0; use bitvec::prelude::*; diff --git a/vc-test/src/main.rs b/vc-test/src/main.rs index 0e3b2290f..668d11c24 100644 --- a/vc-test/src/main.rs +++ b/vc-test/src/main.rs @@ -103,14 +103,14 @@ async fn main() { (true, "--jwt-no-jws") => jwt_no_jws = true, (true, "--jwt-presentation") => jwt_presentation = true, (true, "--jwt-decode") => jwt_decode = true, - (true, _) => panic!("Unexpected option '{}'", arg), + (true, _) => panic!("Unexpected option '{arg}'"), (false, _) => { if cmd.is_none() { cmd = Option::Some(arg); } else if filename.is_none() { filename = Option::Some(arg); } else { - panic!("Unexpected argument '{}'", arg); + panic!("Unexpected argument '{arg}'"); } } } @@ -157,7 +157,7 @@ async fn main() { write_out(output); } _ => { - eprintln!("Unexpected command '{}'", cmd_str); + eprintln!("Unexpected command '{cmd_str}'"); std::process::exit(1); } }