class CliKeyPasswordResolver implements KeyPasswordResolver {

    public void getSingleKeyPassword(final int keyNumber, final KeyData keyPair, final KeyEncryptor keyEncryptor) {

        final boolean isInline = KeyDataUtil.isInline(keyPair);
        final boolean isFilesystem = KeyDataUtil.isFileSystem(keyPair);

        if (!isInline && !isFilesystem) {
            // some other key type that doesn't use passwords, skip
            return;
        }

        final boolean isLocked = KeyDataUtil.isLocked(keyPair);

        if (isLocked) {

            ConfigKeyPair configKeyPair = KeyDataUtil.unmarshal(keyPair, keyEncryptor);

            int currentAttemptNumber = MAX_PASSWORD_ATTEMPTS;
            while (currentAttemptNumber > 0) {

                if (Objects.isNull(configKeyPair.getPassword())
                        || configKeyPair.getPassword().length == 0
                        || Optional.ofNullable(configKeyPair.getPrivateKey())
                                .filter(s -> s.contains("NACL_FAILURE"))
                                .isPresent()) {

                    final String attemptOutput =
                            "Attempt "
                                    + (MAX_PASSWORD_ATTEMPTS - currentAttemptNumber + 1)
                                    + " of "
                                    + MAX_PASSWORD_ATTEMPTS
                                    + ".";
                    System.out.printf("Password for key[%s] missing or invalid.", keyNumber);
                    System.out.println();
                    System.out.printf("%s Enter a password for the key", attemptOutput);
                    System.out.println();

                    final char[] pass = passwordReader.readPasswordFromConsole();
                    configKeyPair.withPassword(pass);
                    keyPair.setPassword(pass);
                }
                currentAttemptNumber--;
            }
        }
    }

    public  CliKeyPasswordResolver();
    public  CliKeyPasswordResolver(final PasswordReader passwordReader);

}