@@ -137,7 +137,12 @@ struct AncillaryDataIter<'a, T> {
137
137
}
138
138
139
139
impl < ' a , T > AncillaryDataIter < ' a , T > {
140
- pub fn new ( data : & ' a [ u8 ] ) -> AncillaryDataIter < ' a , T > {
140
+ /// Create `AncillaryDataIter` struct to iterate through the data unit in the control message.
141
+ ///
142
+ /// # Safety
143
+ ///
144
+ /// `data` must contain a valid control message.
145
+ unsafe fn new ( data : & ' a [ u8 ] ) -> AncillaryDataIter < ' a , T > {
141
146
AncillaryDataIter { data, phantom : PhantomData }
142
147
}
143
148
}
@@ -325,12 +330,24 @@ pub enum AncillaryData<'a> {
325
330
}
326
331
327
332
impl < ' a > AncillaryData < ' a > {
328
- fn as_rights ( data : & ' a [ u8 ] ) -> Self {
333
+ /// Create a `AncillaryData::ScmRights` variant.
334
+ ///
335
+ /// # Safety
336
+ ///
337
+ /// `data` must contain a valid control message and the control message must be type of
338
+ /// `SOL_SOCKET` and level of `SCM_RIGHTS`.
339
+ unsafe fn as_rights ( data : & ' a [ u8 ] ) -> Self {
329
340
let ancillary_data_iter = AncillaryDataIter :: new ( data) ;
330
341
let scm_rights = ScmRights ( ancillary_data_iter) ;
331
342
AncillaryData :: ScmRights ( scm_rights)
332
343
}
333
344
345
+ /// Create a `AncillaryData::ScmCredentials` variant.
346
+ ///
347
+ /// # Safety
348
+ ///
349
+ /// `data` must contain a valid control message and the control message must be type of
350
+ /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDENTIALS`.
334
351
#[ cfg( any(
335
352
doc,
336
353
target_os = "android" ,
@@ -345,7 +362,7 @@ impl<'a> AncillaryData<'a> {
345
362
target_os = "openbsd" ,
346
363
target_env = "uclibc" ,
347
364
) ) ]
348
- fn as_credentials ( data : & ' a [ u8 ] ) -> Self {
365
+ unsafe fn as_credentials ( data : & ' a [ u8 ] ) -> Self {
349
366
let ancillary_data_iter = AncillaryDataIter :: new ( data) ;
350
367
let scm_credentials = ScmCredentials ( ancillary_data_iter) ;
351
368
AncillaryData :: ScmCredentials ( scm_credentials)
0 commit comments