11mod cfuture;
2+
23pub use cfuture:: * ;
34use std:: marker:: PhantomData ;
45
56mod cstream;
7+
68pub use cstream:: * ;
79
810pub use self :: bindings:: tanker_future;
@@ -18,12 +20,13 @@ pub type LogHandlerCallback = Box<dyn Fn(LogRecord) + Send>;
1820
1921use crate :: {
2022 AttachResult , Device , EncryptionOptions , Error , ErrorCode , LogRecord , LogRecordLevel , Options ,
21- SharingOptions , Status , VerificationMethod ,
23+ SharingOptions , Status , VerificationMethod , VerificationOptions ,
2224} ;
2325use lazy_static:: lazy_static;
2426use std:: convert:: TryFrom ;
2527use std:: ffi:: { c_void, CStr , CString } ;
2628use std:: os:: raw:: c_char;
29+ use std:: ptr:: NonNull ;
2730use std:: sync:: { Mutex , Once } ;
2831
2932static RUST_SDK_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
@@ -152,17 +155,47 @@ pub async unsafe fn generate_verification_key(ctanker: CTankerPtr) -> Result<Str
152155pub async unsafe fn register_identity (
153156 ctanker : CTankerPtr ,
154157 verification : * const CVerification ,
155- ) -> Result < ( ) , Error > {
156- let fut = unsafe { CFuture :: < c_void > :: new ( tanker_register_identity ( ctanker, verification) ) } ;
157- fut. await . map ( |_| ( ) )
158+ options : & VerificationOptions ,
159+ ) -> Result < Option < String > , Error > {
160+ let c_options = tanker_verification_options {
161+ version : 1 ,
162+ with_session_token : options. with_session_token ,
163+ } ;
164+ let fut = unsafe {
165+ CFuture :: < c_void > :: new ( tanker_register_identity ( ctanker, verification, & c_options) )
166+ } ;
167+ let token_str_ptr = fut. await ? as * mut i8 ;
168+ Ok ( NonNull :: new ( token_str_ptr) . map ( |str_ptr| {
169+ let str = CStr :: from_ptr ( str_ptr. as_ptr ( ) )
170+ . to_str ( )
171+ . unwrap ( )
172+ . to_owned ( ) ;
173+ free_buffer ( str_ptr. as_ptr ( ) as * mut c_void ) ;
174+ str
175+ } ) )
158176}
159177
160178pub async unsafe fn verify_identity (
161179 ctanker : CTankerPtr ,
162180 verification : * const CVerification ,
163- ) -> Result < ( ) , Error > {
164- let fut = unsafe { CFuture :: < c_void > :: new ( tanker_verify_identity ( ctanker, verification) ) } ;
165- fut. await . map ( |_| ( ) )
181+ options : & VerificationOptions ,
182+ ) -> Result < Option < String > , Error > {
183+ let c_options = tanker_verification_options {
184+ version : 1 ,
185+ with_session_token : options. with_session_token ,
186+ } ;
187+ let fut = unsafe {
188+ CFuture :: < c_void > :: new ( tanker_verify_identity ( ctanker, verification, & c_options) )
189+ } ;
190+ let token_str_ptr = fut. await ? as * mut i8 ;
191+ Ok ( NonNull :: new ( token_str_ptr) . map ( |str_ptr| {
192+ let str = CStr :: from_ptr ( str_ptr. as_ptr ( ) )
193+ . to_str ( )
194+ . unwrap ( )
195+ . to_owned ( ) ;
196+ free_buffer ( str_ptr. as_ptr ( ) as * mut c_void ) ;
197+ str
198+ } ) )
166199}
167200
168201pub async unsafe fn verify_provisional_identity (
@@ -176,10 +209,28 @@ pub async unsafe fn verify_provisional_identity(
176209pub async unsafe fn set_verification_method (
177210 ctanker : CTankerPtr ,
178211 verification : * const CVerification ,
179- ) -> Result < ( ) , Error > {
180- let fut =
181- unsafe { CFuture :: < c_void > :: new ( tanker_set_verification_method ( ctanker, verification) ) } ;
182- fut. await . map ( |_| ( ) )
212+ options : & VerificationOptions ,
213+ ) -> Result < Option < String > , Error > {
214+ let c_options = tanker_verification_options {
215+ version : 1 ,
216+ with_session_token : options. with_session_token ,
217+ } ;
218+ let fut = unsafe {
219+ CFuture :: < c_void > :: new ( tanker_set_verification_method (
220+ ctanker,
221+ verification,
222+ & c_options,
223+ ) )
224+ } ;
225+ let token_str_ptr = fut. await ? as * mut i8 ;
226+ Ok ( NonNull :: new ( token_str_ptr) . map ( |str_ptr| {
227+ let str = CStr :: from_ptr ( str_ptr. as_ptr ( ) )
228+ . to_str ( )
229+ . unwrap ( )
230+ . to_owned ( ) ;
231+ free_buffer ( str_ptr. as_ptr ( ) as * mut c_void ) ;
232+ str
233+ } ) )
183234}
184235
185236pub async unsafe fn get_verification_methods (
0 commit comments