Skip to content

Commit b78fb2a

Browse files
committed
Fix Clippy warnings from Rust 1.87
This commit updates the code to be compliant with Clippy checks for 1.87. Signed-off-by: Mark Kirichenko <[email protected]>
1 parent 151fefc commit b78fb2a

27 files changed

+323
-390
lines changed

enclave_build/src/docker.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,26 @@ mod tests {
354354
fn test_get_credentials() {
355355
let test_user = "test_user";
356356
let test_password = "test_password";
357-
let auth = format!("{}:{}", test_user, test_password);
357+
let auth = format!("{test_user}:{test_password}");
358358
let encoded_auth = general_purpose::STANDARD.encode(auth);
359359
let config = format!(
360360
r#"{{
361361
"auths": {{
362362
"https://public.ecr.aws/aws-nitro-enclaves/hello/v1/": {{
363-
"auth": "{}"
363+
"auth": "{encoded_auth}"
364364
}},
365365
"https://registry.example.com": {{
366366
"auth": "b3RoZXJfdXNlcjpvdGhlcl9wYXNzd29yZA=="
367367
}}
368368
}}
369-
}}"#,
370-
encoded_auth
369+
}}"#
371370
);
372371

373372
// Create a temporary file
374373
let mut temp_file = NamedTempFile::new().expect("Failed to create temporary file.");
375374

376375
// Write the config to the temporary file
377-
write!(temp_file, "{}", config).expect("Failed to write to temporary file.");
376+
write!(temp_file, "{config}").expect("Failed to write to temporary file.");
378377

379378
// Set the DOCKER_CONFIG environment variable to point to the temporary file's path
380379
let temp_file_path = temp_file.path().to_string_lossy().to_string();

