+
    	:i!  c                   s    R t ^ RIt^RIHt ^RIHt ^RIHt  ! R R]P                  4      t ! R R4      t ! R	 R
4      t	R# )zI
Classes and algorithms for matching requested access to access vectors.
N)access)objectmodel)utilc                   s0   a  ] tR t^t o RR ltR tRtV tR# )MatchNc                s:    Wn         W n        R V n        RV n        R# FN)	interfacedistinfo_dir_change__hash__)selfr   r      &&&6/usr/lib/python3.14/site-packages/sepolgen/matching.py__init__ZMatch.__init__    s    "	$     c                s     V P                   V P                  3pVP                   VP                  3pV! W44      #   \        \        3 d
    \        u # i ; iN)r   r   ZAttributeErrorZ	TypeErrorZNotImplemented)r	   ZotherZmethodab   &&&  r   _compareZMatch._compare(   sS    	"D001AU223A!<	* 	"!!	"s   7: AA)r   r   r   r   )N    )__name__
__module____qualname____firstlineno__r   r   __static_attributes____classdictcell__Z__classdict__   @r   r   r      s     " "r   r   c                   sN   a  ] tR t^1t o ^tR tR tR tR tR t	R t
R tRtV tR	# )
	MatchListc                s`    . V n         . V n        V P                  V n        R V n        RV n        R# r   )childrenbastardsDEFAULT_THRESHOLD	thresholdallow_info_dir_changeavr	      &r   r   ZMatchList.__init__3   s,    //%*"r   c                s    \        V P                  4      '       d   V P                  ^ ,          # \        V P                  4      '       d   V P                  ^ ,          # R# r   Nlenr   r   r#   r$   r   bestZMatchList.best<   sA    t}}==##t}}==##r   c                s`    \        V P                  4      \        V P                  4      ,           # r   r&   r#   r$   r   __len__ZMatchList.__len__C   s!     4==!C$666r   c                s,    \        V P                  4      # r   )Ziterr   r#   r$   r   __iter__ZMatchList.__iter__I   s    DMM""r   c                sX    \         P                  ! V P                  V P                  4      # r   )	itertoolschainr   r   r#   r$   r   allZMatchList.allL   s    t}}dmm<<r   c                s.   VP                   V P                  8:  d_   VP                  '       d   V P                  '       d   V P                  P                  V4       R # V P                  P                  V4       R # V P                  P                  V4       R # r   )r   r    r   r!   r   appendr   )r	   Zmatch   &&r   r.   ZMatchList.appendO   s_    ::'(((D,F,F,F$$U+$$U+MM  'r   c                sn    V P                   P                  4        V P                  P                  4        R # r   )r   sortr   r#   r$   r   r0   ZMatchList.sortX   s"    r   )r!   r"   r   r   r    N)r   r   r   r   r   r   r(   r)   r*   r-   r.   r0   r   r   r   r   r   r   r   1   s3     7#=( r   r   c                   sH   a  ] tR t^]t o R	R ltR tR tR tR tR t	Rt
V tR# )
AccessMatcherNc                s    ^
V n         ^
V n        V'       d   Wn        M\        P                  ! 4       V n        ^dV n        R# )i
   N)type_penaltyobj_penalty	perm_mapsr   ZPermMappingsinfo_dir_penalty)r	   r4   r/   r   r   ZAccessMatcher.__init__^   s4    &N(557DN !$r   c                sd    W8X  g   \         P                  ! V4      '       d   ^ # V P                  ) # r   )r    
is_idparamr2   )r	   r   r   r
   r   type_distanceZAccessMatcher.type_distancej   s)    6V&&q))%%%%r   c                sT   VP                   P                  VP                   4      p\        V4      ^ 8w  d*   V P                  P	                  VP
                  V4      pV) # VP                   P                  VP                   4      pV P                  P	                  VP
                  V4      # r6   )permsZ
