command/keyring: refactor, adjust tests