|
|
@ -1,10 +1,10 @@ |
|
|
|
//! Process Services (PS) module. This is used for miscellaneous utility tasks, but
|
|
|
|
//! 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 particularly important because it is used to generate random data, which
|
|
|
|
//! is required for common things like [`HashMap`](std::collections::HashMap).
|
|
|
|
//! 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>
|
|
|
|
//! See also <https://www.3dbrew.org/wiki/Process_Services>
|
|
|
|
|
|
|
|
|
|
|
|
use crate::error::ResultCode; |
|
|
|
use crate::error::ResultCode; |
|
|
|
|
|
|
|
use crate::Result; |
|
|
|
|
|
|
|
|
|
|
|
#[repr(u32)] |
|
|
|
#[repr(u32)] |
|
|
|
pub enum AESAlgorithm { |
|
|
|
pub enum AESAlgorithm { |
|
|
@ -30,24 +30,45 @@ pub enum AESKeyType { |
|
|
|
Keyslot39Nfc, |
|
|
|
Keyslot39Nfc, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn local_friend_code_seed() -> crate::Result<u64> { |
|
|
|
pub struct Ps(()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
let mut seed: u64 = 0; |
|
|
|
|
|
|
|
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?; |
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?; |
|
|
|
Ok(seed) |
|
|
|
Ok(seed) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn device_id() -> crate::Result<u32> { |
|
|
|
pub fn device_id(&self) -> crate::Result<u32> { |
|
|
|
let mut id: u32 = 0; |
|
|
|
let mut id: u32 = 0; |
|
|
|
|
|
|
|
|
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?; |
|
|
|
ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?; |
|
|
|
Ok(id) |
|
|
|
Ok(id) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn generate_random_bytes(out: &mut [u8]) -> crate::Result<()> { |
|
|
|
pub fn generate_random_bytes(&self, out: &mut [u8]) -> crate::Result<()> { |
|
|
|
ResultCode(unsafe { ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) })?; |
|
|
|
ResultCode(unsafe { |
|
|
|
|
|
|
|
ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) |
|
|
|
|
|
|
|
})?; |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Drop for Ps { |
|
|
|
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
|
|
|
|
ctru_sys::psExit(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)] |
|
|
|
#[cfg(test)] |
|
|
|
mod tests { |
|
|
|
mod tests { |
|
|
|