@@ -19,7 +19,6 @@ use alloc::vec::Vec;
19
19
20
20
use core:: convert:: TryInto ;
21
21
22
- use crate :: input:: SafeInputString ;
23
22
use bitbox02_sys:: keystore_error_t;
24
23
25
24
pub const BIP39_WORDLIST_LEN : u16 = bitbox02_sys:: BIP39_WORDLIST_LEN as u16 ;
@@ -62,12 +61,12 @@ impl core::convert::From<keystore_error_t> for Error {
62
61
}
63
62
}
64
63
65
- pub fn unlock ( password : & SafeInputString ) -> Result < ( ) , Error > {
64
+ pub fn unlock ( password : & str ) -> Result < ( ) , Error > {
66
65
let mut remaining_attempts: u8 = 0 ;
67
66
let mut securechip_result: i32 = 0 ;
68
67
match unsafe {
69
68
bitbox02_sys:: keystore_unlock (
70
- password. as_cstr ( ) ,
69
+ crate :: util :: str_to_cstr_vec ( password) . unwrap ( ) . as_ptr ( ) ,
71
70
& mut remaining_attempts,
72
71
& mut securechip_result,
73
72
)
@@ -85,18 +84,24 @@ pub fn lock() {
85
84
unsafe { bitbox02_sys:: keystore_lock ( ) }
86
85
}
87
86
88
- pub fn unlock_bip39 ( mnemonic_passphrase : & SafeInputString ) -> Result < ( ) , Error > {
89
- if unsafe { bitbox02_sys:: keystore_unlock_bip39 ( mnemonic_passphrase. as_cstr ( ) ) } {
87
+ pub fn unlock_bip39 ( mnemonic_passphrase : & str ) -> Result < ( ) , Error > {
88
+ if unsafe {
89
+ bitbox02_sys:: keystore_unlock_bip39 (
90
+ crate :: util:: str_to_cstr_vec ( mnemonic_passphrase)
91
+ . unwrap ( )
92
+ . as_ptr ( ) ,
93
+ )
94
+ } {
90
95
Ok ( ( ) )
91
96
} else {
92
97
Err ( Error :: CannotUnlockBIP39 )
93
98
}
94
99
}
95
100
96
- pub fn create_and_store_seed ( password : & SafeInputString , host_entropy : & [ u8 ] ) -> Result < ( ) , Error > {
101
+ pub fn create_and_store_seed ( password : & str , host_entropy : & [ u8 ] ) -> Result < ( ) , Error > {
97
102
match unsafe {
98
103
bitbox02_sys:: keystore_create_and_store_seed (
99
- password. as_cstr ( ) ,
104
+ crate :: util :: str_to_cstr_vec ( password) . unwrap ( ) . as_ptr ( ) ,
100
105
host_entropy. as_ptr ( ) ,
101
106
host_entropy. len ( ) as _ ,
102
107
)
@@ -304,9 +309,13 @@ pub fn bip39_mnemonic_to_seed(mnemonic: &str) -> Result<zeroize::Zeroizing<Vec<u
304
309
}
305
310
}
306
311
307
- pub fn encrypt_and_store_seed ( seed : & [ u8 ] , password : & SafeInputString ) -> Result < ( ) , Error > {
312
+ pub fn encrypt_and_store_seed ( seed : & [ u8 ] , password : & str ) -> Result < ( ) , Error > {
308
313
match unsafe {
309
- bitbox02_sys:: keystore_encrypt_and_store_seed ( seed. as_ptr ( ) , seed. len ( ) , password. as_cstr ( ) )
314
+ bitbox02_sys:: keystore_encrypt_and_store_seed (
315
+ seed. as_ptr ( ) ,
316
+ seed. len ( ) ,
317
+ crate :: util:: str_to_cstr_vec ( password) . unwrap ( ) . as_ptr ( ) ,
318
+ )
310
319
} {
311
320
keystore_error_t:: KEYSTORE_OK => Ok ( ( ) ) ,
312
321
err => Err ( err. into ( ) ) ,
0 commit comments