enclave_build/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a> Docker2Eif<'a> {
101101
let sign_info = match (private_key, certificate_path) {
102102
(Some(key), Some(cert)) => SignKeyData::new(key, Path::new(&cert)).map_or_else(
103103
|e| {
104-
eprintln!("Could not read signing info: {:?}", e);
104+
eprintln!("Could not read signing info: {e:?}");
105105
None
106106
},
107107
Some,

samples/command_executer/src/command_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ impl CommandOutput {
7272

7373
pub fn new_from(output: Output) -> Result<Self, String> {
7474
Ok(CommandOutput {
75-
stdout: String::from_utf8(output.stdout).map_err(|err| format!("{:?}", err))?,
76-
stderr: String::from_utf8(output.stderr).map_err(|err| format!("{:?}", err))?,
75+
stdout: String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))?,
76+
stderr: String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?,
7777
rc: output.status.code(),
7878
})
7979
}

samples/command_executer/src/lib.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ impl VsockSocket {
4444
impl Drop for VsockSocket {
4545
fn drop(&mut self) {
4646
shutdown(self.socket_fd, Shutdown::Both)
47-
.unwrap_or_else(|e| eprintln!("Failed to shut socket down: {:?}", e));
48-
close(self.socket_fd).unwrap_or_else(|e| eprintln!("Failed to close socket: {:?}", e));
47+
.unwrap_or_else(|e| eprintln!("Failed to shut socket down: {e:?}"));
48+
close(self.socket_fd).unwrap_or_else(|e| eprintln!("Failed to close socket: {e:?}"));
4949
}
5050
}
5151

@@ -67,11 +67,11 @@ fn vsock_connect(cid: u32, port: u32) -> Result<VsockSocket, String> {
6767
SockFlag::empty(),
6868
None,
6969
)
70-
.map_err(|err| format!("Failed to create the socket: {:?}", err))?,
70+
.map_err(|err| format!("Failed to create the socket: {err:?}"))?,
7171
);
7272
match connect(vsocket.as_raw_fd(), &sockaddr) {
7373
Ok(_) => return Ok(vsocket),
74-
Err(e) => err_msg = format!("Failed to connect: {}", e),
74+
Err(e) => err_msg = format!("Failed to connect: {e}"),
7575
}
7676

7777
std::thread::sleep(std::time::Duration::from_secs(1 << i));
@@ -86,8 +86,8 @@ fn run_server(fd: RawFd, no_wait: bool) -> Result<(), String> {
8686
let mut buf = [0u8; BUF_MAX_LEN];
8787
recv_loop(fd, &mut buf, len)?;
8888

89-
let len_usize = len.try_into().map_err(|err| format!("{:?}", err))?;
90-
let command = std::str::from_utf8(&buf[0..len_usize]).map_err(|err| format!("{:?}", err))?;
89+
let len_usize = len.try_into().map_err(|err| format!("{err:?}"))?;
90+
let command = std::str::from_utf8(&buf[0..len_usize]).map_err(|err| format!("{err:?}"))?;
9191

9292
// execute command
9393
let command_output = if no_wait {
@@ -99,7 +99,7 @@ fn run_server(fd: RawFd, no_wait: bool) -> Result<(), String> {
9999
if output.is_err() {
100100
CommandOutput::new(
101101
String::new(),
102-
format!("Could not execute the command {}", command),
102+
format!("Could not execute the command {command}"),
103103
1,
104104
)
105105
} else {
@@ -110,15 +110,15 @@ fn run_server(fd: RawFd, no_wait: bool) -> Result<(), String> {
110110
.arg("-c")
111111
.arg(command)
112112
.output()
113-
.map_err(|err| format!("Could not execute the command {}: {:?}", command, err))?;
113+
.map_err(|err| format!("Could not execute the command {command}: {err:?}"))?;
114114
CommandOutput::new_from(output)?
115115
};
116116

117117
// send output
118118
let json_output = serde_json::to_string(&command_output)
119-
.map_err(|err| format!("Could not serialize the output: {:?}", err))?;
119+
.map_err(|err| format!("Could not serialize the output: {err:?}"))?;
120120
let buf = json_output.as_bytes();
121-
let len: u64 = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
121+
let len: u64 = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
122122
send_u64(fd, len)?;
123123
send_loop(fd, buf, len)?;
124124
Ok(())
@@ -129,28 +129,28 @@ fn recv_file_server(fd: RawFd) -> Result<(), String> {
129129
let len = recv_u64(fd)?;
130130
let mut buf = [0u8; BUF_MAX_LEN];
131131
recv_loop(fd, &mut buf, len)?;
132-
let len_usize = len.try_into().map_err(|err| format!("{:?}", err))?;
133-
let path = std::str::from_utf8(&buf[0..len_usize]).map_err(|err| format!("{:?}", err))?;
132+
let len_usize = len.try_into().map_err(|err| format!("{err:?}"))?;
133+
let path = std::str::from_utf8(&buf[0..len_usize]).map_err(|err| format!("{err:?}"))?;
134134

135-
let mut file = File::open(path).map_err(|err| format!("Could not open file {:?}", err))?;
135+
let mut file = File::open(path).map_err(|err| format!("Could not open file {err:?}"))?;
136136

137137
let filesize = file
138138
.metadata()
139-
.map_err(|err| format!("Could not get file metadata {:?}", err))?
139+
.map_err(|err| format!("Could not get file metadata {err:?}"))?
140140
.len();
141141

142142
send_u64(fd, filesize)?;
143-
println!("Sending file {} - size {}", path, filesize);
143+
println!("Sending file {path} - size {filesize}");
144144

145145
let mut progress: u64 = 0;
146146
let mut tmpsize: u64;
147147

148148
while progress < filesize {
149-
tmpsize = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
149+
tmpsize = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
150150
tmpsize = min(tmpsize, filesize - progress);
151151

152-
file.read_exact(&mut buf[..tmpsize.try_into().map_err(|err| format!("{:?}", err))?])
153-
.map_err(|err| format!("Could not read {:?}", err))?;
152+
file.read_exact(&mut buf[..tmpsize.try_into().map_err(|err| format!("{err:?}"))?])
153+
.map_err(|err| format!("Could not read {err:?}"))?;
154154
send_loop(fd, &buf, tmpsize)?;
155155
progress += tmpsize
156156
}
@@ -163,25 +163,25 @@ fn send_file_server(fd: RawFd) -> Result<(), String> {
163163
let len = recv_u64(fd)?;
164164
let mut buf = [0u8; BUF_MAX_LEN];
165165
recv_loop(fd, &mut buf, len)?;
166-
let len_usize = len.try_into().map_err(|err| format!("{:?}", err))?;
167-
let path = std::str::from_utf8(&buf[0..len_usize]).map_err(|err| format!("{:?}", err))?;
166+
let len_usize = len.try_into().map_err(|err| format!("{err:?}"))?;
167+
let path = std::str::from_utf8(&buf[0..len_usize]).map_err(|err| format!("{err:?}"))?;
168168

169-
let mut file = File::create(path).map_err(|err| format!("Could not open file {:?}", err))?;
169+
let mut file = File::create(path).map_err(|err| format!("Could not open file {err:?}"))?;
170170

171171
// Receive filesize
172172
let filesize = recv_u64(fd)?;
173-
println!("Receiving file {} - size {}", path, filesize);
173+
println!("Receiving file {path} - size {filesize}");
174174

175175
let mut progress: u64 = 0;
176176
let mut tmpsize: u64;
177177

178178
while progress < filesize {
179-
tmpsize = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
179+
tmpsize = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
180180
tmpsize = min(tmpsize, filesize - progress);
181181

182182
recv_loop(fd, &mut buf, tmpsize)?;
183-
file.write_all(&buf[..tmpsize.try_into().map_err(|err| format!("{:?}", err))?])
184-
.map_err(|err| format!("Could not write {:?}", err))?;
183+
file.write_all(&buf[..tmpsize.try_into().map_err(|err| format!("{err:?}"))?])
184+
.map_err(|err| format!("Could not write {err:?}"))?;
185185
progress += tmpsize
186186
}
187187

@@ -195,16 +195,16 @@ pub fn listen(args: ListenArgs) -> Result<(), String> {
195195
SockFlag::empty(),
196196
None,
197197
)
198-
.map_err(|err| format!("Create socket failed: {:?}", err))?;
198+
.map_err(|err| format!("Create socket failed: {err:?}"))?;
199199

200200
let sockaddr = VsockAddr::new(VMADDR_CID_ANY, args.port);
201201

202-
bind(socket_fd, &sockaddr).map_err(|err| format!("Bind failed: {:?}", err))?;
202+
bind(socket_fd, &sockaddr).map_err(|err| format!("Bind failed: {err:?}"))?;
203203

204-
listen_vsock(socket_fd, BACKLOG).map_err(|err| format!("Listen failed: {:?}", err))?;
204+
listen_vsock(socket_fd, BACKLOG).map_err(|err| format!("Listen failed: {err:?}"))?;
205205

206206
loop {
207-
let fd = accept(socket_fd).map_err(|err| format!("Accept failed: {:?}", err))?;
207+
let fd = accept(socket_fd).map_err(|err| format!("Accept failed: {err:?}"))?;
208208

209209
//cmd id
210210
let cmdid = match recv_u64(fd) {
@@ -216,30 +216,30 @@ pub fn listen(args: ListenArgs) -> Result<(), String> {
216216
}
217217
},
218218
Err(e) => {
219-
eprintln!("Error {}", e);
219+
eprintln!("Error {e}");
220220
continue;
221221
}
222222
};
223223

224224
match cmdid {
225225
CmdId::RunCmd => {
226226
if let Err(e) = run_server(fd, false) {
227-
eprintln!("Error {}", e);
227+
eprintln!("Error {e}");
228228
}
229229
}
230230
CmdId::RecvFile => {
231231
if let Err(e) = recv_file_server(fd) {
232-
eprintln!("Error {}", e);
232+
eprintln!("Error {e}");
233233
}
234234
}
235235
CmdId::SendFile => {
236236
if let Err(e) = send_file_server(fd) {
237-
eprintln!("Error {}", e);
237+
eprintln!("Error {e}");
238238
}
239239
}
240240
CmdId::RunCmdNoWait => {
241241
if let Err(e) = run_server(fd, true) {
242-
eprintln!("Error {}", e);
242+
eprintln!("Error {e}");
243243
}
244244
}
245245
}
@@ -259,7 +259,7 @@ pub fn run(args: RunArgs) -> Result<i32, String> {
259259

260260
// send command
261261
let buf = args.command.as_bytes();
262-
let len: u64 = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
262+
let len: u64 = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
263263
send_u64(socket_fd, len)?;
264264
send_loop(socket_fd, buf, len)?;
265265

@@ -272,23 +272,23 @@ pub fn run(args: RunArgs) -> Result<i32, String> {
272272
let recv_len = min(BUF_MAX_LEN as u64, to_recv);
273273
recv_loop(socket_fd, &mut buf, recv_len)?;
274274
to_recv -= recv_len;
275-
let to_recv_usize: usize = recv_len.try_into().map_err(|err| format!("{:?}", err))?;
275+
let to_recv_usize: usize = recv_len.try_into().map_err(|err| format!("{err:?}"))?;
276276
json_output.push_str(
277-
std::str::from_utf8(&buf[0..to_recv_usize]).map_err(|err| format!("{:?}", err))?,
277+
std::str::from_utf8(&buf[0..to_recv_usize]).map_err(|err| format!("{err:?}"))?,
278278
);
279279
}
280280

281281
let output: CommandOutput = serde_json::from_str(json_output.as_str())
282-
.map_err(|err| format!("Could not deserialize the output: {:?}", err))?;
282+
.map_err(|err| format!("Could not deserialize the output: {err:?}"))?;
283283
print!("{}", output.stdout);
284284
eprint!("{}", output.stderr);
285285

286286
Ok(output.rc.unwrap_or_default())
287287
}
288288

289289
pub fn recv_file(args: FileArgs) -> Result<(), String> {
290-
let mut file = File::create(&args.localfile)
291-
.map_err(|err| format!("Could not open localfile {:?}", err))?;
290+
let mut file =
291+
File::create(&args.localfile).map_err(|err| format!("Could not open localfile {err:?}"))?;
292292
let vsocket = vsock_connect(args.cid, args.port)?;
293293
let socket_fd = vsocket.as_raw_fd();
294294

@@ -297,7 +297,7 @@ pub fn recv_file(args: FileArgs) -> Result<(), String> {
297297

298298
// send remotefile path
299299
let buf = args.remotefile.as_bytes();
300-
let len: u64 = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
300+
let len: u64 = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
301301
send_u64(socket_fd, len)?;
302302
send_loop(socket_fd, buf, len)?;
303303

@@ -315,20 +315,20 @@ pub fn recv_file(args: FileArgs) -> Result<(), String> {
315315
let mut buf = [0u8; BUF_MAX_LEN];
316316

317317
while progress < filesize {
318-
tmpsize = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
318+
tmpsize = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
319319
tmpsize = min(tmpsize, filesize - progress);
320320

321321
recv_loop(socket_fd, &mut buf, tmpsize)?;
322-
file.write_all(&buf[..tmpsize.try_into().map_err(|err| format!("{:?}", err))?])
323-
.map_err(|err| format!("Could not write {:?}", err))?;
322+
file.write_all(&buf[..tmpsize.try_into().map_err(|err| format!("{err:?}"))?])
323+
.map_err(|err| format!("Could not write {err:?}"))?;
324324
progress += tmpsize
325325
}
326326
Ok(())
327327
}
328328

329329
pub fn send_file(args: FileArgs) -> Result<(), String> {
330330
let mut file =
331-
File::open(&args.localfile).map_err(|err| format!("Could not open localfile {:?}", err))?;
331+
File::open(&args.localfile).map_err(|err| format!("Could not open localfile {err:?}"))?;
332332
let vsocket = vsock_connect(args.cid, args.port)?;
333333
let socket_fd = vsocket.as_raw_fd();
334334

@@ -337,13 +337,13 @@ pub fn send_file(args: FileArgs) -> Result<(), String> {
337337

338338
// send remotefile path
339339
let buf = args.remotefile.as_bytes();
340-
let len: u64 = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
340+
let len: u64 = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
341341
send_u64(socket_fd, len)?;
342342
send_loop(socket_fd, buf, len)?;
343343

344344
let filesize = file
345345
.metadata()
346-
.map_err(|err| format!("Could not get file metadate {:?}", err))?
346+
.map_err(|err| format!("Could not get file metadate {err:?}"))?
347347
.len();
348348

349349
send_u64(socket_fd, filesize)?;
@@ -359,11 +359,11 @@ pub fn send_file(args: FileArgs) -> Result<(), String> {
359359
let mut tmpsize: u64;
360360

361361
while progress < filesize {
362-
tmpsize = buf.len().try_into().map_err(|err| format!("{:?}", err))?;
362+
tmpsize = buf.len().try_into().map_err(|err| format!("{err:?}"))?;
363363
tmpsize = min(tmpsize, filesize - progress);
364364

365-
file.read_exact(&mut buf[..tmpsize.try_into().map_err(|err| format!("{:?}", err))?])
366-
.map_err(|err| format!("Could not read {:?}", err))?;
365+
file.read_exact(&mut buf[..tmpsize.try_into().map_err(|err| format!("{err:?}"))?])
366+
.map_err(|err| format!("Could not read {err:?}"))?;
367367
send_loop(socket_fd, &buf, tmpsize)?;
368368
progress += tmpsize
369369
}

samples/command_executer/src/protocol_helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ pub fn recv_i32(fd: RawFd) -> Result<i32, String> {
3333
}
3434

3535
pub fn send_loop(fd: RawFd, buf: &[u8], len: u64) -> Result<(), String> {
36-
let len: usize = len.try_into().map_err(|err| format!("{:?}", err))?;
36+
let len: usize = len.try_into().map_err(|err| format!("{err:?}"))?;
3737
let mut send_bytes = 0;
3838

3939
while send_bytes < len {
4040
let size = match send(fd, &buf[send_bytes..len], MsgFlags::empty()) {
4141
Ok(size) => size,
4242
Err(nix::errno::Errno::EINTR) => 0,
43-
Err(err) => return Err(format!("{:?}", err)),
43+
Err(err) => return Err(format!("{err:?}")),
4444
};
4545
send_bytes += size;
4646
}
@@ -49,15 +49,15 @@ pub fn send_loop(fd: RawFd, buf: &[u8], len: u64) -> Result<(), String> {
4949
}
5050

5151
pub fn recv_loop(fd: RawFd, buf: &mut [u8], len: u64) -> Result<(), String> {
52-
let len: usize = len.try_into().map_err(|err| format!("{:?}", err))?;
52+
let len: usize = len.try_into().map_err(|err| format!("{err:?}"))?;
5353
let mut recv_bytes = 0;
5454

5555
while recv_bytes < len {
5656
let size = match recv(fd, &mut buf[recv_bytes..len], MsgFlags::empty()) {
5757
Ok(0) => return Err(format!("{:?}", "Peer closed connection")),
5858
Ok(size) => size,
5959
Err(nix::errno::Errno::EINTR) => 0,
60-
Err(err) => return Err(format!("{:?}", err)),
60+
Err(err) => return Err(format!("{err:?}")),
6161
};
6262
recv_bytes += size;
6363
}

0 commit comments

Comments
 (0)