Skip to content

Commit

Permalink
refactor: simplify minID calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
tri-adam committed Mar 19, 2024
1 parent 7ad27b6 commit df206d4
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/integrity/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"cmp"
"errors"
"fmt"
"math"
"slices"

"github.com/ProtonMail/go-crypto/openpgp/clearsign"
Expand Down Expand Up @@ -141,20 +142,16 @@ func getGroupSignatures(f *sif.FileImage, groupID uint32, legacy bool) ([]sif.De
// in the object group with identifier groupID. If no such object group is found, errGroupNotFound
// is returned.
func getGroupMinObjectID(f *sif.FileImage, groupID uint32) (uint32, error) {
minID := ^uint32(0)
var minID uint32 = math.MaxUint32

f.WithDescriptors(func(od sif.Descriptor) bool {
if od.GroupID() != groupID {
return false
}

if id := od.ID(); id < minID {
minID = id
if od.GroupID() == groupID {
minID = min(minID, od.ID())
}
return false
})

if minID == ^uint32(0) {
if minID == math.MaxUint32 {
return 0, errGroupNotFound
}
return minID, nil
Expand Down

0 comments on commit df206d4

Please sign in to comment.