Skip to content

Commit 55af3a7

Browse files
committed
Linting.
1 parent ece2d45 commit 55af3a7

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

src/lib/asn1/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ pub fn parse_oid_string<S: AsRef<str>>(oid_str: S) -> Result<ObjectIdentifier, A
4747
let arcs: Result<Vec<u32>, _> = oid_str.split('.').map(|s| s.parse::<u32>()).collect();
4848
let arcs = match arcs {
4949
Ok(arcs) => arcs,
50-
Err(e) => return Err(Asn1Error::InvalidOid { message: format!("Failed to parse OID '{}': {}", oid_str, e) }),
50+
Err(e) => return Err(Asn1Error::InvalidOid { message: format!("Failed to parse OID '{oid_str}': {e}") }),
5151
};
5252

5353
// Create ObjectIdentifier from arcs
5454
match ObjectIdentifier::new(arcs) {
5555
Some(oid) => Ok(oid),
56-
None => Err(Asn1Error::InvalidOid { message: format!("Failed to create ObjectIdentifier from '{}'", oid_str) }),
56+
None => Err(Asn1Error::InvalidOid { message: format!("Failed to create ObjectIdentifier from '{oid_str}'") }),
5757
}
5858
}
5959

src/lib/certificates/builder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ impl CertificateBuilder {
182182
let sensitive_der = rasn::der::encode(&sensitive_attr)?;
183183

184184
AttributeBuilder::new()
185-
.with_oid(&oid.to_string())
185+
.with_oid(oid.to_string())
186186
.with_value(sensitive_der)
187187
.as_sensitive()
188188
.build()?
189189
} else {
190190
// Create a plain attribute
191191
AttributeBuilder::new()
192-
.with_oid(&oid.to_string())
192+
.with_oid(oid.to_string())
193193
.with_value(&entry.value)
194194
.as_plain()
195195
.build()?
@@ -202,7 +202,7 @@ impl CertificateBuilder {
202202
let kyc_der = rasn::der::encode(&kyc_attributes)?;
203203

204204
// Create the extension
205-
Ok(Extension::new(&KYC_ATTRIBUTES_EXTENSION_OID.to_string(), kyc_der, false)?)
205+
Ok(Extension::new(KYC_ATTRIBUTES_EXTENSION_OID.to_string(), kyc_der, false)?)
206206
}
207207
}
208208

