Skip to content

Commit 181de20

Browse files
committed
rustfmt: reformat large function calls
1 parent f23a2c2 commit 181de20

File tree

3 files changed

+156
-81
lines changed

3 files changed

+156
-81
lines changed

src/api.rs

Lines changed: 115 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,21 @@ impl Keyring {
237237
/// Requires `read` permission on the keyring.
238238
pub fn read(&self) -> Result<(Vec<Key>, Vec<Keyring>)> {
239239
let sz = check_call_ret(unsafe { keyctl_read(self.id, ptr::null_mut(), 0) })?;
240-
let mut buffer = Vec::<key_serial_t>::with_capacity((sz as usize) /
241-
mem::size_of::<KeyringSerial>());
240+
let mut buffer =
241+
Vec::<key_serial_t>::with_capacity((sz as usize) / mem::size_of::<KeyringSerial>());
242242
let actual_sz = check_call_ret(unsafe {
243-
keyctl_read(self.id,
244-
buffer.as_mut_ptr() as *mut libc::c_char,
245-
sz as usize)
243+
keyctl_read(
244+
self.id,
245+
buffer.as_mut_ptr() as *mut libc::c_char,
246+
sz as usize,
247+
)
246248
})?;
247249
unsafe { buffer.set_len((actual_sz as usize) / mem::size_of::<KeyringSerial>()) };
248250
let keys = buffer.iter()
249251
.map(|&id| Key::new_impl(id))
250252
.partition(|key| key.description().unwrap().type_ == "keyring");
251-
Ok((keys.1,
253+
Ok((
254+
keys.1,
252255
keys.0
253256
.iter()
254257
.map(|key| Keyring::new_impl(key.id))
@@ -285,11 +288,13 @@ impl Keyring {
285288
let desc_cstr = CString::new(description.description().as_bytes()).unwrap();
286289
let payload = payload.payload();
287290
let res = unsafe {
288-
add_key(type_cstr.as_ptr(),
289-
desc_cstr.as_ptr(),
290-
payload.as_ptr() as *const libc::c_void,
291-
payload.len(),
292-
self.id)
291+
add_key(
292+
type_cstr.as_ptr(),
293+
desc_cstr.as_ptr(),
294+
payload.as_ptr() as *const libc::c_void,
295+
payload.len(),
296+
self.id,
297+
)
293298
};
294299
check_call(i64::from(res), Key::new_impl(res))
295300
}
@@ -343,10 +348,12 @@ impl Keyring {
343348
let desc_cstr = CString::new(description).unwrap();
344349
let info_cstr = CString::new(info).unwrap();
345350
check_call_ret_serial(unsafe {
346-
request_key(type_cstr.as_ptr(),
347-
desc_cstr.as_ptr(),
348-
info_cstr.as_ptr(),
349-
self.id)
351+
request_key(
352+
type_cstr.as_ptr(),
353+
desc_cstr.as_ptr(),
354+
info_cstr.as_ptr(),
355+
self.id,
356+
)
350357
})
351358
}
352359

@@ -415,9 +422,11 @@ impl Keyring {
415422
let sz = check_call_ret(unsafe { keyctl_describe(self.id, ptr::null_mut(), 0) })?;
416423
let mut buffer = Vec::with_capacity(sz as usize);
417424
let actual_sz = check_call_ret(unsafe {
418-
keyctl_describe(self.id,
419-
buffer.as_mut_ptr() as *mut libc::c_char,
420-
sz as usize)
425+
keyctl_describe(
426+
self.id,
427+
buffer.as_mut_ptr() as *mut libc::c_char,
428+
sz as usize,
429+
)
421430
})?;
422431
unsafe { buffer.set_len((actual_sz - 1) as usize) };
423432
let str_slice = str::from_utf8(&buffer[..]).unwrap();
@@ -439,7 +448,10 @@ impl Keyring {
439448
/// Any partial seconds are ignored. A timeout of 0 means "no expiration". Requires the
440449
/// `setattr` permission on the keyring.
441450
pub fn set_timeout(&mut self, timeout: Duration) -> Result<()> {
442-
check_call(unsafe { keyctl_set_timeout(self.id, timeout.as_secs() as u32) }, ())
451+
check_call(
452+
unsafe { keyctl_set_timeout(self.id, timeout.as_secs() as u32) },
453+
(),
454+
)
443455
}
444456

445457
/// The security context of the keyring. Depends on the security manager loaded into the kernel
@@ -448,9 +460,11 @@ impl Keyring {
448460
let sz = check_call_ret(unsafe { keyctl_get_security(self.id, ptr::null_mut(), 0) })?;
449461
let mut buffer = Vec::with_capacity(sz as usize);
450462
let actual_sz = check_call_ret(unsafe {
451-
keyctl_get_security(self.id,
452-
buffer.as_mut_ptr() as *mut libc::c_char,
453-
sz as usize)
463+
keyctl_get_security(
464+
self.id,
465+
buffer.as_mut_ptr() as *mut libc::c_char,
466+
sz as usize,
467+
)
454468
})?;
455469
unsafe { buffer.set_len(actual_sz as usize) };
456470
let str_slice = str::from_utf8(&buffer[..]).unwrap();
@@ -519,10 +533,10 @@ impl Key {
519533
D: AsRef<[u8]>,
520534
{
521535
let data = data.as_ref();
522-
check_call(unsafe {
523-
keyctl_update(self.id, data.as_ptr() as *const libc::c_void, data.len())
524-
},
525-
())
536+
check_call(
537+
unsafe { keyctl_update(self.id, data.as_ptr() as *const libc::c_void, data.len()) },
538+
(),
539+
)
526540
}
527541

528542
/// Revokes the key. Requires `write` permission on the key.
@@ -568,9 +582,11 @@ impl Key {
568582
let sz = check_call_ret(unsafe { keyctl_read(self.id, ptr::null_mut(), 0) })?;
569583
let mut buffer = Vec::with_capacity(sz as usize);
570584
let actual_sz = check_call_ret(unsafe {
571-
keyctl_read(self.id,
572-
buffer.as_mut_ptr() as *mut libc::c_char,
573-
sz as usize)
585+
keyctl_read(
586+
self.id,
587+
buffer.as_mut_ptr() as *mut libc::c_char,
588+
sz as usize,
589+
)
574590
})?;
575591
unsafe { buffer.set_len(actual_sz as usize) };
576592
Ok(buffer)
@@ -600,15 +616,33 @@ impl Key {
600616

601617
/// Create an object to manage a key request.
602618
pub fn manage(&mut self) -> Result<KeyManager> {
603-
check_call(unsafe { keyctl_assume_authority(self.id) },
604-
KeyManager::new(Key::new_impl(self.id)))
619+
check_call(
620+
unsafe { keyctl_assume_authority(self.id) },
621+
KeyManager::new(Key::new_impl(self.id)),
622+
)
605623
}
606624

607625
/// Compute a Diffie-Hellman prime for use as a shared secret or public key.
608626
pub fn compute_dh(private: &Key, prime: &Key, base: &Key) -> Result<Vec<u8>> {
609-
let sz = check_call_ret(unsafe { keyctl_dh_compute(private.id, prime.id, base.id, ptr::null_mut() as *mut libc::c_char, 0) })?;
627+
let sz = check_call_ret(unsafe {
628+
keyctl_dh_compute(
629+
private.id,
630+
prime.id,
631+
base.id,
632+
ptr::null_mut() as *mut libc::c_char,
633+
0,
634+
)
635+
})?;
610636
let mut buffer = Vec::with_capacity(sz as usize);
611-
let actual_sz = check_call_ret(unsafe { keyctl_dh_compute(private.id, prime.id, base.id, buffer.as_mut_ptr() as *mut libc::c_char, sz as usize) })?;
637+
let actual_sz = check_call_ret(unsafe {
638+
keyctl_dh_compute(
639+
private.id,
640+
prime.id,
641+
base.id,
642+
buffer.as_mut_ptr() as *mut libc::c_char,
643+
sz as usize,
644+
)
645+
})?;
612646
unsafe { buffer.set_len(actual_sz as usize) };
613647
Ok(buffer)
614648
}
@@ -641,15 +675,19 @@ impl Description {
641675
None
642676
} else {
643677
if len > 5 {
644-
error!("New fields detected! Please report this upstream to \
645-
https://github.com/mathstuf/rust-keyutils: {}",
646-
desc);
678+
error!(
679+
"New fields detected! Please report this upstream to \
680+
https://github.com/mathstuf/rust-keyutils: {}",
681+
desc,
682+
);
647683
}
648684
let bits = KeyPermissions::from_str_radix(pieces[1], 16).unwrap();
649685
if Permission::from_bits(bits).is_none() {
650-
error!("New permission bits detected! Please report this upstream to \
651-
https://github.com/mathstuf/rust-keyutils: {}",
652-
bits);
686+
error!(
687+
"New permission bits detected! Please report this upstream to \
688+
https://github.com/mathstuf/rust-keyutils: {}",
689+
bits,
690+
);
653691
}
654692
Some(Description {
655693
type_: pieces[4].to_owned(),
@@ -681,13 +719,17 @@ impl KeyManager {
681719
P: AsRef<[u8]>,
682720
{
683721
let payload = payload.as_ref();
684-
check_call(unsafe {
685-
keyctl_instantiate(self.key.id,
686-
payload.as_ptr() as *const libc::c_void,
687-
payload.len(),
688-
keyring.id)
689-
},
690-
())
722+
check_call(
723+
unsafe {
724+
keyctl_instantiate(
725+
self.key.id,
726+
payload.as_ptr() as *const libc::c_void,
727+
payload.len(),
728+
keyring.id,
729+
)
730+
},
731+
(),
732+
)
691733
}
692734

693735
/// Reject the key with the given `error`.
@@ -698,8 +740,17 @@ impl KeyManager {
698740
/// `write` permission on the keyring.
699741
pub fn reject(self, keyring: &Keyring, timeout: Duration, error: errno::Errno) -> Result<()> {
700742
let errno::Errno(errval) = error;
701-
check_call(unsafe { keyctl_reject(self.key.id, timeout.as_secs() as u32, errval as u32, keyring.id) },
702-
())
743+
check_call(
744+
unsafe {
745+
keyctl_reject(
746+
self.key.id,
747+
timeout.as_secs() as u32,
748+
errval as u32,
749+
keyring.id,
750+
)
751+
},
752+
(),
753+
)
703754
}
704755

705756
/// Reject the key with `ENOKEY`.
@@ -709,8 +760,10 @@ impl KeyManager {
709760
/// requesting a non-existant key repeatedly. The requester must have
710761
/// `write` permission on the keyring.
711762
pub fn negate(self, keyring: &Keyring, timeout: Duration) -> Result<()> {
712-
check_call(unsafe { keyctl_negate(self.key.id, timeout.as_secs() as u32, keyring.id) },
713-
())
763+
check_call(
764+
unsafe { keyctl_negate(self.key.id, timeout.as_secs() as u32, keyring.id) },
765+
(),
766+
)
714767
}
715768
}
716769

@@ -734,8 +787,10 @@ mod tests {
734787
let description = "test:rust-keyutils:add_key";
735788
let payload = "payload";
736789
let key = keyring.add_key::<keytypes::User, _, _>(description, payload.as_bytes()).unwrap();
737-
assert_eq!(key.read().unwrap(),
738-
payload.as_bytes().iter().cloned().collect::<Vec<_>>());
790+
assert_eq!(
791+
key.read().unwrap(),
792+
payload.as_bytes().iter().cloned().collect::<Vec<_>>()
793+
);
739794

740795
// Clean up.
741796
keyring.unlink_key(&key).unwrap();
@@ -853,8 +908,10 @@ mod tests {
853908
let description = "test:rust-keyutils:read_key";
854909
let payload = "payload";
855910
let key = keyring.add_key::<keytypes::User, _, _>(description, payload.as_bytes()).unwrap();
856-
assert_eq!(key.read().unwrap(),
857-
payload.as_bytes().iter().cloned().collect::<Vec<_>>());
911+
assert_eq!(
912+
key.read().unwrap(),
913+
payload.as_bytes().iter().cloned().collect::<Vec<_>>()
914+
);
858915

859916
// Clean up.
860917
keyring.unlink_key(&key).unwrap();
@@ -1051,8 +1108,10 @@ mod tests {
10511108
let new_payload = "new_payload";
10521109
let updated_key = keyring.add_key::<keytypes::User, _, _>(description, new_payload.as_bytes()).unwrap();
10531110
assert_eq!(key, updated_key);
1054-
assert_eq!(updated_key.read().unwrap(),
1055-
new_payload.as_bytes().iter().cloned().collect::<Vec<_>>());
1111+
assert_eq!(
1112+
updated_key.read().unwrap(),
1113+
new_payload.as_bytes().iter().cloned().collect::<Vec<_>>()
1114+
);
10561115

10571116
// Clean up.
10581117
keyring.unlink_key(&key).unwrap();

src/constants.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -220,36 +220,48 @@ bitflags! {
220220

221221
#[test]
222222
fn test_keyring_ids() {
223-
assert_eq!(SpecialKeyring::Thread.serial(),
224-
KEY_SPEC_THREAD_KEYRING);
225-
assert_eq!(SpecialKeyring::Process.serial(),
226-
KEY_SPEC_PROCESS_KEYRING);
227-
assert_eq!(SpecialKeyring::Session.serial(),
228-
KEY_SPEC_SESSION_KEYRING);
223+
assert_eq!(SpecialKeyring::Thread.serial(), KEY_SPEC_THREAD_KEYRING);
224+
assert_eq!(SpecialKeyring::Process.serial(), KEY_SPEC_PROCESS_KEYRING);
225+
assert_eq!(SpecialKeyring::Session.serial(), KEY_SPEC_SESSION_KEYRING);
229226
assert_eq!(SpecialKeyring::User.serial(), KEY_SPEC_USER_KEYRING);
230-
assert_eq!(SpecialKeyring::UserSession.serial(),
231-
KEY_SPEC_USER_SESSION_KEYRING);
232-
assert_eq!(SpecialKeyring::Group.serial(),
233-
KEY_SPEC_GROUP_KEYRING);
227+
assert_eq!(
228+
SpecialKeyring::UserSession.serial(),
229+
KEY_SPEC_USER_SESSION_KEYRING
230+
);
231+
assert_eq!(SpecialKeyring::Group.serial(), KEY_SPEC_GROUP_KEYRING);
234232
}
235233

236234
#[test]
237235
fn test_default_keyring_ids() {
238236
assert_eq!(DefaultKeyring::NoChange.serial(), KEY_REQKEY_DEFL_NO_CHANGE);
239-
assert_eq!(DefaultKeyring::ThreadKeyring.serial(),
240-
KEY_REQKEY_DEFL_THREAD_KEYRING);
241-
assert_eq!(DefaultKeyring::ProcessKeyring.serial(),
242-
KEY_REQKEY_DEFL_PROCESS_KEYRING);
243-
assert_eq!(DefaultKeyring::SessionKeyring.serial(),
244-
KEY_REQKEY_DEFL_SESSION_KEYRING);
245-
assert_eq!(DefaultKeyring::UserKeyring.serial(),
246-
KEY_REQKEY_DEFL_USER_KEYRING);
247-
assert_eq!(DefaultKeyring::UserSessionKeyring.serial(),
248-
KEY_REQKEY_DEFL_USER_SESSION_KEYRING);
249-
assert_eq!(DefaultKeyring::GroupKeyring.serial(),
250-
KEY_REQKEY_DEFL_GROUP_KEYRING);
251-
assert_eq!(DefaultKeyring::DefaultKeyring.serial(),
252-
KEY_REQKEY_DEFL_DEFAULT);
237+
assert_eq!(
238+
DefaultKeyring::ThreadKeyring.serial(),
239+
KEY_REQKEY_DEFL_THREAD_KEYRING
240+
);
241+
assert_eq!(
242+
DefaultKeyring::ProcessKeyring.serial(),
243+
KEY_REQKEY_DEFL_PROCESS_KEYRING
244+
);
245+
assert_eq!(
246+
DefaultKeyring::SessionKeyring.serial(),
247+
KEY_REQKEY_DEFL_SESSION_KEYRING
248+
);
249+
assert_eq!(
250+
DefaultKeyring::UserKeyring.serial(),
251+
KEY_REQKEY_DEFL_USER_KEYRING
252+
);
253+
assert_eq!(
254+
DefaultKeyring::UserSessionKeyring.serial(),
255+
KEY_REQKEY_DEFL_USER_SESSION_KEYRING
256+
);
257+
assert_eq!(
258+
DefaultKeyring::GroupKeyring.serial(),
259+
KEY_REQKEY_DEFL_GROUP_KEYRING
260+
);
261+
assert_eq!(
262+
DefaultKeyring::DefaultKeyring.serial(),
263+
KEY_REQKEY_DEFL_DEFAULT
264+
);
253265
}
254266

255267
#[test]

src/keytypes/blacklist.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ pub struct Description {
8181

8282
impl KeyDescription for Description {
8383
fn description(&self) -> Cow<str> {
84-
Cow::Owned(format!("{}:{}", self.hash_type.name(), AsciiHex::convert(&self.hash)))
84+
Cow::Owned(format!(
85+
"{}:{}",
86+
self.hash_type.name(),
87+
AsciiHex::convert(&self.hash),
88+
))
8589
}
8690
}

0 commit comments

Comments
 (0)