1+ use std:: ffi:: CString ;
2+
13use bson:: { Document , RawDocument } ;
24use mongocrypt_sys as sys;
35
46use crate :: {
57 binary:: BinaryBuf ,
6- error:: { self , Result } ,
8+ error:: { self , encoding , Result } ,
79} ;
810
911pub ( crate ) fn doc_binary ( doc : & Document ) -> Result < BinaryBuf > {
@@ -13,15 +15,20 @@ pub(crate) fn doc_binary(doc: &Document) -> Result<BinaryBuf> {
1315 Ok ( BinaryBuf :: new ( bytes) )
1416}
1517
18+ pub ( crate ) fn path_cstring ( path : & std:: path:: Path ) -> Result < CString > {
19+ let bytes = path_bytes ( path) ?;
20+ CString :: new ( bytes) . map_err ( |e| encoding ! ( "could not convert path to cstring: {:?}" , e) )
21+ }
22+
1623#[ cfg( unix) ]
17- pub ( crate ) fn path_bytes ( path : & std:: path:: Path ) -> Result < Vec < u8 > > {
24+ fn path_bytes ( path : & std:: path:: Path ) -> Result < Vec < u8 > > {
1825 use std:: os:: unix:: prelude:: OsStrExt ;
1926
2027 Ok ( path. as_os_str ( ) . as_bytes ( ) . to_vec ( ) )
2128}
2229
2330#[ cfg( not( unix) ) ]
24- pub ( crate ) fn path_bytes ( path : & std:: path:: Path ) -> Result < Vec < u8 > > {
31+ fn path_bytes ( path : & std:: path:: Path ) -> Result < Vec < u8 > > {
2532 // This is correct for Windows because libmongocrypt internally converts
2633 // from utf8 to utf16 on that platform.
2734 use error:: Error ;
@@ -32,9 +39,9 @@ pub(crate) fn path_bytes(path: &std::path::Path) -> Result<Vec<u8>> {
3239 Ok ( s. as_bytes ( ) . to_vec ( ) )
3340}
3441
35- pub ( crate ) fn str_bytes_len ( s : & str ) -> Result < ( * const i8 , i32 ) > {
42+ pub ( crate ) fn str_bytes_len ( s : & str ) -> Result < ( * const std :: ffi :: c_char , i32 ) > {
3643 Ok ( (
37- s. as_bytes ( ) . as_ptr ( ) as * const i8 ,
44+ s. as_bytes ( ) . as_ptr ( ) as * const std :: ffi :: c_char ,
3845 s. as_bytes ( ) . len ( ) . try_into ( ) ?,
3946 ) )
4047}
0 commit comments