generated from cunicu/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
name.go
45 lines (37 loc) · 1.29 KB
/
name.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// SPDX-FileCopyrightText: 2023 Steffen Vogel <post@steffenvogel.de>
// SPDX-License-Identifier: Apache-2.0
package filter
import (
"regexp"
iso "cunicu.li/go-iso7816"
)
// HasName compares the name of the smart card reader
// with the provided name.
func HasName(nameExpected string) Filter {
return func(reader string, _ *iso.Card) (bool, error) {
return reader == nameExpected, nil
}
}
// HasName matches the name of the smart card reader
// against the provided regular expression.
func HasNameRegex(regex string) Filter {
re := regexp.MustCompile(regex)
return func(reader string, _ *iso.Card) (bool, error) {
return re.MatchString(reader), nil
}
}
// IsYubikey checks if the smart card is a YubiKey
// based on the name of the smart card reader.
func IsYubiKey(reader string, card *iso.Card) (bool, error) {
return HasNameRegex("(?i)YubiKey")(reader, card)
}
// IsNikrokey checks if the smart card is a Nitrokey
// based on the name of the smart card reader.
func IsNitrokey(reader string, card *iso.Card) (bool, error) {
return HasNameRegex("(?i)Nitrokey")(reader, card)
}
// IsNikrokey3 checks if the smart card is a Nitrokey 3
// based on the name of the smart card reader.
func IsNitrokey3(reader string, card *iso.Card) (bool, error) {
return HasNameRegex("Nitrokey 3")(reader, card)
}