class CliKeyPasswordResolver implements KeyPasswordResolver {

    @Override
    public void resolveKeyPasswords(final Config config) {

        final KeyConfiguration input = config.getKeys();
        if (input == null) {
            // invalid config, but gets picked up by validation later
            return;
        }

        final List<char[]> allPasswords = new ArrayList<>();
        if (input.getPasswords() != null) {
            allPasswords.addAll(
                input.getPasswords().stream().map(String::toCharArray).collect(Collectors.toList())
            );
        } else if (input.getPasswordFile() != null) {
            try {
                allPasswords.addAll(
                    Files.readAllLines(input.getPasswordFile(), StandardCharsets.UTF_8)
                        .stream()
                        .map(String::toCharArray)
                        .collect(Collectors.toList())
                );
            } catch (final IOException ex) {
                // dont do anything, if any keys are locked validation will complain that
                // locked keys were provided without passwords
                System.err.println("Could not read the password file");
            }
        }

        List<KeyData> keyPairs = input.getKeyData();

        IntStream.range(0, input.getKeyData().size())
                .forEachOrdered(
                        i -> {
                            if (i < allPasswords.size()) {
                                keyPairs.get(i).setPassword(allPasswords.get(i));
                            }
                        });

        // decrypt the keys, either using provided passwords or read from CLI

        EncryptorConfig encryptorConfig =
                Optional.ofNullable(config.getEncryptor())
                        .orElse(
                                new EncryptorConfig() {
                                    {
                                        setType(EncryptorType.NACL);
                                    }
                                });

        final KeyEncryptor keyEncryptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);

        IntStream.range(0, input.getKeyData().size())
                .forEachOrdered(
                        keyNumber -> getSingleKeyPassword(keyNumber, input.getKeyData().get(keyNumber), keyEncryptor));
    }

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

}