Add methods to get key capabilities (#125)
* Add methods to get key capabilities Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Use correct indetity to check for flags Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Fix lint Signed-off-by: Aditya Wasan <adityawasan55@gmail.com> * Remove CanCertify and update CanSign to use SigningKey Signed-off-by: GitHub <noreply@github.com> * keyring: implement CanSign and CanEncrypt Signed-off-by: GitHub <noreply@github.com> * key/keyring: add tests for key capabilities Signed-off-by: GitHub <noreply@github.com> * Apply suggestions from code review Renames CanSign to CanVerify and adds an extended test for public-only keys to confirm CanVerify is true for them. Co-authored-by: wussler <aron@wussler.it> Co-authored-by: Harsh Shandilya <me@msfjarvis.dev> Co-authored-by: wussler <aron@wussler.it>
This commit is contained in:
parent
80b9a7aca2
commit
3dd1711707
4 changed files with 58 additions and 0 deletions
|
|
@ -114,6 +114,28 @@ func (keyRing *KeyRing) GetIdentities() []*Identity {
|
|||
return identities
|
||||
}
|
||||
|
||||
// CanVerify returns true if any of the keys in the keyring can be used for verification.
|
||||
func (keyRing *KeyRing) CanVerify() bool {
|
||||
keys := keyRing.GetKeys()
|
||||
for _, key := range keys {
|
||||
if key.CanVerify() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CanEncrypt returns true if any of the keys in the keyring can be used for encryption.
|
||||
func (keyRing *KeyRing) CanEncrypt() bool {
|
||||
keys := keyRing.GetKeys()
|
||||
for _, key := range keys {
|
||||
if key.CanEncrypt() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetKeyIDs returns array of IDs of keys in this KeyRing.
|
||||
func (keyRing *KeyRing) GetKeyIDs() []uint64 {
|
||||
var res = make([]uint64, len(keyRing.entities))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue