@@ -22,7 +22,7 @@ use crate::{
22
22
error:: { Error , ErrorCode } ,
23
23
fabric,
24
24
interaction_model:: messages:: GenericPath ,
25
- tlv:: { self , FromTLV , TLVElement , TLVList , TLVWriter , TagType , ToTLV } ,
25
+ tlv:: { self , FromTLV , Nullable , TLVElement , TLVList , TLVWriter , TagType , ToTLV } ,
26
26
transport:: session:: { Session , SessionMode , MAX_CAT_IDS_PER_NOC } ,
27
27
utils:: writebuf:: WriteBuf ,
28
28
} ;
@@ -282,7 +282,15 @@ impl Target {
282
282
}
283
283
284
284
type Subjects = [ Option < u64 > ; SUBJECTS_PER_ENTRY ] ;
285
- type Targets = [ Option < Target > ; TARGETS_PER_ENTRY ] ;
285
+
286
+ type Targets = Nullable < [ Option < Target > ; TARGETS_PER_ENTRY ] > ;
287
+ impl Targets {
288
+ fn init_notnull ( ) -> Self {
289
+ const INIT_TARGETS : Option < Target > = None ;
290
+ Nullable :: NotNull ( [ INIT_TARGETS ; TARGETS_PER_ENTRY ] )
291
+ }
292
+ }
293
+
286
294
#[ derive( ToTLV , FromTLV , Clone , Debug , PartialEq ) ]
287
295
#[ tlvargs( start = 1 ) ]
288
296
pub struct AclEntry {
@@ -298,14 +306,12 @@ pub struct AclEntry {
298
306
impl AclEntry {
299
307
pub fn new ( fab_idx : u8 , privilege : Privilege , auth_mode : AuthMode ) -> Self {
300
308
const INIT_SUBJECTS : Option < u64 > = None ;
301
- const INIT_TARGETS : Option < Target > = None ;
302
-
303
309
Self {
304
310
fab_idx : Some ( fab_idx) ,
305
311
privilege,
306
312
auth_mode,
307
313
subjects : [ INIT_SUBJECTS ; SUBJECTS_PER_ENTRY ] ,
308
- targets : [ INIT_TARGETS ; TARGETS_PER_ENTRY ] ,
314
+ targets : Targets :: init_notnull ( ) ,
309
315
}
310
316
}
311
317
@@ -324,12 +330,20 @@ impl AclEntry {
324
330
}
325
331
326
332
pub fn add_target ( & mut self , target : Target ) -> Result < ( ) , Error > {
333
+ if self . targets . is_null ( ) {
334
+ self . targets = Targets :: init_notnull ( ) ;
335
+ }
327
336
let index = self
328
337
. targets
338
+ . as_ref ( )
339
+ . notnull ( )
340
+ . unwrap ( )
329
341
. iter ( )
330
342
. position ( |s| s. is_none ( ) )
331
343
. ok_or ( ErrorCode :: NoSpace ) ?;
332
- self . targets [ index] = Some ( target) ;
344
+
345
+ self . targets . as_mut ( ) . notnull ( ) . unwrap ( ) [ index] = Some ( target) ;
346
+
333
347
Ok ( ( ) )
334
348
}
335
349
@@ -358,12 +372,17 @@ impl AclEntry {
358
372
fn match_access_desc ( & self , object : & AccessDesc ) -> bool {
359
373
let mut allow = false ;
360
374
let mut entries_exist = false ;
361
- for t in self . targets . iter ( ) . flatten ( ) {
362
- entries_exist = true ;
363
- if ( t. endpoint . is_none ( ) || t. endpoint == object. path . endpoint )
364
- && ( t. cluster . is_none ( ) || t. cluster == object. path . cluster )
365
- {
366
- allow = true
375
+ match self . targets . as_ref ( ) . notnull ( ) {
376
+ None => allow = true , // Allow if targets are NULL
377
+ Some ( targets) => {
378
+ for t in targets. iter ( ) . flatten ( ) {
379
+ entries_exist = true ;
380
+ if ( t. endpoint . is_none ( ) || t. endpoint == object. path . endpoint )
381
+ && ( t. cluster . is_none ( ) || t. cluster == object. path . cluster )
382
+ {
383
+ allow = true
384
+ }
385
+ }
367
386
}
368
387
}
369
388
if !entries_exist {
0 commit comments