All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.emv.qrcode.decoder.cpm.ApplicationTemplateDecoder Maven / Gradle / Ivy
package com.emv.qrcode.decoder.cpm;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.BiConsumer;
import org.apache.commons.codec.binary.Hex;
import com.emv.qrcode.core.exception.DuplicateTagException;
import com.emv.qrcode.core.exception.PresentedModeException;
import com.emv.qrcode.core.model.cpm.BERTLAlphanumeric;
import com.emv.qrcode.core.model.cpm.BERTLBinary;
import com.emv.qrcode.core.model.cpm.BERTLCompressedNumeric;
import com.emv.qrcode.core.model.cpm.BERTLNumeric;
import com.emv.qrcode.core.model.cpm.BERTag;
import com.emv.qrcode.core.utils.BERUtils;
import com.emv.qrcode.model.cpm.ApplicationSpecificTransparentTemplate;
import com.emv.qrcode.model.cpm.ApplicationTemplate;
import com.emv.qrcode.model.cpm.constants.ConsumerPresentedModeFieldCodes;
import com.emv.qrcode.model.cpm.constants.TagTransactionProcessingCodes;
public final class ApplicationTemplateDecoder extends DecoderCpm {
private static final Entry, BiConsumer> defaultEntry = consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData);
private static final Map, BiConsumer>> mapConsumers = new HashMap<>();
static {
mapConsumers.put(ConsumerPresentedModeFieldCodes.ID_APPLICATION_SPECIFIC_TRANSPARENT_TEMPLATE, consumerTagLengthValue(ApplicationSpecificTransparentTemplate.class, ApplicationTemplate::setApplicationSpecificTransparentTemplate));
mapConsumers.put(TagTransactionProcessingCodes.ID_APPLICATION_DEFINITION_FILE_NAME, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_APPLICATION_LABEL, consumerTagLengthValue(BERTLAlphanumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_TRACK_2_EQUIVALENT_DATA, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_APPLICATION_PAN, consumerTagLengthValue(BERTLCompressedNumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_CARDHOLDER_NAME, consumerTagLengthValue(BERTLAlphanumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_LANGUAGE_PREFERENCE, consumerTagLengthValue(BERTLAlphanumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_ISSUER_URL, consumerTagLengthValue(BERTLAlphanumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_APPLICATION_VERSION_NUMBER, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_TOKEN_REQUESTOR_ID, consumerTagLengthValue(BERTLNumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_PAYMENT_ACCOUNT_REFERENCE, consumerTagLengthValue(BERTLAlphanumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_LAST_4_DIGITS_OF_PAN, consumerTagLengthValue(BERTLNumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_CRYPTOGRAM_INFORMATION_DATA, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_APPLICATION_TRANSACTION_COUNTER, consumerTagLengthValue(BERTLNumeric.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_APPLICATION_CRYPTOGRAM, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_ISSUER_APPLICATION_DATA, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
mapConsumers.put(TagTransactionProcessingCodes.ID_UNPREDICTABLE_NUMBER, consumerTagLengthValue(BERTLBinary.class, ApplicationTemplate::addAdditionalData));
}
public ApplicationTemplateDecoder(final byte[] source) {
super(BERUtils.valueOf(source));
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected ApplicationTemplate decode() throws PresentedModeException {
final Set tags = new HashSet<>();
final ApplicationTemplate result = new ApplicationTemplate();
while (iterator.hasNext()) {
final byte[] value = iterator.next();
final BERTag tag = new BERTag(BERUtils.valueOfTag(value));
if (tags.contains(tag)) {
throw new DuplicateTagException("ApplicationTemplate", tag.toString(), Hex.encodeHexString(value, false));
}
tags.add(tag);
final Entry, BiConsumer> entry = mapConsumers.getOrDefault(tag, defaultEntry);
final Class> clazz = entry.getKey();
final BiConsumer consumer = entry.getValue();
consumer.accept(result, DecoderCpm.decode(value, clazz));
}
return result;
}
}