|
|
|
@ -1,10 +1,10 @@
@@ -1,10 +1,10 @@
|
|
|
|
|
//! Process Services (PS) module. This is used for miscellaneous utility tasks, but
|
|
|
|
|
//! is particularly important because it is used to generate random data, which
|
|
|
|
|
//! is required for common things like [`HashMap`](std::collections::HashMap).
|
|
|
|
|
//! As such, it is initialized by default in `ctru::init` instead of having a safety handler
|
|
|
|
|
//! See also <https://www.3dbrew.org/wiki/Process_Services>
|
|
|
|
|
|
|
|
|
|
use crate::error::ResultCode; |
|
|
|
|
use crate::Result; |
|
|
|
|
|
|
|
|
|
#[repr(u32)] |
|
|
|
|
pub enum AESAlgorithm { |
|
|
|
@ -30,23 +30,44 @@ pub enum AESKeyType {
@@ -30,23 +30,44 @@ pub enum AESKeyType {
|
|
|
|
|
Keyslot39Nfc, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn local_friend_code_seed() -> crate::Result<u64> { |
|
|
|
|
let mut seed: u64 = 0; |
|
|
|
|
pub struct Ps(()); |
|
|
|
|
|
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?; |
|
|
|
|
Ok(seed) |
|
|
|
|
} |
|
|
|
|
impl Ps { |
|
|
|
|
pub fn new() -> Result<Self> { |
|
|
|
|
unsafe { |
|
|
|
|
ResultCode(ctru_sys::psInit())?; |
|
|
|
|
Ok(Ps(())) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn local_friend_code_seed(&self) -> crate::Result<u64> { |
|
|
|
|
let mut seed: u64 = 0; |
|
|
|
|
|
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?; |
|
|
|
|
Ok(seed) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn device_id() -> crate::Result<u32> { |
|
|
|
|
let mut id: u32 = 0; |
|
|
|
|
pub fn device_id(&self) -> crate::Result<u32> { |
|
|
|
|
let mut id: u32 = 0; |
|
|
|
|
|
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?; |
|
|
|
|
Ok(id) |
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?; |
|
|
|
|
Ok(id) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> { |
|
|
|
|
ResultCode(unsafe { |
|
|
|
|
ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) |
|
|
|
|
})?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn generate_random_bytes(out: &mut [u8]) -> crate::Result<()> { |
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) })?; |
|
|
|
|
Ok(()) |
|
|
|
|
impl Drop for Ps { |
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
unsafe { |
|
|
|
|
ctru_sys::psExit(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
|