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} } ;
3
3
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.
9
10
///
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.
11
12
/// when passed to a callback) and must be copied if the values are
12
13
/// needed for longer.
13
14
#[ allow( non_camel_case_types) ]
14
15
#[ repr( C ) ]
15
- pub struct rustls_string {
16
- data : * const c_char ,
16
+ pub struct rustls_slice_bytes < ' a > {
17
+ data : * const u8 ,
17
18
len : size_t ,
19
+ phantom : PhantomData < & ' a [ u8 ] > ,
18
20
}
19
21
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 ,
24
26
len : s. len ( ) as size_t ,
27
+ phantom : PhantomData ,
25
28
}
26
29
}
27
30
}
28
31
29
- /// A read-only view on a Rust slice of bytes.
32
+ /// A read-only view on a vector of Rust byte slices.
33
+ ///
30
34
/// 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 .
33
37
///
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.
35
39
/// when passed to a callback) and must be copied if the values are
36
40
/// needed for longer.
37
41
#[ allow( non_camel_case_types) ]
38
42
#[ 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 > ,
41
45
len : size_t ,
42
46
}
43
47
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 ( ) ) ;
49
54
}
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 ( ) ,
62
58
}
63
- None => ( ) ,
64
- } ;
65
- strings
59
+ }
66
60
}
67
61
68
- /// A read-only view on a list of Rust bytes .
62
+ /// A read-only view on a Rust utf-8 string slice .
69
63
/// 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.
72
67
///
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.
74
69
/// when passed to a callback) and must be copied if the values are
75
70
/// needed for longer.
76
- ///
77
71
#[ allow( non_camel_case_types) ]
78
72
#[ repr( C ) ]
79
- pub struct rustls_vec_bytes {
80
- data : * const rustls_bytes ,
73
+ pub struct rustls_str < ' a > {
74
+ data : * const c_char ,
81
75
len : size_t ,
76
+ phantom : PhantomData < & ' a str > ,
82
77
}
83
78
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 ( ) ,
89
106
}
90
107
}
91
108
}
@@ -94,10 +111,9 @@ impl<'a> From<&'a Vec<rustls_bytes>> for rustls_vec_bytes {
94
111
/// This is used to pass data from crustls to callback functions provided
95
112
/// by the user of the API. The `data` is an array of `len` 16 bit values.
96
113
///
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.
98
115
/// when passed to a callback) and must be copied if the values are
99
116
/// needed for longer.
100
- ///
101
117
#[ allow( non_camel_case_types) ]
102
118
#[ repr( C ) ]
103
119
pub struct rustls_vec_ushort {
0 commit comments