Skip to content

Commit 21a9a72

Browse files
authored
feat(general): new rustfmt rules (#461)
* bump rust-ci * update rustfmt.toml * apply fmt
1 parent 154c42e commit 21a9a72

File tree

170 files changed

+2529
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+2529
-716
lines changed

rust/Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
VERSION 0.8
22

3-
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.4.9 AS rust-ci
3+
IMPORT github.com/input-output-hk/catalyst-ci/earthly/rust:v3.5.3 AS rust-ci
44
IMPORT ../ AS repo-ci
55

66
COPY_SRC:

rust/c509-certificate/examples/cli/main.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ const SELF_SIGNED_INT: u8 = 2;
142142

143143
/// A function to generate C509 certificate.
144144
fn generate(
145-
file: &PathBuf, output: Option<PathBuf>, private_key: Option<&PrivateKey>,
145+
file: &PathBuf,
146+
output: Option<PathBuf>,
147+
private_key: Option<&PrivateKey>,
146148
key_type: Option<String>,
147149
) -> anyhow::Result<()> {
148150
let data = fs::read_to_string(file)?;
@@ -209,7 +211,10 @@ fn generate(
209211
}
210212

211213
/// Write a data to a file given an output path.
212-
fn write_to_output_file(output: PathBuf, data: &[u8]) -> anyhow::Result<()> {
214+
fn write_to_output_file(
215+
output: PathBuf,
216+
data: &[u8],
217+
) -> anyhow::Result<()> {
213218
let mut file = File::create(output).map_err(|e| anyhow::anyhow!(e))?;
214219
file.write_all(data).map_err(|e| anyhow::anyhow!(e))?;
215220
Ok(())
@@ -219,7 +224,9 @@ fn write_to_output_file(output: PathBuf, data: &[u8]) -> anyhow::Result<()> {
219224
/// If self-signed is true, issuer is the same as subject.
220225
/// Otherwise, issuer must be present.
221226
fn determine_issuer(
222-
self_signed: bool, issuer: Option<Vec<Attribute>>, subject: Vec<Attribute>,
227+
self_signed: bool,
228+
issuer: Option<Vec<Attribute>>,
229+
subject: Vec<Attribute>,
223230
) -> anyhow::Result<Vec<Attribute>> {
224231
if self_signed {
225232
Ok(subject)
@@ -230,7 +237,8 @@ fn determine_issuer(
230237

231238
/// Validate the certificate type.
232239
fn validate_certificate_type(
233-
self_signed: bool, certificate_type: Option<u8>,
240+
self_signed: bool,
241+
certificate_type: Option<u8>,
234242
) -> anyhow::Result<()> {
235243
if self_signed && certificate_type.unwrap_or(SELF_SIGNED_INT) != SELF_SIGNED_INT {
236244
return Err(anyhow::anyhow!(
@@ -260,7 +268,10 @@ fn get_key_type(key_type: Option<String>) -> anyhow::Result<(Oid<'static>, Optio
260268
}
261269

262270
/// Parse date string to u64.
263-
fn parse_or_default_date(date_option: Option<String>, default: u64) -> Result<u64, anyhow::Error> {
271+
fn parse_or_default_date(
272+
date_option: Option<String>,
273+
default: u64,
274+
) -> Result<u64, anyhow::Error> {
264275
match date_option {
265276
Some(date) => {
266277
DateTime::parse_from_rfc3339(&date)
@@ -284,7 +295,10 @@ fn parse_serial_number(serial_number: Option<UnwrappedBigUint>) -> UnwrappedBigU
284295
// -------------------verify-----------------------
285296

286297
/// Verify the signature of the certificate given public key file path.
287-
fn verify(file: &PathBuf, public_key: PathBuf) -> anyhow::Result<()> {
298+
fn verify(
299+
file: &PathBuf,
300+
public_key: PathBuf,
301+
) -> anyhow::Result<()> {
288302
let cert = fs::read(file)?;
289303
let pk = PublicKey::from_file(public_key)?;
290304
match c509_certificate::verify(&cert, &pk) {
@@ -297,7 +311,10 @@ fn verify(file: &PathBuf, public_key: PathBuf) -> anyhow::Result<()> {
297311
// -------------------decode-----------------------
298312

299313
/// Decode the certificate to JSON.
300-
fn decode(file: &PathBuf, output: Option<PathBuf>) -> anyhow::Result<()> {
314+
fn decode(
315+
file: &PathBuf,
316+
output: Option<PathBuf>,
317+
) -> anyhow::Result<()> {
301318
let cert = fs::read(file)?;
302319
let mut d = minicbor::Decoder::new(&cert);
303320
let c509 = c509_certificate::c509::C509::decode(&mut d, &mut ())?;

rust/c509-certificate/src/algorithm_identifier.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ pub struct AlgorithmIdentifier {
3636
impl AlgorithmIdentifier {
3737
/// Create new instance of `AlgorithmIdentifier`.
3838
#[must_use]
39-
pub fn new(oid: Oid<'static>, param: Option<String>) -> Self {
39+
pub fn new(
40+
oid: Oid<'static>,
41+
param: Option<String>,
42+
) -> Self {
4043
Self {
4144
c509_oid: C509oid::new(oid),
4245
param,
@@ -58,7 +61,9 @@ impl AlgorithmIdentifier {
5861

5962
impl Encode<()> for AlgorithmIdentifier {
6063
fn encode<W: Write>(
61-
&self, e: &mut Encoder<W>, ctx: &mut (),
64+
&self,
65+
e: &mut Encoder<W>,
66+
ctx: &mut (),
6267
) -> Result<(), minicbor::encode::Error<W::Error>> {
6368
match &self.param {
6469
// [ algorithm: ~oid, parameters: bytes ]
@@ -77,7 +82,10 @@ impl Encode<()> for AlgorithmIdentifier {
7782
}
7883

7984
impl Decode<'_, ()> for AlgorithmIdentifier {
80-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
85+
fn decode(
86+
d: &mut Decoder<'_>,
87+
ctx: &mut (),
88+
) -> Result<Self, minicbor::decode::Error> {
8189
// [ algorithm: ~oid, parameters: bytes ]
8290
if decode_datatype(d, "Algorithm Identifier")? == minicbor::data::Type::Array {
8391
let len = decode_array_len(d, "Algorithm Identifier")?;

rust/c509-certificate/src/attributes/attribute.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ impl Attribute {
6363
}
6464

6565
/// Add a value to `Attribute`.
66-
pub fn add_value(&mut self, value: AttributeValue) {
66+
pub fn add_value(
67+
&mut self,
68+
value: AttributeValue,
69+
) {
6770
self.value.push(value);
6871
}
6972

@@ -98,8 +101,13 @@ impl<'de> Deserialize<'de> for Attribute {
98101
}
99102

100103
impl Serialize for Attribute {
101-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
102-
where S: serde::Serializer {
104+
fn serialize<S>(
105+
&self,
106+
serializer: S,
107+
) -> Result<S::Ok, S::Error>
108+
where
109+
S: serde::Serializer,
110+
{
103111
let helper = Helper {
104112
oid: self.registered_oid().c509_oid().oid().to_string(),
105113
value: self.value.clone(),
@@ -110,7 +118,9 @@ impl Serialize for Attribute {
110118

111119
impl Encode<()> for Attribute {
112120
fn encode<W: Write>(
113-
&self, e: &mut Encoder<W>, ctx: &mut (),
121+
&self,
122+
e: &mut Encoder<W>,
123+
ctx: &mut (),
114124
) -> Result<(), minicbor::encode::Error<W::Error>> {
115125
// Encode CBOR int if available
116126
if let Some(&oid) = self
@@ -145,7 +155,10 @@ impl Encode<()> for Attribute {
145155
}
146156

147157
impl Decode<'_, ()> for Attribute {
148-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
158+
fn decode(
159+
d: &mut Decoder<'_>,
160+
ctx: &mut (),
161+
) -> Result<Self, minicbor::decode::Error> {
149162
// Handle CBOR int
150163
let mut attr = if decode_datatype(d, "Attribute as OID int")? == minicbor::data::Type::U8 {
151164
let i = decode_helper(d, "Attribute as OID int", ctx)?;
@@ -193,7 +206,9 @@ pub enum AttributeValue {
193206

194207
impl Encode<()> for AttributeValue {
195208
fn encode<W: Write>(
196-
&self, e: &mut Encoder<W>, ctx: &mut (),
209+
&self,
210+
e: &mut Encoder<W>,
211+
ctx: &mut (),
197212
) -> Result<(), minicbor::encode::Error<W::Error>> {
198213
match self {
199214
AttributeValue::Text(text) => encode_helper(e, "Attribute value", ctx, text)?,
@@ -204,7 +219,10 @@ impl Encode<()> for AttributeValue {
204219
}
205220

206221
impl Decode<'_, ()> for AttributeValue {
207-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
222+
fn decode(
223+
d: &mut Decoder<'_>,
224+
ctx: &mut (),
225+
) -> Result<Self, minicbor::decode::Error> {
208226
match decode_datatype(d, "Attribute value")? {
209227
minicbor::data::Type::String => {
210228
Ok(AttributeValue::Text(decode_helper(

rust/c509-certificate/src/attributes/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ impl Attributes {
4141

4242
/// Add an `Attribute` to the `Attributes`.
4343
/// and set `Attribute` value to support multiple value.
44-
pub fn add_attribute(&mut self, attribute: Attribute) {
44+
pub fn add_attribute(
45+
&mut self,
46+
attribute: Attribute,
47+
) {
4548
self.0.push(attribute.set_multi_value());
4649
}
4750
}
@@ -54,7 +57,9 @@ impl Default for Attributes {
5457

5558
impl Encode<()> for Attributes {
5659
fn encode<W: Write>(
57-
&self, e: &mut Encoder<W>, ctx: &mut (),
60+
&self,
61+
e: &mut Encoder<W>,
62+
ctx: &mut (),
5863
) -> Result<(), minicbor::encode::Error<W::Error>> {
5964
if self.0.is_empty() {
6065
return Err(minicbor::encode::Error::message(
@@ -74,7 +79,10 @@ impl Encode<()> for Attributes {
7479
}
7580

7681
impl Decode<'_, ()> for Attributes {
77-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
82+
fn decode(
83+
d: &mut Decoder<'_>,
84+
ctx: &mut (),
85+
) -> Result<Self, minicbor::decode::Error> {
7886
let len = decode_array_len(d, "Attributes")?;
7987
if len == 0 {
8088
return Err(minicbor::decode::Error::message("Attributes is empty"));

rust/c509-certificate/src/big_uint.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ impl From<UnwrappedBigUint> for u64 {
3636

3737
impl Encode<()> for UnwrappedBigUint {
3838
fn encode<W: Write>(
39-
&self, e: &mut Encoder<W>, _ctx: &mut (),
39+
&self,
40+
e: &mut Encoder<W>,
41+
_ctx: &mut (),
4042
) -> Result<(), minicbor::encode::Error<W::Error>> {
4143
let bytes = self.0.to_be_bytes();
4244
// Trim leading zeros
@@ -52,7 +54,10 @@ impl Encode<()> for UnwrappedBigUint {
5254
}
5355

5456
impl Decode<'_, ()> for UnwrappedBigUint {
55-
fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
57+
fn decode(
58+
d: &mut Decoder<'_>,
59+
_ctx: &mut (),
60+
) -> Result<Self, minicbor::decode::Error> {
5661
// Turn bytes into u64
5762
let b = decode_bytes(d, "Unwrapped big uint")?
5863
.iter()

rust/c509-certificate/src/c509.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ pub struct C509 {
2323
impl C509 {
2424
/// Create a new instance of C509 Certificate .
2525
#[must_use]
26-
pub fn new(tbs_cert: TbsCert, issuer_signature_value: Option<Vec<u8>>) -> Self {
26+
pub fn new(
27+
tbs_cert: TbsCert,
28+
issuer_signature_value: Option<Vec<u8>>,
29+
) -> Self {
2730
Self {
2831
tbs_cert,
2932
issuer_signature_value,
@@ -45,7 +48,9 @@ impl C509 {
4548

4649
impl Encode<()> for C509 {
4750
fn encode<W: Write>(
48-
&self, e: &mut Encoder<W>, ctx: &mut (),
51+
&self,
52+
e: &mut Encoder<W>,
53+
ctx: &mut (),
4954
) -> Result<(), minicbor::encode::Error<W::Error>> {
5055
self.tbs_cert.encode(e, ctx)?;
5156
match self.issuer_signature_value {
@@ -57,7 +62,10 @@ impl Encode<()> for C509 {
5762
}
5863

5964
impl Decode<'_, ()> for C509 {
60-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
65+
fn decode(
66+
d: &mut Decoder<'_>,
67+
ctx: &mut (),
68+
) -> Result<Self, minicbor::decode::Error> {
6169
let tbs_cert = TbsCert::decode(d, ctx)?;
6270
let issuer_signature_value = match decode_datatype(d, "C509 Issuer Signature value")? {
6371
minicbor::data::Type::Bytes => Some(decode_bytes(d, "C509 Issuer Signature value")?),

rust/c509-certificate/src/cert_tbs.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ impl TbsCert {
4848
#[must_use]
4949
#[allow(clippy::too_many_arguments)]
5050
pub fn new(
51-
c509_certificate_type: u8, certificate_serial_number: UnwrappedBigUint,
52-
issuer_signature_algorithm: IssuerSignatureAlgorithm, issuer: Option<Name>,
53-
validity_not_before: Time, validity_not_after: Time, subject: Name,
54-
subject_public_key_algorithm: SubjectPubKeyAlgorithm, subject_public_key: Vec<u8>,
51+
c509_certificate_type: u8,
52+
certificate_serial_number: UnwrappedBigUint,
53+
issuer_signature_algorithm: IssuerSignatureAlgorithm,
54+
issuer: Option<Name>,
55+
validity_not_before: Time,
56+
validity_not_after: Time,
57+
subject: Name,
58+
subject_public_key_algorithm: SubjectPubKeyAlgorithm,
59+
subject_public_key: Vec<u8>,
5560
extensions: Extensions,
5661
) -> Self {
5762
Self {
@@ -149,7 +154,9 @@ impl TbsCert {
149154

150155
impl Encode<()> for TbsCert {
151156
fn encode<W: Write>(
152-
&self, e: &mut Encoder<W>, ctx: &mut (),
157+
&self,
158+
e: &mut Encoder<W>,
159+
ctx: &mut (),
153160
) -> Result<(), minicbor::encode::Error<W::Error>> {
154161
encode_helper(e, "Certificate type", ctx, &self.c509_certificate_type)?;
155162
self.certificate_serial_number.encode(e, ctx)?;
@@ -166,7 +173,10 @@ impl Encode<()> for TbsCert {
166173
}
167174

168175
impl Decode<'_, ()> for TbsCert {
169-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
176+
fn decode(
177+
d: &mut Decoder<'_>,
178+
ctx: &mut (),
179+
) -> Result<Self, minicbor::decode::Error> {
170180
let cert_type = decode_helper(d, "Certificate type", ctx)?;
171181
let serial_number = UnwrappedBigUint::decode(d, ctx)?;
172182
let issuer_signature_algorithm = IssuerSignatureAlgorithm::decode(d, ctx)?;

rust/c509-certificate/src/extensions/alt_name.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ impl AlternativeName {
3636

3737
impl Encode<()> for AlternativeName {
3838
fn encode<W: Write>(
39-
&self, e: &mut Encoder<W>, ctx: &mut (),
39+
&self,
40+
e: &mut Encoder<W>,
41+
ctx: &mut (),
4042
) -> Result<(), minicbor::encode::Error<W::Error>> {
4143
self.0.encode(e, ctx)
4244
}
4345
}
4446

4547
impl Decode<'_, ()> for AlternativeName {
46-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
48+
fn decode(
49+
d: &mut Decoder<'_>,
50+
ctx: &mut (),
51+
) -> Result<Self, minicbor::decode::Error> {
4752
GeneralNamesOrText::decode(d, ctx).map(AlternativeName::new)
4853
}
4954
}
@@ -64,7 +69,9 @@ pub enum GeneralNamesOrText {
6469

6570
impl Encode<()> for GeneralNamesOrText {
6671
fn encode<W: Write>(
67-
&self, e: &mut Encoder<W>, ctx: &mut (),
72+
&self,
73+
e: &mut Encoder<W>,
74+
ctx: &mut (),
6875
) -> Result<(), minicbor::encode::Error<W::Error>> {
6976
match self {
7077
GeneralNamesOrText::GeneralNames(gns) => {
@@ -88,7 +95,10 @@ impl Encode<()> for GeneralNamesOrText {
8895
}
8996

9097
impl Decode<'_, ()> for GeneralNamesOrText {
91-
fn decode(d: &mut Decoder<'_>, ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
98+
fn decode(
99+
d: &mut Decoder<'_>,
100+
ctx: &mut (),
101+
) -> Result<Self, minicbor::decode::Error> {
92102
match decode_datatype(d, "Alternative Name - General Names")? {
93103
// If it is a string it is a GeneralNames with only 1 DNSName
94104
minicbor::data::Type::String => {

0 commit comments

Comments
 (0)