Browse Source

Refreshed PS module due to ctru::init

pull/92/head
Andrea Ciliberti 2 years ago
parent
commit
60f3e1fe5a
  1. 4
      ctru-rs/Cargo.toml
  2. 6
      ctru-rs/src/applets/swkbd.rs
  3. 34
      ctru-rs/src/services/ps.rs

4
ctru-rs/Cargo.toml

@ -15,8 +15,8 @@ name = "ctru" @@ -15,8 +15,8 @@ name = "ctru"
cfg-if = "1.0"
ctru-sys = { path = "../ctru-sys", version = "0.4" }
const-zero = "0.1.0"
linker-fix-3ds = { path = "../../rust-linker-fix-3ds" }
pthread-3ds = { path = "../../pthread-3ds" }
linker-fix-3ds = { git = "https://github.com/rust3ds/rust-linker-fix-3ds.git" }
pthread-3ds = {git = "https://github.com/rust3ds/pthread-3ds.git" }
libc = "0.2.121"
bitflags = "1.0.0"
widestring = "0.2.2"

6
ctru-rs/src/applets/swkbd.rs

@ -126,11 +126,7 @@ impl Swkbd { @@ -126,11 +126,7 @@ impl Swkbd {
/// the output will be truncated but should still be well-formed UTF-8
pub fn get_bytes(&mut self, buf: &mut [u8]) -> Result<Button, Error> {
unsafe {
match swkbdInputText(
self.state.as_mut(),
buf.as_mut_ptr(),
buf.len(),
) {
match swkbdInputText(self.state.as_mut(), buf.as_mut_ptr(), buf.len()) {
ctru_sys::SWKBD_BUTTON_NONE => Err(self.parse_swkbd_error()),
ctru_sys::SWKBD_BUTTON_LEFT => Ok(Button::Left),
ctru_sys::SWKBD_BUTTON_MIDDLE => Ok(Button::Middle),

34
ctru-rs/src/services/ps.rs

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
//! See also <https://www.3dbrew.org/wiki/Process_Services>
use crate::error::ResultCode;
use crate::Result;
#[repr(u32)]
pub enum AESAlgorithm {
@ -30,23 +31,44 @@ pub enum AESKeyType { @@ -30,23 +31,44 @@ pub enum AESKeyType {
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;
ResultCode(unsafe { ctru_sys::PS_GetLocalFriendCodeSeed(&mut seed) })?;
Ok(seed)
}
}
pub fn device_id() -> crate::Result<u32> {
pub fn device_id(&self) -> crate::Result<u32> {
let mut id: u32 = 0;
ResultCode(unsafe { ctru_sys::PS_GetDeviceId(&mut id) })?;
Ok(id)
}
}
pub fn generate_random_bytes(out: &mut [u8]) -> crate::Result<()> {
ResultCode(unsafe { ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len()) })?;
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(())
}
}
impl Drop for Ps {
fn drop(&mut self) {
unsafe {
ctru_sys::psExit();
}
}
}
#[cfg(test)]

Loading…
Cancel
Save