func (kp *Keypairs) Select(orgID *identity.ID, t primitive.KeyType) (*ClaimedKeyPair, error) {
	if orgID == nil {
		return nil, errors.New("Invalid OrgID Provided to select keypairs")
	}
	possible, ok := kp.keypairs[*orgID]
	if !ok {
		return nil, ErrMissingKeysForOrg
	}
	for _, k := range possible {
		if k.PublicKey.Body.KeyType == t && !k.Revoked() {
			return &k, nil
		}
	}
	return nil, ErrMissingValidKeypair
}
Select returns a keypair for the given type inside the specified
organization. If a valid key (non-revoked) cannot be found an error is
returned.
package registry
import (
	"context"
	"errors"
	"net/url"
	"github.com/manifoldco/torus-cli/apitypes"
	"github.com/manifoldco/torus-cli/envelope"
	"github.com/manifoldco/torus-cli/identity"
	"github.com/manifoldco/torus-cli/primitive"
)
var ErrPublicKeyNotFound = &apitypes.Error{
	Type: apitypes.NotFoundError,
	Err:  []string{"Could not find public key"},
}
var ErrMissingValidKeypair = &apitypes.Error{
	Type: apitypes.NotFoundError,
	Err:  []string{"Missing encryption or signing keypairs"},
}
var ErrMissingKeysForOrg = &apitypes.Error{
	Type: apitypes.NotFoundError,
	Err:  []string{"Could not find keypairs for org"},
}
type Keypairs struct {
	keypairs map[identity.ID][]ClaimedKeyPair
	idIndex  map[identity.ID]ClaimedKeyPair
}
func NewKeypairs() *Keypairs {
	return &Keypairs{
		keypairs: map[identity.ID][]ClaimedKeyPair{},
		idIndex:  map[identity.ID]ClaimedKeyPair{},
	}
}
func (kp *Keypairs) Add(keypairs ...ClaimedKeyPair) error {
	for _, k := range keypairs {
		kp.idIndex[*k.PublicKey.ID] = k
		orgID := *k.PublicKey.Body.OrgID
		_, ok := kp.keypairs[orgID]
		if !ok {
			kp.keypairs[orgID] = []ClaimedKeyPair{k}
			continue
		}
		kp.keypairs[orgID] = append(kp.keypairs[orgID], k)
	}
	return nil
}
func (kp *Keypairs) Get(publicKeyID *identity.ID) (*ClaimedKeyPair, error) {
	if publicKeyID == nil {
		return nil, errors.New("Invalid PublicKeyID provided to get keypair")
	}
	ckp, ok := kp.idIndex[*publicKeyID]
	if !ok {
		return nil, ErrPublicKeyNotFound
	}
	return &ckp, nil
}