Skip to content

Commit 90df419

Browse files
committed
tests/utils: add a function to create an invalid key
1 parent ec9917b commit 90df419

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/tests/utils/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
use std::sync::atomic;
2828

29-
use crate::{Keyring, KeyringSerial, SpecialKeyring};
29+
use crate::{Key, Keyring, KeyringSerial, SpecialKeyring};
3030

3131
pub mod kernel;
3232
pub mod keys;
@@ -43,9 +43,17 @@ pub fn new_test_keyring() -> Keyring {
4343
.unwrap()
4444
}
4545

46-
pub fn invalid_keyring() -> Keyring {
46+
unsafe fn invalid_serial() -> KeyringSerial {
4747
// Yes, we're explicitly breaking the NonZeroI32 rules here. However, it is not passing through
4848
// any bits which care (e.g., `Option`), so this is purely to test that using an invalid
4949
// keyring ID gives back `EINVAL` as expected.
50-
unsafe { Keyring::new(KeyringSerial::new_unchecked(0)) }
50+
KeyringSerial::new_unchecked(0)
51+
}
52+
53+
pub fn invalid_keyring() -> Keyring {
54+
unsafe { Keyring::new(invalid_serial()) }
55+
}
56+
57+
pub fn invalid_key() -> Key {
58+
unsafe { Key::new(invalid_serial()) }
5159
}

0 commit comments

Comments
 (0)