class PlaintextKeysProvider implements CardKeysProvider {

    @Override
    public Optional<GPCardKeys> getCardKeys(String spec) {
        if (spec == null)
            return Optional.empty();
        
        // Default key, with shorthand
        if ("default".startsWith(spec.toLowerCase()))
            return Optional.of(PlaintextKeys.defaultKey());

        try {
            // emv:<hex>
            for (PlaintextKeys.Diversification d : PlaintextKeys.Diversification.values()) {
                if (spec.toLowerCase().startsWith(d.name().toLowerCase())) {
                    byte[] k = HexUtils.stringToBin(spec.substring(d.name().length() + 1));
                    return Optional.of(PlaintextKeys.derivedFromMasterKey(k, null, d));
                }
            }

            // hex
            byte[] k = HexUtils.stringToBin(spec);
            return Optional.of(PlaintextKeys.fromMasterKey(k));
        } catch (IllegalArgumentException e) {
            // log
        }
        return Optional.empty();
    }

}

class TestPlaintextKeysProvider {

    @Test
    public void testMasterKey() {

        CardKeysProvider p = new PlaintextKeysProvider();
        Assert.assertTrue(p.getCardKeys("404142434445464748494a4b4c4d4e4f").isPresent());
    }

}