From 68801d0bca58c3735bb21549f1d1097876cf06b0 Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Tue, 7 Oct 2025 14:03:05 +0700 Subject: [PATCH 1/5] bump cat-ci:rust version --- rust/Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/Earthfile b/rust/Earthfile index 373108a861b..3cbd5784415 100644 --- a/rust/Earthfile +++ b/rust/Earthfile @@ -1,6 +1,6 @@ VERSION 0.8 -IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.4.9 AS rust-ci +IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.5.17 AS rust-ci IMPORT ../ AS repo-ci COPY_SRC: From 86f28b6467e8d93758861eab231b37f15e71a6cf Mon Sep 17 00:00:00 2001 From: Mr-Leshiy Date: Tue, 7 Oct 2025 14:09:02 +0700 Subject: [PATCH 2/5] wip --- rust/.cargo/config.toml | 4 +- rust/.config/nextest.toml | 11 ++ rust/c509-certificate/examples/cli/main.rs | 31 ++++-- .../src/algorithm_identifier.rs | 14 ++- .../src/attributes/attribute.rs | 32 ++++-- rust/c509-certificate/src/attributes/mod.rs | 14 ++- rust/c509-certificate/src/big_uint.rs | 9 +- rust/c509-certificate/src/c509.rs | 14 ++- rust/c509-certificate/src/cert_tbs.rs | 22 ++-- .../src/extensions/alt_name.rs | 18 +++- .../src/extensions/extension/mod.rs | 33 ++++-- rust/c509-certificate/src/extensions/mod.rs | 14 ++- .../src/general_names/data.rs | 6 +- .../src/general_names/general_name.rs | 23 +++- .../c509-certificate/src/general_names/mod.rs | 14 ++- .../src/general_names/other_name_hw_module.rs | 14 ++- rust/c509-certificate/src/helper/decode.rs | 26 +++-- rust/c509-certificate/src/helper/encode.rs | 20 +++- .../src/issuer_sig_algo/mod.rs | 23 +++- rust/c509-certificate/src/lib.rs | 10 +- rust/c509-certificate/src/name/mod.rs | 21 +++- rust/c509-certificate/src/oid.rs | 23 +++- rust/c509-certificate/src/signing.rs | 26 ++++- .../src/subject_pub_key_algo/mod.rs | 23 +++- rust/c509-certificate/src/tables.rs | 18 +++- rust/c509-certificate/src/time.rs | 9 +- .../src/auxdata/aux_data.rs | 8 +- .../src/auxdata/block.rs | 5 +- .../src/auxdata/metadatum.rs | 13 ++- .../src/auxdata/metadatum_label.rs | 3 +- .../src/auxdata/metadatum_value.rs | 3 +- .../src/auxdata/scripts.rs | 6 +- .../src/cip134_uri.rs | 5 +- rust/cardano-blockchain-types/src/fork.rs | 7 +- .../src/metadata/cip36/key_registration.rs | 18 +++- .../src/metadata/cip36/mod.rs | 17 ++- .../metadata/cip36/registration_witness.rs | 5 +- .../src/metadata/cip36/validation.rs | 5 +- .../src/metadata/cip36/voting_pk.rs | 5 +- .../src/multi_era_block_data.rs | 50 +++++++-- rust/cardano-blockchain-types/src/network.rs | 10 +- rust/cardano-blockchain-types/src/point.rs | 58 +++++++--- rust/cardano-blockchain-types/src/slot.rs | 12 ++- .../src/stake_address.rs | 16 ++- .../src/txn_witness.rs | 16 ++- .../examples/follow_chains.rs | 38 +++++-- rust/cardano-chain-follower/src/chain_sync.rs | 64 ++++++++--- .../src/chain_sync_config.rs | 20 +++- .../src/chain_sync_live_chains.rs | 65 +++++++++--- .../src/chain_sync_ready.rs | 7 +- .../src/chain_update.rs | 11 +- rust/cardano-chain-follower/src/follow.rs | 26 ++++- .../src/mithril_query.rs | 4 +- .../src/mithril_snapshot.rs | 13 ++- .../src/mithril_snapshot_config.rs | 19 +++- .../src/mithril_snapshot_data.rs | 5 +- .../src/mithril_snapshot_iterator.rs | 26 ++++- .../src/mithril_snapshot_sync.rs | 69 ++++++++---- .../src/mithril_turbo_downloader.rs | 42 ++++++-- .../cardano-chain-follower/src/snapshot_id.rs | 45 ++++++-- rust/cardano-chain-follower/src/stats/mod.rs | 80 +++++++++++--- .../src/stats/rollback.rs | 19 +++- .../src/stats/thread/mod.rs | 14 ++- .../src/turbo_downloader/mod.rs | 100 ++++++++++++++---- .../src/catalyst_id/key_rotation.rs | 10 +- rust/catalyst-types/src/catalyst_id/mod.rs | 37 +++++-- .../src/catalyst_id/role_index.rs | 10 +- rust/catalyst-types/src/cbor_utils.rs | 11 +- rust/catalyst-types/src/conversion.rs | 7 +- rust/catalyst-types/src/hashes.rs | 17 ++- rust/catalyst-types/src/problem_report.rs | 60 +++++++++-- rust/catalyst-types/src/uuid/mod.rs | 7 +- rust/catalyst-types/src/uuid/uuid_v4.rs | 14 ++- rust/catalyst-types/src/uuid/uuid_v7.rs | 14 ++- rust/catalyst-voting/benches/vote_protocol.rs | 2 +- .../src/crypto/babystep_giantstep.rs | 13 ++- .../catalyst-voting/src/crypto/ed25519/mod.rs | 16 ++- .../catalyst-voting/src/crypto/elgamal/mod.rs | 40 +++++-- .../src/crypto/group/ristretto255/mod.rs | 51 +++++++-- rust/catalyst-voting/src/crypto/hash.rs | 20 +++- .../src/crypto/zk_dl_equality.rs | 29 +++-- .../src/crypto/zk_unit_vector/challenges.rs | 7 +- .../src/crypto/zk_unit_vector/decoding.rs | 8 +- .../src/crypto/zk_unit_vector/mod.rs | 43 ++++++-- .../src/crypto/zk_unit_vector/polynomial.rs | 19 +++- .../randomness_announcements.rs | 10 +- .../src/crypto/zk_unit_vector/utils.rs | 5 +- .../src/vote_protocol/tally/mod.rs | 8 +- .../src/vote_protocol/tally/proof.rs | 11 +- .../src/vote_protocol/voter/decoding.rs | 13 ++- .../src/vote_protocol/voter/mod.rs | 27 +++-- .../src/vote_protocol/voter/proof.rs | 21 ++-- .../tests/testsuite/common/mod.rs | 6 +- rust/cbork-cddl-parser/src/lib.rs | 5 +- rust/cbork-cddl-parser/src/parser.rs | 3 +- rust/cbork-cddl-parser/src/preprocessor.rs | 4 +- rust/cbork-cddl-parser/tests/common/mod.rs | 4 +- rust/cbork-utils/src/decode_helper.rs | 33 ++++-- rust/deny.toml | 7 +- .../examples/add-file-with-pinning.rs | 5 +- .../examples/provide-content-dht.rs | 2 +- rust/hermes-ipfs/examples/pubsub.rs | 5 +- rust/hermes-ipfs/src/lib.rs | 98 +++++++++++++---- rust/immutable-ledger/src/serialize.rs | 59 ++++++++--- .../src/cardano/cip509/cip509.rs | 37 +++++-- .../src/cardano/cip509/rbac/certs/c509.rs | 5 +- .../cip509/rbac/certs/c509_metadatum.rs | 5 +- .../src/cardano/cip509/rbac/certs/x509.rs | 5 +- .../src/cardano/cip509/rbac/metadata.rs | 28 +++-- .../src/cardano/cip509/rbac/pub_key.rs | 5 +- .../src/cardano/cip509/rbac/role_data.rs | 13 ++- .../src/cardano/cip509/types/key_local_ref.rs | 5 +- .../cardano/cip509/types/payment_history.rs | 5 +- .../src/cardano/cip509/types/point_data.rs | 5 +- .../src/cardano/cip509/types/point_tx_idx.rs | 10 +- .../src/cardano/cip509/types/role_data.rs | 26 ++++- .../cardano/cip509/types/role_data_record.rs | 32 ++++-- .../cardano/cip509/utils/cip134_uri_set.rs | 24 ++++- .../src/cardano/cip509/utils/cip19.rs | 4 +- .../src/cardano/cip509/utils/extract_key.rs | 6 +- .../src/cardano/cip509/validation.rs | 52 +++++++-- .../src/cardano/cip509/x509_chunks.rs | 10 +- .../src/registration/cardano/mod.rs | 40 +++++-- .../src/registration/cardano/update_rbac.rs | 23 ++-- rust/rbac-registration/src/utils/test.rs | 5 +- rust/rustfmt.toml | 6 +- rust/signed_doc/bins/mk_signed_doc.rs | 10 +- rust/signed_doc/src/builder.rs | 14 ++- rust/signed_doc/src/content.rs | 7 +- rust/signed_doc/src/lib.rs | 14 ++- .../src/metadata/content_encoding.rs | 15 ++- rust/signed_doc/src/metadata/content_type.rs | 10 +- rust/signed_doc/src/metadata/document_ref.rs | 5 +- rust/signed_doc/src/metadata/extra_fields.rs | 6 +- rust/signed_doc/src/metadata/mod.rs | 16 ++- rust/signed_doc/src/metadata/section.rs | 14 ++- rust/signed_doc/src/metadata/utils.rs | 16 ++- rust/signed_doc/src/providers.rs | 25 +++-- rust/signed_doc/src/signature/mod.rs | 17 ++- rust/signed_doc/src/validator/mod.rs | 22 ++-- .../src/validator/rules/content_encoding.rs | 5 +- .../src/validator/rules/content_type.rs | 5 +- .../signed_doc/src/validator/rules/doc_ref.rs | 13 ++- rust/signed_doc/src/validator/rules/mod.rs | 8 +- .../src/validator/rules/parameters.rs | 8 +- rust/signed_doc/src/validator/rules/reply.rs | 8 +- .../signed_doc/src/validator/rules/section.rs | 5 +- .../src/validator/rules/signature_kid.rs | 5 +- .../src/validator/rules/template.rs | 16 ++- rust/signed_doc/src/validator/utils.rs | 5 +- rust/signed_doc/tests/common/mod.rs | 8 +- rust/vote-tx-v1/src/decoding.rs | 13 ++- rust/vote-tx-v1/src/lib.rs | 58 +++++++--- rust/vote-tx-v2/src/encoded_cbor.rs | 9 +- rust/vote-tx-v2/src/gen_tx/builder.rs | 20 +++- rust/vote-tx-v2/src/gen_tx/event_map.rs | 18 +++- rust/vote-tx-v2/src/gen_tx/mod.rs | 21 +++- rust/vote-tx-v2/src/gen_tx/tx_body.rs | 9 +- rust/vote-tx-v2/src/gen_tx/vote.rs | 9 +- rust/vote-tx-v2/src/public_tx/mod.rs | 15 ++- rust/vote-tx-v2/src/public_tx/vote.rs | 18 +++- rust/vote-tx-v2/src/uuid.rs | 9 +- 162 files changed, 2335 insertions(+), 654 deletions(-) diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml index cd8aa55e3ea..317a7a8456d 100644 --- a/rust/.cargo/config.toml +++ b/rust/.cargo/config.toml @@ -14,7 +14,7 @@ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=-crt-static" + "-C", "target-feature=+crt-static" ] # Should be the default to have fully static rust programs in CI @@ -22,7 +22,7 @@ rustflags = [ linker = "clang" rustflags = [ "-C", "link-arg=-fuse-ld=/usr/bin/mold", - "-C", "target-feature=-crt-static" + "-C", "target-feature=+crt-static" ] [build] diff --git a/rust/.config/nextest.toml b/rust/.config/nextest.toml index be3673830bb..e74e1ac35e7 100644 --- a/rust/.config/nextest.toml +++ b/rust/.config/nextest.toml @@ -47,3 +47,14 @@ store-success-output = true # Note that if a description can be extracted from the output, it is always stored in the # element. store-failure-output = true + +[test-groups] +serial-integration = { max-threads = 1 } + +[[profile.default.overrides]] +filter = 'test(/^serial::/)' +test-group = 'serial-integration' + +[[profile.ci.overrides]] +filter = 'test(/^serial::/)' +test-group = "serial-integration" \ No newline at end of file diff --git a/rust/c509-certificate/examples/cli/main.rs b/rust/c509-certificate/examples/cli/main.rs index cf80c5fc85c..e63d9e5f8cd 100644 --- a/rust/c509-certificate/examples/cli/main.rs +++ b/rust/c509-certificate/examples/cli/main.rs @@ -142,7 +142,9 @@ const SELF_SIGNED_INT: u8 = 2; /// A function to generate C509 certificate. fn generate( - file: &PathBuf, output: Option, private_key: Option<&PrivateKey>, + file: &PathBuf, + output: Option, + private_key: Option<&PrivateKey>, key_type: Option, ) -> anyhow::Result<()> { let data = fs::read_to_string(file)?; @@ -209,7 +211,10 @@ fn generate( } /// Write a data to a file given an output path. -fn write_to_output_file(output: PathBuf, data: &[u8]) -> anyhow::Result<()> { +fn write_to_output_file( + output: PathBuf, + data: &[u8], +) -> anyhow::Result<()> { let mut file = File::create(output).map_err(|e| anyhow::anyhow!(e))?; file.write_all(data).map_err(|e| anyhow::anyhow!(e))?; Ok(()) @@ -219,7 +224,9 @@ fn write_to_output_file(output: PathBuf, data: &[u8]) -> anyhow::Result<()> { /// If self-signed is true, issuer is the same as subject. /// Otherwise, issuer must be present. fn determine_issuer( - self_signed: bool, issuer: Option>, subject: Vec, + self_signed: bool, + issuer: Option>, + subject: Vec, ) -> anyhow::Result> { if self_signed { Ok(subject) @@ -230,7 +237,8 @@ fn determine_issuer( /// Validate the certificate type. fn validate_certificate_type( - self_signed: bool, certificate_type: Option, + self_signed: bool, + certificate_type: Option, ) -> anyhow::Result<()> { if self_signed && certificate_type.unwrap_or(SELF_SIGNED_INT) != SELF_SIGNED_INT { return Err(anyhow::anyhow!( @@ -260,7 +268,10 @@ fn get_key_type(key_type: Option) -> anyhow::Result<(Oid<'static>, Optio } /// Parse date string to u64. -fn parse_or_default_date(date_option: Option, default: u64) -> Result { +fn parse_or_default_date( + date_option: Option, + default: u64, +) -> Result { match date_option { Some(date) => { DateTime::parse_from_rfc3339(&date) @@ -284,7 +295,10 @@ fn parse_serial_number(serial_number: Option) -> UnwrappedBigU // -------------------verify----------------------- /// Verify the signature of the certificate given public key file path. -fn verify(file: &PathBuf, public_key: PathBuf) -> anyhow::Result<()> { +fn verify( + file: &PathBuf, + public_key: PathBuf, +) -> anyhow::Result<()> { let cert = fs::read(file)?; let pk = PublicKey::from_file(public_key)?; match c509_certificate::verify(&cert, &pk) { @@ -297,7 +311,10 @@ fn verify(file: &PathBuf, public_key: PathBuf) -> anyhow::Result<()> { // -------------------decode----------------------- /// Decode the certificate to JSON. -fn decode(file: &PathBuf, output: Option) -> anyhow::Result<()> { +fn decode( + file: &PathBuf, + output: Option, +) -> anyhow::Result<()> { let cert = fs::read(file)?; let mut d = minicbor::Decoder::new(&cert); let c509 = c509_certificate::c509::C509::decode(&mut d, &mut ())?; diff --git a/rust/c509-certificate/src/algorithm_identifier.rs b/rust/c509-certificate/src/algorithm_identifier.rs index c30d7d32bf7..a8a7fc95c64 100644 --- a/rust/c509-certificate/src/algorithm_identifier.rs +++ b/rust/c509-certificate/src/algorithm_identifier.rs @@ -36,7 +36,10 @@ pub struct AlgorithmIdentifier { impl AlgorithmIdentifier { /// Create new instance of `AlgorithmIdentifier`. #[must_use] - pub fn new(oid: Oid<'static>, param: Option) -> Self { + pub fn new( + oid: Oid<'static>, + param: Option, + ) -> Self { Self { c509_oid: C509oid::new(oid), param, @@ -58,7 +61,9 @@ impl AlgorithmIdentifier { impl Encode<()> for AlgorithmIdentifier { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { match &self.param { // [ algorithm: ~oid, parameters: bytes ] @@ -77,7 +82,10 @@ impl Encode<()> for AlgorithmIdentifier { } impl Decode<'_, ()> for AlgorithmIdentifier { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { // [ algorithm: ~oid, parameters: bytes ] if decode_datatype(d, "Algorithm Identifier")? == minicbor::data::Type::Array { let len = decode_array_len(d, "Algorithm Identifier")?; diff --git a/rust/c509-certificate/src/attributes/attribute.rs b/rust/c509-certificate/src/attributes/attribute.rs index 4a179e18915..f1629ce41f4 100644 --- a/rust/c509-certificate/src/attributes/attribute.rs +++ b/rust/c509-certificate/src/attributes/attribute.rs @@ -63,7 +63,10 @@ impl Attribute { } /// Add a value to `Attribute`. - pub fn add_value(&mut self, value: AttributeValue) { + pub fn add_value( + &mut self, + value: AttributeValue, + ) { self.value.push(value); } @@ -98,8 +101,13 @@ impl<'de> Deserialize<'de> for Attribute { } impl Serialize for Attribute { - fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer { + fn serialize( + &self, + serializer: S, + ) -> Result + where + S: serde::Serializer, + { let helper = Helper { oid: self.registered_oid().c509_oid().oid().to_string(), value: self.value.clone(), @@ -110,7 +118,9 @@ impl Serialize for Attribute { impl Encode<()> for Attribute { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { // Encode CBOR int if available if let Some(&oid) = self @@ -145,7 +155,10 @@ impl Encode<()> for Attribute { } impl Decode<'_, ()> for Attribute { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { // Handle CBOR int let mut attr = if decode_datatype(d, "Attribute as OID int")? == minicbor::data::Type::U8 { let i = decode_helper(d, "Attribute as OID int", ctx)?; @@ -193,7 +206,9 @@ pub enum AttributeValue { impl Encode<()> for AttributeValue { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { match self { AttributeValue::Text(text) => encode_helper(e, "Attribute value", ctx, text)?, @@ -204,7 +219,10 @@ impl Encode<()> for AttributeValue { } impl Decode<'_, ()> for AttributeValue { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { match decode_datatype(d, "Attribute value")? { minicbor::data::Type::String => { Ok(AttributeValue::Text(decode_helper( diff --git a/rust/c509-certificate/src/attributes/mod.rs b/rust/c509-certificate/src/attributes/mod.rs index e608244c444..ed16375c4d6 100644 --- a/rust/c509-certificate/src/attributes/mod.rs +++ b/rust/c509-certificate/src/attributes/mod.rs @@ -41,7 +41,10 @@ impl Attributes { /// Add an `Attribute` to the `Attributes`. /// and set `Attribute` value to support multiple value. - pub fn add_attribute(&mut self, attribute: Attribute) { + pub fn add_attribute( + &mut self, + attribute: Attribute, + ) { self.0.push(attribute.set_multi_value()); } } @@ -54,7 +57,9 @@ impl Default for Attributes { impl Encode<()> for Attributes { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { if self.0.is_empty() { return Err(minicbor::encode::Error::message( @@ -74,7 +79,10 @@ impl Encode<()> for Attributes { } impl Decode<'_, ()> for Attributes { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { let len = decode_array_len(d, "Attributes")?; if len == 0 { return Err(minicbor::decode::Error::message("Attributes is empty")); diff --git a/rust/c509-certificate/src/big_uint.rs b/rust/c509-certificate/src/big_uint.rs index a6e67ad0a56..cba17bad52e 100644 --- a/rust/c509-certificate/src/big_uint.rs +++ b/rust/c509-certificate/src/big_uint.rs @@ -36,7 +36,9 @@ impl From for u64 { impl Encode<()> for UnwrappedBigUint { fn encode( - &self, e: &mut Encoder, _ctx: &mut (), + &self, + e: &mut Encoder, + _ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { let bytes = self.0.to_be_bytes(); // Trim leading zeros @@ -52,7 +54,10 @@ impl Encode<()> for UnwrappedBigUint { } impl Decode<'_, ()> for UnwrappedBigUint { - fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + _ctx: &mut (), + ) -> Result { // Turn bytes into u64 let b = decode_bytes(d, "Unwrapped big uint")? .iter() diff --git a/rust/c509-certificate/src/c509.rs b/rust/c509-certificate/src/c509.rs index 4018740e240..ca1369b998c 100644 --- a/rust/c509-certificate/src/c509.rs +++ b/rust/c509-certificate/src/c509.rs @@ -23,7 +23,10 @@ pub struct C509 { impl C509 { /// Create a new instance of C509 Certificate . #[must_use] - pub fn new(tbs_cert: TbsCert, issuer_signature_value: Option>) -> Self { + pub fn new( + tbs_cert: TbsCert, + issuer_signature_value: Option>, + ) -> Self { Self { tbs_cert, issuer_signature_value, @@ -45,7 +48,9 @@ impl C509 { impl Encode<()> for C509 { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { self.tbs_cert.encode(e, ctx)?; match self.issuer_signature_value { @@ -57,7 +62,10 @@ impl Encode<()> for C509 { } impl Decode<'_, ()> for C509 { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { let tbs_cert = TbsCert::decode(d, ctx)?; let issuer_signature_value = match decode_datatype(d, "C509 Issuer Signature value")? { minicbor::data::Type::Bytes => Some(decode_bytes(d, "C509 Issuer Signature value")?), diff --git a/rust/c509-certificate/src/cert_tbs.rs b/rust/c509-certificate/src/cert_tbs.rs index fc88dbdbfa7..695b4efcece 100644 --- a/rust/c509-certificate/src/cert_tbs.rs +++ b/rust/c509-certificate/src/cert_tbs.rs @@ -48,10 +48,15 @@ impl TbsCert { #[must_use] #[allow(clippy::too_many_arguments)] pub fn new( - c509_certificate_type: u8, certificate_serial_number: UnwrappedBigUint, - issuer_signature_algorithm: IssuerSignatureAlgorithm, issuer: Option, - validity_not_before: Time, validity_not_after: Time, subject: Name, - subject_public_key_algorithm: SubjectPubKeyAlgorithm, subject_public_key: Vec, + c509_certificate_type: u8, + certificate_serial_number: UnwrappedBigUint, + issuer_signature_algorithm: IssuerSignatureAlgorithm, + issuer: Option, + validity_not_before: Time, + validity_not_after: Time, + subject: Name, + subject_public_key_algorithm: SubjectPubKeyAlgorithm, + subject_public_key: Vec, extensions: Extensions, ) -> Self { Self { @@ -149,7 +154,9 @@ impl TbsCert { impl Encode<()> for TbsCert { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { encode_helper(e, "Certificate type", ctx, &self.c509_certificate_type)?; self.certificate_serial_number.encode(e, ctx)?; @@ -166,7 +173,10 @@ impl Encode<()> for TbsCert { } impl Decode<'_, ()> for TbsCert { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { let cert_type = decode_helper(d, "Certificate type", ctx)?; let serial_number = UnwrappedBigUint::decode(d, ctx)?; let issuer_signature_algorithm = IssuerSignatureAlgorithm::decode(d, ctx)?; diff --git a/rust/c509-certificate/src/extensions/alt_name.rs b/rust/c509-certificate/src/extensions/alt_name.rs index 0f9896c8588..f977219ca0d 100644 --- a/rust/c509-certificate/src/extensions/alt_name.rs +++ b/rust/c509-certificate/src/extensions/alt_name.rs @@ -36,14 +36,19 @@ impl AlternativeName { impl Encode<()> for AlternativeName { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { self.0.encode(e, ctx) } } impl Decode<'_, ()> for AlternativeName { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { GeneralNamesOrText::decode(d, ctx).map(AlternativeName::new) } } @@ -64,7 +69,9 @@ pub enum GeneralNamesOrText { impl Encode<()> for GeneralNamesOrText { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { match self { GeneralNamesOrText::GeneralNames(gns) => { @@ -88,7 +95,10 @@ impl Encode<()> for GeneralNamesOrText { } impl Decode<'_, ()> for GeneralNamesOrText { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { match decode_datatype(d, "Alternative Name - General Names")? { // If it is a string it is a GeneralNames with only 1 DNSName minicbor::data::Type::String => { diff --git a/rust/c509-certificate/src/extensions/extension/mod.rs b/rust/c509-certificate/src/extensions/extension/mod.rs index c442d7ccad6..57061923e35 100644 --- a/rust/c509-certificate/src/extensions/extension/mod.rs +++ b/rust/c509-certificate/src/extensions/extension/mod.rs @@ -33,7 +33,11 @@ pub struct Extension { impl Extension { /// Create a new instance of `Extension` using `OID` and value. #[must_use] - pub fn new(oid: Oid<'static>, value: ExtensionValue, critical: bool) -> Self { + pub fn new( + oid: Oid<'static>, + value: ExtensionValue, + critical: bool, + ) -> Self { Self { registered_oid: C509oidRegistered::new(oid, EXTENSIONS_LOOKUP.get_int_to_oid_table()), critical, @@ -83,8 +87,13 @@ impl<'de> Deserialize<'de> for Extension { } impl Serialize for Extension { - fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer { + fn serialize( + &self, + serializer: S, + ) -> Result + where + S: serde::Serializer, + { let helper = Helper { oid: self.registered_oid.c509_oid().oid().to_string(), value: self.value.clone(), @@ -99,7 +108,9 @@ impl Encode<()> for Extension { // - (extensionID: int, extensionValue: any) // - (extensionID: ~oid, ? critical: true, extensionValue: bytes) fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { // Handle CBOR int based on OID mapping if let Some(&mapped_oid) = self @@ -133,7 +144,10 @@ impl Encode<()> for Extension { } impl Decode<'_, ()> for Extension { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { match decode_datatype(d, "Extension")? { // Check whether OID is an int // Even the encoding is i16, the minicbor decoder doesn't know what type we encoded, @@ -214,7 +228,9 @@ impl ExtensionValueTypeTrait for ExtensionValueType { impl Encode<()> for ExtensionValue { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { match self { ExtensionValue::Int(value) => { @@ -239,7 +255,10 @@ impl Encode<()> for ExtensionValue { impl Decode<'_, C> for ExtensionValue where C: ExtensionValueTypeTrait + Debug { - fn decode(d: &mut Decoder<'_>, ctx: &mut C) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut C, + ) -> Result { match ctx.get_type() { ExtensionValueType::Int => { let value = decode_helper(d, "Extension value", ctx)?; diff --git a/rust/c509-certificate/src/extensions/mod.rs b/rust/c509-certificate/src/extensions/mod.rs index 5f1a99d579e..112123a4a04 100644 --- a/rust/c509-certificate/src/extensions/mod.rs +++ b/rust/c509-certificate/src/extensions/mod.rs @@ -49,7 +49,10 @@ impl Extensions { } /// Add an `Extension` to the `Extensions`. - pub fn add_extension(&mut self, extension: Extension) { + pub fn add_extension( + &mut self, + extension: Extension, + ) { self.0.push(extension); } } @@ -62,7 +65,9 @@ impl Default for Extensions { impl Encode<()> for Extensions { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { // If there is only one extension and it is KeyUsage, encode as int // encoding as absolute value of the second int and the sign of the first int @@ -98,7 +103,10 @@ impl Encode<()> for Extensions { } impl Decode<'_, ()> for Extensions { - fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + _ctx: &mut (), + ) -> Result { // If only KeyUsage is in the extension -> will only contain an int if decode_datatype(d, "Extensions KeyUsage")? == minicbor::data::Type::U8 || decode_datatype(d, "Extensions KeyUsage")? == minicbor::data::Type::I8 diff --git a/rust/c509-certificate/src/general_names/data.rs b/rust/c509-certificate/src/general_names/data.rs index 0099a381839..45b73fe933a 100644 --- a/rust/c509-certificate/src/general_names/data.rs +++ b/rust/c509-certificate/src/general_names/data.rs @@ -69,7 +69,11 @@ impl IntegerToGNTable { } /// Add a new integer to `GeneralNameTypeRegistry` map table. - pub(crate) fn add(&mut self, k: i16, v: GeneralNameTypeRegistry) { + pub(crate) fn add( + &mut self, + k: i16, + v: GeneralNameTypeRegistry, + ) { self.0.add(k, v); } diff --git a/rust/c509-certificate/src/general_names/general_name.rs b/rust/c509-certificate/src/general_names/general_name.rs index 990bde6a82d..2e5d6b81862 100644 --- a/rust/c509-certificate/src/general_names/general_name.rs +++ b/rust/c509-certificate/src/general_names/general_name.rs @@ -42,7 +42,10 @@ pub struct GeneralName { impl GeneralName { /// Create a new instance of `GeneralName`. #[must_use] - pub fn new(gn_type: GeneralNameTypeRegistry, value: GeneralNameValue) -> Self { + pub fn new( + gn_type: GeneralNameTypeRegistry, + value: GeneralNameValue, + ) -> Self { Self { gn_type, value } } @@ -61,7 +64,9 @@ impl GeneralName { impl Encode<()> for GeneralName { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { // Encode GeneralNameType as int let i = get_int_from_gn(self.gn_type).map_err(minicbor::encode::Error::message)?; @@ -73,7 +78,10 @@ impl Encode<()> for GeneralName { } impl Decode<'_, ()> for GeneralName { - fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + _ctx: &mut (), + ) -> Result { if decode_datatype(d, "General Name as OID int")? == minicbor::data::Type::U8 || decode_datatype(d, "General Name as OID int")? == minicbor::data::Type::I8 { @@ -158,7 +166,9 @@ impl GeneralNameValueTrait for GeneralNameValueType { impl Encode<()> for GeneralNameValue { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { match self { GeneralNameValue::Text(value) => { @@ -188,7 +198,10 @@ impl Encode<()> for GeneralNameValue { impl Decode<'_, C> for GeneralNameValue where C: GeneralNameValueTrait + Debug { - fn decode(d: &mut Decoder<'_>, ctx: &mut C) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut C, + ) -> Result { match ctx.get_type() { GeneralNameValueType::Text => { let value = decode_helper(d, "General Name value", ctx)?; diff --git a/rust/c509-certificate/src/general_names/mod.rs b/rust/c509-certificate/src/general_names/mod.rs index 996a5a5a000..d681380287a 100644 --- a/rust/c509-certificate/src/general_names/mod.rs +++ b/rust/c509-certificate/src/general_names/mod.rs @@ -38,7 +38,10 @@ impl GeneralNames { } /// Add a new `GeneralName` to the `GeneralNames`. - pub fn add_general_name(&mut self, gn: GeneralName) { + pub fn add_general_name( + &mut self, + gn: GeneralName, + ) { self.0.push(gn); } } @@ -51,7 +54,9 @@ impl Default for GeneralNames { impl Encode<()> for GeneralNames { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { if self.0.is_empty() { return Err(minicbor::encode::Error::message( @@ -71,7 +76,10 @@ impl Encode<()> for GeneralNames { } impl Decode<'_, ()> for GeneralNames { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { let len = decode_array_len(d, "General Names")?; let mut gn = GeneralNames::new(); for _ in 0..len / 2 { diff --git a/rust/c509-certificate/src/general_names/other_name_hw_module.rs b/rust/c509-certificate/src/general_names/other_name_hw_module.rs index 7e2660cc088..b9f14e5c8e4 100644 --- a/rust/c509-certificate/src/general_names/other_name_hw_module.rs +++ b/rust/c509-certificate/src/general_names/other_name_hw_module.rs @@ -29,7 +29,10 @@ pub struct OtherNameHardwareModuleName { impl OtherNameHardwareModuleName { /// Create a new instance of `OtherNameHardwareModuleName`. #[must_use] - pub fn new(hw_type: Oid<'static>, hw_serial_num: Vec) -> Self { + pub fn new( + hw_type: Oid<'static>, + hw_serial_num: Vec, + ) -> Self { Self { hw_type: C509oid::new(hw_type), hw_serial_num, @@ -51,7 +54,9 @@ impl OtherNameHardwareModuleName { impl Encode<()> for OtherNameHardwareModuleName { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { encode_array_len(e, "OtherNameHardwareModule", 2)?; self.hw_type.encode(e, ctx)?; @@ -65,7 +70,10 @@ impl Encode<()> for OtherNameHardwareModuleName { } impl<'a> Decode<'a, ()> for OtherNameHardwareModuleName { - fn decode(d: &mut Decoder<'a>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'a>, + ctx: &mut (), + ) -> Result { decode_array_len(d, "OtherNameHardwareModule")?; let hw_type = C509oid::decode(d, ctx)?; let hw_serial_num = decode_bytes(d, "OtherNameHardwareModule serial number")?; diff --git a/rust/c509-certificate/src/helper/decode.rs b/rust/c509-certificate/src/helper/decode.rs index d43ef62e5e7..6f219560afb 100644 --- a/rust/c509-certificate/src/helper/decode.rs +++ b/rust/c509-certificate/src/helper/decode.rs @@ -4,9 +4,13 @@ use minicbor::{decode, Decoder}; /// Generic helper function for decoding different types. pub(crate) fn decode_helper<'a, T, C>( - d: &mut Decoder<'a>, from: &str, context: &mut C, + d: &mut Decoder<'a>, + from: &str, + context: &mut C, ) -> Result -where T: minicbor::Decode<'a, C> { +where + T: minicbor::Decode<'a, C>, +{ T::decode(d, context).map_err(|e| { decode::Error::message(format!( "Failed to decode {:?} in {from}: {e}", @@ -16,7 +20,10 @@ where T: minicbor::Decode<'a, C> { } /// Helper function for decoding bytes. -pub(crate) fn decode_bytes(d: &mut Decoder, from: &str) -> Result, decode::Error> { +pub(crate) fn decode_bytes( + d: &mut Decoder, + from: &str, +) -> Result, decode::Error> { d.bytes().map(<[u8]>::to_vec).map_err(|e| { decode::Error::message(format!( "Failed to decode bytes in {from}: @@ -26,7 +33,10 @@ pub(crate) fn decode_bytes(d: &mut Decoder, from: &str) -> Result, decod } /// Helper function for decoding array. -pub(crate) fn decode_array_len(d: &mut Decoder, from: &str) -> Result { +pub(crate) fn decode_array_len( + d: &mut Decoder, + from: &str, +) -> Result { d.array() .map_err(|e| { decode::Error::message(format!( @@ -40,7 +50,10 @@ pub(crate) fn decode_array_len(d: &mut Decoder, from: &str) -> Result Result<(), decode::Error> { +pub(crate) fn decode_null( + d: &mut Decoder, + from: &str, +) -> Result<(), decode::Error> { d.null().map_err(|e| { decode::Error::message(format!( "Failed to decode null in {from}: @@ -51,7 +64,8 @@ pub(crate) fn decode_null(d: &mut Decoder, from: &str) -> Result<(), decode::Err /// Helper function for decoding datatype. pub(crate) fn decode_datatype( - d: &mut Decoder, from: &str, + d: &mut Decoder, + from: &str, ) -> Result { d.datatype().map_err(|e| { decode::Error::message(format!( diff --git a/rust/c509-certificate/src/helper/encode.rs b/rust/c509-certificate/src/helper/encode.rs index 3184ce0a4cd..286b9ba329f 100644 --- a/rust/c509-certificate/src/helper/encode.rs +++ b/rust/c509-certificate/src/helper/encode.rs @@ -7,9 +7,14 @@ use minicbor::{ /// Generic helper function for encoding different types. pub(crate) fn encode_helper( - e: &mut Encoder, from: &str, ctx: &mut C, value: &T, + e: &mut Encoder, + from: &str, + ctx: &mut C, + value: &T, ) -> Result<(), encode::Error> -where T: minicbor::Encode { +where + T: minicbor::Encode, +{ T::encode(value, e, ctx).map_err(|err| { encode::Error::with_message( err, @@ -25,7 +30,9 @@ where T: minicbor::Encode { /// Helper function for encoding bytes. pub(crate) fn encode_bytes( - e: &mut Encoder, from: &str, value: &[u8], + e: &mut Encoder, + from: &str, + value: &[u8], ) -> Result<(), encode::Error> { e.bytes(value).map_err(|err| { encode::Error::with_message(err, format!("Failed to encode bytes in {from}")) @@ -35,7 +42,8 @@ pub(crate) fn encode_bytes( /// Helper function for encoding null. pub(crate) fn encode_null( - e: &mut Encoder, from: &str, + e: &mut Encoder, + from: &str, ) -> Result<(), encode::Error> { e.null().map_err(|err| { encode::Error::with_message(err, format!("Failed to encode null in {from}")) @@ -45,7 +53,9 @@ pub(crate) fn encode_null( /// Helper function for encoding array. pub(crate) fn encode_array_len( - e: &mut Encoder, from: &str, len: u64, + e: &mut Encoder, + from: &str, + len: u64, ) -> Result<(), encode::Error> { e.array(len).map_err(|err| { encode::Error::with_message(err, format!("Failed to encode array in {from}")) diff --git a/rust/c509-certificate/src/issuer_sig_algo/mod.rs b/rust/c509-certificate/src/issuer_sig_algo/mod.rs index 3fb049d2fae..87156343539 100644 --- a/rust/c509-certificate/src/issuer_sig_algo/mod.rs +++ b/rust/c509-certificate/src/issuer_sig_algo/mod.rs @@ -38,7 +38,10 @@ pub struct IssuerSignatureAlgorithm { impl IssuerSignatureAlgorithm { /// Create new instance of `IssuerSignatureAlgorithm` where it registered with /// Issuer Signature Algorithm lookup table. - pub fn new(oid: Oid<'static>, param: Option) -> Self { + pub fn new( + oid: Oid<'static>, + param: Option, + ) -> Self { Self { registered_oid: C509oidRegistered::new( oid.clone(), @@ -82,8 +85,13 @@ impl<'de> Deserialize<'de> for IssuerSignatureAlgorithm { } impl Serialize for IssuerSignatureAlgorithm { - fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer { + fn serialize( + &self, + serializer: S, + ) -> Result + where + S: serde::Serializer, + { let helper = Helper { oid: self.registered_oid.c509_oid().oid().to_string(), param: self.algo_identifier.param().clone(), @@ -94,7 +102,9 @@ impl Serialize for IssuerSignatureAlgorithm { impl Encode<()> for IssuerSignatureAlgorithm { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { if let Some(&i) = self .registered_oid @@ -111,7 +121,10 @@ impl Encode<()> for IssuerSignatureAlgorithm { } impl Decode<'_, ()> for IssuerSignatureAlgorithm { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { match decode_datatype(d, "Issuer Signature Algorithm")? { // Check i16 for -256 and -256 minicbor::data::Type::U8 | minicbor::data::Type::I16 => { diff --git a/rust/c509-certificate/src/lib.rs b/rust/c509-certificate/src/lib.rs index b2292d9eaf7..c72952aa344 100644 --- a/rust/c509-certificate/src/lib.rs +++ b/rust/c509-certificate/src/lib.rs @@ -79,7 +79,10 @@ pub mod time; /// # Errors /// /// Returns an error if the generated data is invalid. -pub fn generate(tbs_cert: &TbsCert, private_key: Option<&PrivateKey>) -> anyhow::Result> { +pub fn generate( + tbs_cert: &TbsCert, + private_key: Option<&PrivateKey>, +) -> anyhow::Result> { // Encode the TbsCert let encoded_tbs = { let mut buffer = Vec::new(); @@ -109,7 +112,10 @@ pub fn generate(tbs_cert: &TbsCert, private_key: Option<&PrivateKey>) -> anyhow: /// # Errors /// Returns an error if the `issuer_signature_value` is invalid or the signature cannot be /// verified. -pub fn verify(c509: &[u8], public_key: &PublicKey) -> anyhow::Result<()> { +pub fn verify( + c509: &[u8], + public_key: &PublicKey, +) -> anyhow::Result<()> { let mut d = minicbor::Decoder::new(c509); let c509 = C509::decode(&mut d, &mut ())?; let mut encoded_tbs = Vec::new(); diff --git a/rust/c509-certificate/src/name/mod.rs b/rust/c509-certificate/src/name/mod.rs index d5032a64fcc..9e118195ea6 100644 --- a/rust/c509-certificate/src/name/mod.rs +++ b/rust/c509-certificate/src/name/mod.rs @@ -57,14 +57,19 @@ impl Name { impl Encode<()> for Name { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { self.0.encode(e, ctx) } } impl Decode<'_, ()> for Name { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { NameValue::decode(d, ctx).map(Name::new) } } @@ -86,7 +91,9 @@ pub enum NameValue { impl Encode<()> for NameValue { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { match self { NameValue::Attribute(attrs) => { @@ -137,7 +144,10 @@ impl Encode<()> for NameValue { } impl Decode<'_, ()> for NameValue { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { match decode_datatype(d, "Name")? { minicbor::data::Type::Array => { let len = decode_array_len(d, "Attributes")?; @@ -166,7 +176,8 @@ impl Decode<'_, ()> for NameValue { /// Encode common name value. fn encode_cn_value( - e: &mut Encoder, cn_value: &AttributeValue, + e: &mut Encoder, + cn_value: &AttributeValue, ) -> Result<(), minicbor::encode::Error> { let hex_regex = Regex::new(r"^[0-9a-f]+$").map_err(minicbor::encode::Error::message)?; let eui64_regex = diff --git a/rust/c509-certificate/src/oid.rs b/rust/c509-certificate/src/oid.rs index db4524a518e..a426507f4ed 100644 --- a/rust/c509-certificate/src/oid.rs +++ b/rust/c509-certificate/src/oid.rs @@ -28,7 +28,10 @@ pub struct C509oidRegistered { impl C509oidRegistered { /// Create a new instance of `C509oidRegistered`. - pub(crate) fn new(oid: Oid<'static>, table: &'static IntegerToOidTable) -> Self { + pub(crate) fn new( + oid: Oid<'static>, + table: &'static IntegerToOidTable, + ) -> Self { Self { c509_oid: C509oid::new(oid), registration_table: table, @@ -85,8 +88,13 @@ impl<'de> Deserialize<'de> for C509oid { } impl Serialize for C509oid { - fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer { + fn serialize( + &self, + serializer: S, + ) -> Result + where + S: serde::Serializer, + { let helper = Helper { oid: self.0.to_string(), }; @@ -103,7 +111,9 @@ impl Encode<()> for C509oid { /// A vector of bytes containing the CBOR encoded OID. /// If the encoding fails, it will return an error. fn encode( - &self, e: &mut Encoder, _ctx: &mut (), + &self, + e: &mut Encoder, + _ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { let oid_bytes = self.0.as_bytes(); encode_bytes(e, "C509 OID", oid_bytes) @@ -118,7 +128,10 @@ impl Decode<'_, ()> for C509oid { /// /// A C509oid instance. /// If the decoding fails, it will return an error. - fn decode(d: &mut Decoder, _ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder, + _ctx: &mut (), + ) -> Result { let oid_bytes = decode_bytes(d, "C509 OID")?; let oid = Oid::new(oid_bytes.into()); Ok(C509oid::new(oid)) diff --git a/rust/c509-certificate/src/signing.rs b/rust/c509-certificate/src/signing.rs index 6fc732c8ad4..b50b8b6a7d8 100644 --- a/rust/c509-certificate/src/signing.rs +++ b/rust/c509-certificate/src/signing.rs @@ -33,12 +33,18 @@ struct FileError { #[allow(dead_code)] impl FileError { /// Create a new `FileError` instance from a string location. - fn from_string(location: String, msg: Option) -> Self { + fn from_string( + location: String, + msg: Option, + ) -> Self { Self { location, msg } } /// Create a new `FileError` instance from a path location. - fn from_path>(path: P, msg: Option) -> Self { + fn from_path>( + path: P, + msg: Option, + ) -> Self { Self { location: path.as_ref().display().to_string(), msg, @@ -47,7 +53,10 @@ impl FileError { } impl Display for FileError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt( + &self, + f: &mut std::fmt::Formatter<'_>, + ) -> std::fmt::Result { let msg = format!("Cannot open or read file at {0}", self.location); let err = self .msg @@ -78,7 +87,10 @@ impl PrivateKey { /// Sign the message with the current private key. /// Returns the signature bytes. #[must_use] - pub fn sign(&self, msg: &[u8]) -> Vec { + pub fn sign( + &self, + msg: &[u8], + ) -> Vec { self.0.sign(msg).to_vec() } } @@ -128,7 +140,11 @@ impl PublicKey { /// /// # Errors /// Returns an error if the signature is invalid. - pub fn verify(&self, msg: &[u8], signature_bytes: &[u8]) -> anyhow::Result<()> { + pub fn verify( + &self, + msg: &[u8], + signature_bytes: &[u8], + ) -> anyhow::Result<()> { let signature_bytes = signature_bytes.try_into().map_err(|_| { anyhow::anyhow!( "Invalid signature bytes size: expected {}, provided {}.", diff --git a/rust/c509-certificate/src/subject_pub_key_algo/mod.rs b/rust/c509-certificate/src/subject_pub_key_algo/mod.rs index b3d923bd1c7..b379a75ad57 100644 --- a/rust/c509-certificate/src/subject_pub_key_algo/mod.rs +++ b/rust/c509-certificate/src/subject_pub_key_algo/mod.rs @@ -39,7 +39,10 @@ pub struct SubjectPubKeyAlgorithm { impl SubjectPubKeyAlgorithm { /// Create new instance of `SubjectPubKeyAlgorithm` where it registered with /// Subject Public Key Algorithm lookup table. - pub fn new(oid: Oid<'static>, param: Option) -> Self { + pub fn new( + oid: Oid<'static>, + param: Option, + ) -> Self { Self { registered_oid: C509oidRegistered::new( oid.clone(), @@ -83,8 +86,13 @@ impl<'de> Deserialize<'de> for SubjectPubKeyAlgorithm { } impl Serialize for SubjectPubKeyAlgorithm { - fn serialize(&self, serializer: S) -> Result - where S: serde::Serializer { + fn serialize( + &self, + serializer: S, + ) -> Result + where + S: serde::Serializer, + { let helper = Helper { oid: self.registered_oid.c509_oid().oid().to_string(), param: self.algo_identifier.param().clone(), @@ -95,7 +103,9 @@ impl Serialize for SubjectPubKeyAlgorithm { impl Encode<()> for SubjectPubKeyAlgorithm { fn encode( - &self, e: &mut Encoder, ctx: &mut (), + &self, + e: &mut Encoder, + ctx: &mut (), ) -> Result<(), minicbor::encode::Error> { if let Some(&i) = self .registered_oid @@ -112,7 +122,10 @@ impl Encode<()> for SubjectPubKeyAlgorithm { } impl Decode<'_, ()> for SubjectPubKeyAlgorithm { - fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result { + fn decode( + d: &mut Decoder<'_>, + ctx: &mut (), + ) -> Result { // Check u8 for 0 - 28 if decode_datatype(d, "Subject public key algorithm")? == minicbor::data::Type::U8 { let i = decode_helper(d, "Subject public key algorithm", ctx)?; diff --git a/rust/c509-certificate/src/tables.rs b/rust/c509-certificate/src/tables.rs index 67e83fde4fd..3c526115a66 100644 --- a/rust/c509-certificate/src/tables.rs +++ b/rust/c509-certificate/src/tables.rs @@ -15,7 +15,11 @@ pub(crate) trait TableTrait { /// Create new instance of the map table. fn new() -> Self; /// Add the key-value pair to the map table. - fn add(&mut self, k: K, v: V); + fn add( + &mut self, + k: K, + v: V, + ); /// Get the bimap of the map table. fn get_map(&self) -> &BiMap; } @@ -38,7 +42,11 @@ impl TableTrait for IntTable { } /// Add the key-value pair to the map table. - fn add(&mut self, k: i16, v: T) { + fn add( + &mut self, + k: i16, + v: T, + ) { self.map.insert(k, v); } @@ -67,7 +75,11 @@ impl IntegerToOidTable { } /// Add the key-value pair to the map table. - pub(crate) fn add(&mut self, k: i16, v: Oid<'static>) { + pub(crate) fn add( + &mut self, + k: i16, + v: Oid<'static>, + ) { self.table.add(k, v); } diff --git a/rust/c509-certificate/src/time.rs b/rust/c509-certificate/src/time.rs index b3e74a178f9..ae6ba280d8c 100644 --- a/rust/c509-certificate/src/time.rs +++ b/rust/c509-certificate/src/time.rs @@ -45,7 +45,9 @@ impl From