Skip to content

Commit

Permalink
minor re-org and optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiriMoran committed Jan 9, 2025
1 parent bf0f37c commit 0f267ba
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/symbolicexpr/symbolicPath.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func (path *SymbolicPath) isSubset(other *SymbolicPath, hints *Hints) bool {
path.Dst.isSubset(&other.Dst, hints)
}

func (path *SymbolicPaths) add(new *SymbolicPath, hints *Hints) *SymbolicPaths {

Check failure on line 30 in pkg/symbolicexpr/symbolicPath.go

View workflow job for this annotation

GitHub Actions / golangci-lint

builtinShadow: shadowing of predeclared identifier: new (gocritic)
if new.isEmpty(hints) {
return path
}
res := append(*path, new)
return &res
}

func (paths *SymbolicPaths) String() string {

Check failure on line 38 in pkg/symbolicexpr/symbolicPath.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1016: methods on the same type should have the same receiver name (seen 1x "path", 4x "paths") (stylecheck)
if len(*paths) == 0 {
return emptySet
Expand Down Expand Up @@ -132,27 +140,27 @@ func ComputeAllowGivenDenies(allowPaths, denyPaths *SymbolicPaths, hints *Hints)

// algorithm described in README of symbolicexpr
func computeAllowGivenAllowHigherDeny(allowPath, denyPath SymbolicPath, hints *Hints) *SymbolicPaths {
resAllowPaths := SymbolicPaths{}
resAllowPaths := &SymbolicPaths{}
for _, srcAtom := range denyPath.Src {
if !srcAtom.isTautology() {
srcAtomNegate := srcAtom.negate().(atomicTerm)
resAllowPaths = append(resAllowPaths, &SymbolicPath{Src: *allowPath.Src.copy().add(srcAtomNegate),
Dst: allowPath.Dst, Conn: allowPath.Conn})
resAllowPaths = resAllowPaths.add(&SymbolicPath{Src: *allowPath.Src.copy().add(srcAtomNegate),
Dst: allowPath.Dst, Conn: allowPath.Conn}, hints)
}
}
for _, dstAtom := range denyPath.Dst {
if !dstAtom.isTautology() {
dstAtomNegate := dstAtom.negate().(atomicTerm)
resAllowPaths = append(resAllowPaths, &SymbolicPath{Src: allowPath.Src, Dst: *allowPath.Dst.copy().add(dstAtomNegate),
Conn: allowPath.Conn})
resAllowPaths = resAllowPaths.add(&SymbolicPath{Src: allowPath.Src, Dst: *allowPath.Dst.copy().add(dstAtomNegate),
Conn: allowPath.Conn}, hints)
}
}
if !denyPath.Conn.IsAll() { // Connection of deny path is not tautology
resAllowPaths = append(resAllowPaths, &SymbolicPath{Src: allowPath.Src, Dst: allowPath.Dst,
Conn: allowPath.Conn.Subtract(denyPath.Conn)})
resAllowPaths = resAllowPaths.add(&SymbolicPath{Src: allowPath.Src, Dst: allowPath.Dst,
Conn: allowPath.Conn.Subtract(denyPath.Conn)}, hints)
}
// removes empty SymblicPaths; of non-empty paths removed redundant terms
return resAllowPaths.removeEmpty(hints).removeRedundant(hints)
return resAllowPaths.removeRedundant(hints)
}

// ConvertFWRuleToSymbolicPaths given a rule, converts its src, dst and Conn to SymbolicPaths
Expand Down

0 comments on commit 0f267ba

Please sign in to comment.