Skip to content

Commit cfebc16

Browse files
author
vlad
committed
clippy fixes
1 parent fff96df commit cfebc16

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

check-hw/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use hyper::server::Server;
2424
use hyper::Client;
2525
use hyper::header::{AUTHORIZATION, ACCEPT, USER_AGENT};
2626
use base64::{engine::general_purpose, Engine as _};
27-
use hex;
2827
use sha2::{Sha256, Digest};
2928
use serde::Serialize;
3029
use crate::fs::OpenOptions;
@@ -105,7 +104,7 @@ fn log_request(remote_addr: SocketAddr, whole_body: &[u8]) -> std::io::Result<()
105104
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
106105
let filename = format!("request_log_{}_{}_from_{}.txt", now.as_secs(), now.subsec_micros(), remote_addr);
107106

108-
let mut file = File::create(&filename)?;
107+
let mut file = File::create(filename)?;
109108
file.write_all(whole_body)?;
110109

111110
Ok(())
@@ -403,7 +402,7 @@ fn extract_cpu_cert_from_cert(cert_data: &[u8]) -> Option<Vec<u8>> {
403402
let b64_clean: String = b64.chars().filter(|c| !c.is_whitespace()).collect();
404403

405404
// Decode Base64 into DER
406-
let der_bytes = match base64::decode(&b64_clean) {
405+
let der_bytes = match base64::decode(b64_clean) {
407406
Ok(x) => x,
408407
Err(_) => {
409408
return None;
@@ -452,7 +451,7 @@ unsafe fn extract_cpu_cert_from_quote(vec_quote: &[u8]) -> Option<Vec<u8>> {
452451
let cert_data = (*auth_data_wrapper)
453452
.auth_data
454453
.as_ptr()
455-
.offset(auth_hdr_size as isize)
454+
.add(auth_hdr_size)
456455
as *const sgx_ql_certification_data_t;
457456

458457
let cert_size_max = auth_size - mem::size_of::<sgx_ql_certification_data_t>();
@@ -491,7 +490,7 @@ fn extract_cpu_cert_from_attestation_combined<R: Read>(reader: &mut R) -> Result
491490
buf.resize(size_dcap_q as usize, 0);
492491
reader.read_exact(buf.as_mut_slice())?;
493492

494-
let ppid = unsafe { extract_cpu_cert_from_quote(&buf.as_slice()) };
493+
let ppid = unsafe { extract_cpu_cert_from_quote(buf.as_slice()) };
495494

496495
buf.resize(size_dcap_c as usize, 0);
497496
reader.read_exact(buf.as_mut_slice())?;
@@ -521,12 +520,12 @@ fn print_request_details(file_path: &std::path::Path, ip: IpAddr) {
521520
buf.resize(size_dcap_q as usize, 0);
522521
f_in.read_exact(buf.as_mut_slice()).unwrap();
523522

524-
let ppid = unsafe { extract_cpu_cert_from_quote(&buf.as_slice()) };
523+
let ppid = unsafe { extract_cpu_cert_from_quote(buf.as_slice()) };
525524

526525
buf.resize(size_dcap_c as usize, 0);
527526
f_in.read_exact(buf.as_mut_slice()).unwrap();
528527

529-
buf.resize(0, 0);
528+
buf.clear();
530529
f_in.read_to_end(&mut buf).unwrap();
531530

532531
println!("IP: {}", ip);
@@ -536,7 +535,7 @@ fn print_request_details(file_path: &std::path::Path, ip: IpAddr) {
536535
println!("Metadata: {}", &s);
537536

538537
if let Some(ppid_val) = ppid {
539-
println!("ppid: {}", hex::encode(&ppid_val));
538+
println!("ppid: {}", hex::encode(ppid_val));
540539
}
541540
}
542541

cosmwasm/enclaves/execute/src/registration/attestation.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl KnownJwtKeys {
9292
fn add_key(&mut self, kid_b64: &str, n_b64: &str) -> Result<(), Box<dyn std::error::Error>> {
9393
let kid_bytes = base64::decode(kid_b64)?;
9494
let n_bytes = my_decode_base64(n_b64)?;
95-
let e_bytes = [01_u8, 00_u8, 01_u8];
95+
let e_bytes = [1_u8, 00_u8, 1_u8];
9696

9797
// 2️⃣ Construct RSA public key
9898
let n = rsa::BigUint::from_bytes_be(&n_bytes);
@@ -326,20 +326,18 @@ impl AttestationCombined {
326326
// try to deserialize in a newer format
327327
let mut pos = 0;
328328
while pos + mem::size_of::<u32>() < blob_len {
329-
let key = unsafe { *(blob_ptr.offset(pos as isize)) };
329+
let key = unsafe { *(blob_ptr.add(pos)) };
330330
pos += 1;
331331

332332
let value_size =
333-
u32::from_le(unsafe { *(blob_ptr.offset(pos as isize) as *const u32) })
334-
as usize;
333+
u32::from_le(unsafe { *(blob_ptr.add(pos) as *const u32) }) as usize;
335334
pos += mem::size_of::<u32>();
336335

337336
if pos + value_size > blob_len {
338337
break;
339338
}
340339

341-
let value =
342-
unsafe { slice::from_raw_parts(blob_ptr.offset(pos as isize), value_size) };
340+
let value = unsafe { slice::from_raw_parts(blob_ptr.add(pos), value_size) };
343341
pos += value_size;
344342

345343
match key {
@@ -431,10 +429,7 @@ impl AttestationCombined {
431429
let auth_size = auth_size_max - auth_hdr_size;
432430

433431
if auth_size > mem::size_of::<sgx_ql_certification_data_t>() {
434-
let cert_data = (*auth_data_wrapper)
435-
.auth_data
436-
.as_ptr()
437-
.offset(auth_hdr_size as isize)
432+
let cert_data = (*auth_data_wrapper).auth_data.as_ptr().add(auth_hdr_size)
438433
as *const sgx_ql_certification_data_t;
439434

440435
let cert_size_max =
@@ -488,7 +483,7 @@ impl AttestationCombined {
488483
let b64_clean: String = b64.chars().filter(|c| !c.is_whitespace()).collect();
489484

490485
// Decode Base64 into DER
491-
let der_bytes = match base64::decode(&b64_clean) {
486+
let der_bytes = match base64::decode(b64_clean) {
492487
Ok(x) => x,
493488
Err(_) => {
494489
return None;
@@ -620,7 +615,7 @@ impl AttestationCombined {
620615
println!(
621616
"quotehash masmatch. in-token: {}, actual: {}",
622617
quotehash_str,
623-
hex::encode(&quote_hash_actual)
618+
hex::encode(quote_hash_actual)
624619
);
625620
return false;
626621
}
@@ -663,7 +658,7 @@ pub fn verify_quote_sgx(
663658
if wl.contains(&ppid_addr) {
664659
true
665660
} else {
666-
println!("Unknown Machine ID: {}", orig_hex::encode(&ppid_addr));
661+
println!("Unknown Machine ID: {}", orig_hex::encode(ppid_addr));
667662
false
668663
}
669664
}

cosmwasm/enclaves/execute/src/registration/offchain.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ pub unsafe extern "C" fn ecall_onchain_approve_upgrade(
709709
fn calculate_machine_id_evidence(machine_id: &[u8]) -> [u8; HASH_SIZE] {
710710
let mut hasher = Sha256::new();
711711

712-
let magic = ['m' as u8, 'i' as u8, 'd' as u8, 0_u8];
713-
hasher.update(&magic);
712+
let magic = [b'm', b'i', b'd'];
713+
hasher.update(magic);
714714

715-
hasher.update(&SELF_REPORT_BODY.mr_enclave.m);
715+
hasher.update(SELF_REPORT_BODY.mr_enclave.m);
716716
hasher.update(machine_id);
717717

718718
let mut ret = [0_u8; HASH_SIZE];
@@ -1230,7 +1230,7 @@ fn print_key_config_ex(seed: &enclave_crypto::Seed) {
12301230
let node_pk = Keychain::generate_consensus_seed_exchange_keypair(seed).get_pubkey();
12311231
let io_pk = Keychain::generate_consensus_io_exchange_keypair(seed).get_pubkey();
12321232

1233-
println!("{},{}", base64::encode(&node_pk), base64::encode(&io_pk));
1233+
println!("{},{}", base64::encode(node_pk), base64::encode(io_pk));
12341234
}
12351235

12361236
fn print_key_config() -> sgx_status_t {
@@ -1245,7 +1245,7 @@ fn print_key_config() -> sgx_status_t {
12451245

12461246
fn print_key_config_rot(seed: &enclave_crypto::Seed) {
12471247
println!("rot_seed pubkey");
1248-
print_key_config_ex(&seed);
1248+
print_key_config_ex(seed);
12491249
}
12501250

12511251
fn export_local_migration_report() -> sgx_status_t {

cosmwasm/enclaves/execute/src/registration/persistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn write_master_pub_keys(key_manager: &Keychain) -> SgxResult<()> {
1313
write_public_key(kp, SEED_EXCH_KEY_SAVE_PATH)?;
1414

1515
let kp = key_manager.get_consensus_io_exchange_keypair().unwrap();
16-
write_public_key(&kp, IO_KEY_SAVE_PATH)?;
16+
write_public_key(kp, IO_KEY_SAVE_PATH)?;
1717

1818
Ok(())
1919
}

0 commit comments

Comments
 (0)