Skip to content

Commit

Permalink
Filter out non-directories up front
Browse files Browse the repository at this point in the history
This way we error when given a path to a dir which contains files but
doesn't contain directories.
  • Loading branch information
jonnystoten committed May 7, 2024
1 parent 118ddd0 commit 80fa7fa
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions tools/key-verification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,30 @@ func main() {
if pathToKeys == "" {
pathToKeys = defaultKeysDir
}
devices, err := os.ReadDir(pathToKeys)
entries, err := os.ReadDir(pathToKeys)
if err != nil {
fmt.Fprintln(os.Stderr, "Error reading directory:", err)
os.Exit(1)
}
var devices []os.DirEntry
for _, device := range entries {
if device.IsDir() {
devices = append(devices, device)
}
}
if len(devices) == 0 {
fmt.Fprintln(os.Stderr, "No devices found in the directory:", pathToKeys)
os.Exit(1)
}
for _, device := range devices {
if device.IsDir() {
serial := device.Name()
path := filepath.Join(pathToKeys, serial)
err := verifyDeviceAttestation(serial, path)
if err != nil {
fmt.Fprintln(os.Stderr, "Error verifying device attestation:", err)
continue
}
fmt.Println("Device attestation verified for:", serial)
serial := device.Name()
path := filepath.Join(pathToKeys, serial)
err := verifyDeviceAttestation(serial, path)
if err != nil {
fmt.Fprintln(os.Stderr, "Error verifying device attestation:", err)
continue
}
fmt.Println("Device attestation verified for:", serial)
}
}

Expand Down

0 comments on commit 80fa7fa

Please sign in to comment.