Skip to content

Commit

Permalink
simple key-caps parser gopasspw#1917
Browse files Browse the repository at this point in the history
  • Loading branch information
TM2500 committed Jul 1, 2021
1 parent bfa4f59 commit a416ae2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion internal/backend/crypto/gpg/colons/parse_colons.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func Parse(reader io.Reader) gpg.KeyList {
Ownertrust: fields[8],
Identities: make(map[string]gpg.Identity, 1),
SubKeys: make(map[string]struct{}, 1),
Caps: parseKeyCaps(fields[11]),
}
case "sub":
fallthrough
Expand All @@ -111,8 +112,27 @@ func Parse(reader io.Reader) gpg.KeyList {
return kl
}

func parseKeyCaps(fields []string) gpg.Capabilities {
func parseKeyCaps(field string) gpg.Capabilities {
keycaps := gpg.Capabilities{}
caps := strings.ToLower(field)

if strings.Contains(caps, "S") {
keycaps.Sign = true
}
if strings.Contains(caps, "E") {
keycaps.Encrypt = true
}
if strings.Contains(caps, "C") {
keycaps.Certify = true
}
if strings.Contains(caps, "A") {
keycaps.Authentication = true
}
if strings.Contains(caps, "D") {
keycaps.Deactivated = true
}

return keycaps
}

func parseColonIdentity(fields []string) gpg.Identity {
Expand Down

0 comments on commit a416ae2

Please sign in to comment.