differencer'   r4   getdefault_distance	obj_class)r	   Zav_reqZav_provZdiffZtotalr   r   perm_distanceZAccessMatcher.perm_distanceq   s}    ||&&w}}5t9>NN66v7G7GNE6M==++FLL9D>>55f6F6FMMr   c                sj   ^ pW0P                  VP                  VP                  4      ,          pW0P                  VP                  VP                  4      ,          pVP                  VP                  8w  d9   \        P
                  ! VP                  4      '       g   W0P                  ,          pV^ 8  d2   V P                  P                  VP                  VP                  4      pMV P                  W4      pV^ 8  d   V^ 8  d	   W4,           # W4,
          # V^ 8  d   V^ 8  d	   WC,
          # W4,           # R# )aT  Determine the 'distance' between 2 access vectors.

This function is used to find an access vector that matches
a 'required' access. To do this we comput a signed numeric
value that indicates how close the req access is to the
'provided' access vector. The closer the value is to 0
the closer the match, with 0 being an exact match.

A value over 0 indicates that the prov access vector provides more
access than the req (in practice, this means that the source type,
target type, and object class is the same and the perms in prov is
a superset of those in req.

A value under 0 indicates that the prov access less - or unrelated
- access to the req access. A different type or object class will
result in a very low value.

The values other than 0 should only be interpreted relative to
one another - they have no exact meaning and are likely to
change.

Params:
  req - [AccessVector] The access that is required. This is the
        access being matched.
  prov - [AccessVector] The access provided. This is the potential
         match that is being evaluated for req.
Returns:
  0   : Exact match between the access vectors.

  < 0 : The prov av does not provide all of the access in req.
        A smaller value indicates that the access is further.

  > 0 : The prov av provides more access than req. The larger
        the value the more access over req.
N)r8   Zsrc_typetgt_typer;   r    r7   r3   r4   r:   r9   r<   )r	   ZreqZprovr   Zpdistr   r   av_distanceZAccessMatcher.av_distance|   s    N  	""3<<??""3<<?? ==DNN*63D3DT^^3T3T$$$D !8NN66t~~tzzRE&&s1E !8qy|#|#QYqy|#|#	 r   c                s   RpV FX  pV P                  W$4      pVf   TpK  V^ 8  d   V^ 8  d   W5,          pK4  WS) ,           pK?  V^ 8  d   W5,          pKP  W5,          pKZ  	  V P                  P                  VP                  VP                  4      pVP
                  fe   \        P                  Vn        V FI  pVP
                  V P                  P                  VP                  VP                  4      ,          Vn        KK  	  V\        P                  ,          ^ 8X  dU   VP
                  \        P                  ,          '       d.   V^ 8  d   W0P                  ,          pV# W0P                  ,          pV# )z


        N)
r>   r4   Zgetdefault_directionr;   r9   Zinfo_dirr   Z	FLOW_NONEZ
FLOW_WRITEr5   )r	   Zav_setr"   r   ZxZtmpZav_dirs   &&&    r   av_set_matchZAccessMatcher.av_set_match   s-     A""2)C|19KD;D!8KDKD $ 44R\\288L??")33FO"(//"&.."E"EakkSTSZSZ"[#\  [+++q0vI_I_7_7_ax---  ---r   c                st   W#n         \        P                  ! VP                  VP                  P                  VP                  . 4      4       FX  pVP                  '       g   K  V P                  VP                  V4      pV^ 8  g   K<  \        WE4      pVP                  V4       KZ  	  VP                  4        R# r%   )r"   r+   r,   Ztgt_type_allZtgt_type_mapZgetr=   Zenabledr?   r    r   r.   r0   )r	   Zifsetr"   Z
match_listZivr   Zms   &&&&   r   
search_ifsZAccessMatcher.search_ifs   s    //%"4"4"'"4"4"8"8b"IKB:::$$RYY3Dqy"O!!!$K 	r   )r5   r3   r4   r2   r   )r   r   r   r   r   r8   r<   r>   r?   r@   r   r   r   r   r   r1   r1   ]   s,     
$&	NF$P&P r   r1   )
Z__doc__r+   Z r    r   r   Z
Comparisonr   r   r1   ) r   r   <module>rA      s?   (    "DOO "$) )X] ]r   