1- use libc:: size_t;
2- use std:: os:: raw:: { c_char , c_uchar , c_ushort} ;
1+ use libc:: { c_char , size_t} ;
2+ use std:: { marker :: PhantomData , os:: raw:: { c_ushort} } ;
33
4- /// A read-only view on a Rust utf-8 string.
5- /// This is used to pass strings from crustls to callback functions provided
6- /// by the user of the API. The `data` is not NUL-terminated.
7- /// `len` indicates the number of utf-8 bytes than can be safely read.
8- /// A `len` of 0 is used to represent a missing value.
4+ /// A read-only view on a Rust byte slice.
5+ ///
6+ /// This is used to pass data from crustls to callback functions provided
7+ /// by the user of the API.
8+ /// `len` indicates the number of bytes than can be safely read.
9+ /// A `len` of 0 is used to represent a missing value OR an empty slice.
910///
10- /// The memmory exposed is available for the duration of the call (e.g.
11+ /// The memory exposed is available for the duration of the call (e.g.
1112/// when passed to a callback) and must be copied if the values are
1213/// needed for longer.
1314#[ allow( non_camel_case_types) ]
1415#[ repr( C ) ]
15- pub struct rustls_string {
16- data : * const c_char ,
16+ pub struct rustls_slice_bytes < ' a > {
17+ data : * const u8 ,
1718 len : size_t ,
19+ phantom : PhantomData < & ' a [ u8 ] > ,
1820}
1921
20- impl < ' a > From < & ' a str > for rustls_string {
21- fn from ( s : & str ) -> Self {
22- rustls_string {
23- data : s. as_ptr ( ) as * const c_char ,
22+ impl < ' a > From < & ' a [ u8 ] > for rustls_slice_bytes < ' a > {
23+ fn from ( s : & [ u8 ] ) -> Self {
24+ rustls_slice_bytes {
25+ data : s. as_ptr ( ) as * const u8 ,
2426 len : s. len ( ) as size_t ,
27+ phantom : PhantomData ,
2528 }
2629 }
2730}
2831
29- /// A read-only view on a Rust slice of bytes.
32+ /// A read-only view on a vector of Rust byte slices.
33+ ///
3034/// This is used to pass data from crustls to callback functions provided
31- /// by the user of the API. `len` indicates the number of bytes than can
32- /// be safely read. A `len` of 0 is used to represent a missing value .
35+ /// by the user of the API. The `data` is an array of `rustls_slice_bytes`
36+ /// structures with `len` elements .
3337///
34- /// The memmory exposed is available for the duration of the call (e.g.
38+ /// The memory exposed is available for the duration of the call (e.g.
3539/// when passed to a callback) and must be copied if the values are
3640/// needed for longer.
3741#[ allow( non_camel_case_types) ]
3842#[ repr( C ) ]
39- pub struct rustls_bytes {
40- data : * const c_uchar ,
43+ pub struct rustls_vec_slice_bytes < ' a > {
44+ data : * const rustls_slice_bytes < ' a > ,
4145 len : size_t ,
4246}
4347
44- impl < ' a > From < & ' a [ u8 ] > for rustls_bytes {
45- fn from ( s : & [ u8 ] ) -> Self {
46- rustls_bytes {
47- data : s. as_ptr ( ) as * const c_uchar ,
48- len : s. len ( ) as size_t ,
48+ impl < ' a > From < & ' a [ & [ u8 ] ] > for rustls_vec_slice_bytes < ' a > {
49+ fn from ( input : & ' a [ & [ u8 ] ] ) -> Self {
50+ let mut output: Vec < rustls_slice_bytes > = vec ! [ ] ;
51+ for b in input {
52+ let b: & [ u8 ] = b;
53+ output. push ( b. into ( ) ) ;
4954 }
50- }
51- }
52-
53- pub ( crate ) fn rustls_bytes_vec_from_slices < ' a > (
54- values : Option < & ' a [ & ' a [ u8 ] ] > ,
55- ) -> Vec < rustls_bytes > {
56- let mut strings: Vec < rustls_bytes > = Vec :: new ( ) ;
57- match values {
58- Some ( values) => {
59- for entry in values. iter ( ) {
60- strings. push ( rustls_bytes:: from ( * entry) )
61- }
55+ rustls_vec_slice_bytes {
56+ data : output. as_ptr ( ) ,
57+ len : output. len ( ) ,
6258 }
63- None => ( ) ,
64- } ;
65- strings
59+ }
6660}
6761
68- /// A read-only view on a list of Rust bytes .
62+ /// A read-only view on a Rust utf-8 string slice .
6963/// This is used to pass data from crustls to callback functions provided
70- /// by the user of the API. The `data` is an array of `rustls_bytes`
71- /// structures with `len` elements.
64+ /// by the user of the API. The `data` is not NUL-terminated.
65+ /// `len` indicates the number of bytes than can be safely read.
66+ /// A `len` of 0 is used to represent a missing value OR an empty string.
7267///
73- /// The memmory exposed is available for the duration of the call (e.g.
68+ /// The memory exposed is available for the duration of the call (e.g.
7469/// when passed to a callback) and must be copied if the values are
7570/// needed for longer.
76- ///
7771#[ allow( non_camel_case_types) ]
7872#[ repr( C ) ]
79- pub struct rustls_vec_bytes {
80- data : * const rustls_bytes ,
73+ pub struct rustls_str < ' a > {
74+ data : * const c_char ,
8175 len : size_t ,
76+ phantom : PhantomData < & ' a str > ,
8277}
8378
84- impl < ' a > From < & ' a Vec < rustls_bytes > > for rustls_vec_bytes {
85- fn from ( values : & Vec < rustls_bytes > ) -> Self {
86- rustls_vec_bytes {
87- data : values. as_ptr ( ) ,
88- len : values. len ( ) ,
79+ impl < ' a > From < & ' a str > for rustls_str < ' a > {
80+ fn from ( s : & str ) -> Self {
81+ rustls_str {
82+ data : s. as_ptr ( ) as * const c_char ,
83+ len : s. len ( ) as size_t ,
84+ phantom : PhantomData ,
85+ }
86+ }
87+ }
88+
89+ #[ allow( non_camel_case_types) ]
90+ #[ repr( C ) ]
91+ pub struct rustls_vec_str < ' a > {
92+ data : * const rustls_str < ' a > ,
93+ len : size_t ,
94+ }
95+
96+ impl < ' a > From < & ' a [ String ] > for rustls_vec_str < ' a > {
97+ fn from ( input : & ' a [ String ] ) -> Self {
98+ let mut output: Vec < rustls_str > = vec ! [ ] ;
99+ for b in input {
100+ let b: & str = b;
101+ output. push ( b. into ( ) ) ;
102+ }
103+ rustls_vec_str {
104+ data : output. as_ptr ( ) ,
105+ len : output. len ( ) ,
89106 }
90107 }
91108}
@@ -94,10 +111,9 @@ impl<'a> From<&'a Vec<rustls_bytes>> for rustls_vec_bytes {
94111/// This is used to pass data from crustls to callback functions provided
95112/// by the user of the API. The `data` is an array of `len` 16 bit values.
96113///
97- /// The memmory exposed is available for the duration of the call (e.g.
114+ /// The memory exposed is available for the duration of the call (e.g.
98115/// when passed to a callback) and must be copied if the values are
99116/// needed for longer.
100- ///
101117#[ allow( non_camel_case_types) ]
102118#[ repr( C ) ]
103119pub struct rustls_vec_ushort {
0 commit comments