@@ -294,7 +294,7 @@ impl Certificate {
294294
/// Parse KYC attributes from an X.509 certificate
295295
fn parse_kyc_attributes(x509_cert: &X509Certificate) -> KYCAttributes {
296296
// Try to find the KYC attributes extension
297-
if let Some(extension) = x509_cert.get_extension(&KYC_ATTRIBUTES_EXTENSION_OID.to_string()) {
297+
if let Some(extension) = x509_cert.get_extension(KYC_ATTRIBUTES_EXTENSION_OID.to_string()) {
298298
// Try to decode the extension value
299299
if let Ok(kyc_attrs) = rasn::der::decode::<KYCAttributes>(extension.value.as_bytes()) {
300300
return kyc_attrs;
@@ -361,7 +361,7 @@ mod tests {
361361
];
362362

363363
for (name, builder) in builders {
364-
assert!(builder.kyc_attributes.is_empty(), "Builder {} should have empty attributes", name);
364+
assert!(builder.kyc_attributes.is_empty(), "Builder {name} should have empty attributes");
365365
}
366366
}
367367

@@ -429,7 +429,7 @@ mod tests {
429429
let x509_cert = cert.to_x509();
430430
// Just check that we can access the X509 certificate
431431
assert!(x509_cert
432-
.get_extension(&KYC_ATTRIBUTES_EXTENSION_OID.to_string())
432+
.get_extension(KYC_ATTRIBUTES_EXTENSION_OID.to_string())
433433
.is_none());
434434

435435
// Test Certificate.kyc_attributes
@@ -445,10 +445,10 @@ mod tests {
445445
assert!(matches!(result.unwrap_err(), CertificateError::AttributeNotFound { .. }));
446446
}
447447

448-
fn test_certificate_building_functionality<T: KeyPair, S>(account: Account<T>)
448+
fn test_certificate_building_functionality<T, S>(account: Account<T>)
449449
where
450450
Account<T>: TryFrom<accounts::Accountable<T>, Error = accounts::AccountError>,
451-
T: CryptoSignerWithOptions<S> + 'static,
451+
T: KeyPair + CryptoSignerWithOptions<S> + 'static,
452452
S: SignatureEncoding,
453453
{
454454
let subject_dn = x509::utils::create_dn(&[(x509::oids::CN, "Test Subject")]).unwrap();
@@ -498,10 +498,10 @@ mod tests {
498498

499499
crate::test_all_key_types!(test_certificate_building, test_certificate_building_functionality);
500500

501-
fn test_certificate_attribute_type_errors<T: KeyPair, S>(account: Account<T>)
501+
fn test_certificate_attribute_type_errors<T, S>(account: Account<T>)
502502
where
503503
Account<T>: TryFrom<accounts::Accountable<T>, Error = accounts::AccountError>,
504-
T: CryptoSignerWithOptions<S> + 'static,
504+
T: KeyPair + CryptoSignerWithOptions<S> + 'static,
505505
S: SignatureEncoding,
506506
{
507507
let subject_dn = x509::utils::create_dn(&[(x509::oids::CN, "Test Subject")]).unwrap();

src/lib/certificates/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/lib/kyc_schema/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ impl AttributeBuilder {
4949
/// Build the attribute
5050
pub fn build(self) -> Result<Attribute, KycSchemaError> {
5151
// Validate and extract OID and value
52-
let oid_str = self.name_oid.ok_or_else(|| KycSchemaError::MissingOid)?;
53-
let value_bytes = self.value.ok_or_else(|| KycSchemaError::MissingValue)?;
52+
let oid_str = self.name_oid.ok_or(KycSchemaError::MissingOid)?;
53+
let value_bytes = self.value.ok_or(KycSchemaError::MissingValue)?;
5454
// Parse OID string using utility function
5555
let oid = parse_oid_string(&oid_str)?;
5656
let octet_string = OctetString::from_slice(&value_bytes);

src/lib/kyc_schema/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ mod tests {
209209

210210
fn build_attribute(test_attr: &TestAttribute) -> Attribute {
211211
let builder = AttributeBuilder::new()
212-
.with_oid(&test_attr.oid.to_string())
212+
.with_oid(test_attr.oid.to_string())
213213
.with_value(test_attr.value);
214214

215215
if test_attr.is_sensitive {
@@ -252,7 +252,7 @@ mod tests {
252252
}
253253

254254
// Test non-existent OID
255-
assert!(attributes.find_by_oid("1.2.3.4.5".to_string()).is_none());
255+
assert!(attributes.find_by_oid("1.2.3.4.5").is_none());
256256
}
257257

258258
#[test]
@@ -320,10 +320,7 @@ mod tests {
320320

321321
#[test]
322322
fn test_from_iterator() {
323-
let attrs: Vec<Attribute> = TEST_ATTRIBUTES
324-
.iter()
325-
.map(|test_attr| build_attribute(test_attr))
326-
.collect();
323+
let attrs: Vec<Attribute> = TEST_ATTRIBUTES.iter().map(build_attribute).collect();
327324

328325
let kyc_attrs: KYCAttributes = attrs.into_iter().collect();
329326
assert_eq!(kyc_attrs.count(), TEST_ATTRIBUTES.len());

src/lib/utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ macro_rules! impl_source_error_from {
4242
/// # Example
4343
/// ```rust
4444
/// use anchor_rs::impl_source_error_from_via;
45+
/// use anchor_rs::asn1::error::Asn1Error;
4546
///
4647
/// #[derive(Debug)]
4748
/// enum MyError {
48-
/// Asn1Error { source: crate::asn1::error::Asn1Error },
49+
/// Asn1Error { source: Asn1Error },
4950
/// }
5051
///
5152
/// impl_source_error_from_via!(MyError, {
52-
/// rasn::error::EncodeError => Asn1Error via crate::asn1::error::Asn1Error,
53-
/// rasn::error::DecodeError => Asn1Error via crate::asn1::error::Asn1Error,
53+
/// rasn::error::EncodeError => Asn1Error via Asn1Error,
54+
/// rasn::error::DecodeError => Asn1Error via Asn1Error,
5455
/// });
5556
/// ```
5657
#[macro_export]

0 commit comments

Comments
 (0)