tink icon indicating copy to clipboard operation
tink copied to clipboard

Add Destroy Method to Go Manager

Open theory opened this issue 3 years ago • 0 comments

Should there be a Destory method on the Go manager? Something like:

// Destroy will destroy the key with given keyID.
// Returns an error if the key is not found or it is the primary key.
func (km *Manager) Destroy(keyID uint32) error {
	if km.ks == nil {
		return errors.New("keyset_manager: cannot destroy key, no keyset")
	}
	if km.ks.PrimaryKeyId == keyID {
		return errors.New("keyset_manager: cannot destroy the primary key")
	}
	for i, key := range km.ks.Key {
		if key.KeyId != keyID {
			continue
		}
		if key.Status == tinkpb.KeyStatusType_ENABLED || key.Status == tinkpb.KeyStatusType_DESTROYED {
			km.ks.Key[i].Status = tinkpb.KeyStatusType_DESTROYED
			return nil
		}
		return fmt.Errorf("keyset_manager: cannot destroy key with id %d with status %s", keyID, key.Status.String())
	}
	return fmt.Errorf("keyset_manager: key with id %d not found", keyID)
}

theory avatar Sep 02 '22 20:09 theory