Search in sources :

Example 16 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class IFDStatusDiff method merge.

private List<IFDStatusType> merge(List<IFDStatusType> deleted) {
    ArrayList<IFDStatusType> states = new ArrayList<IFDStatusType>(result.size() + deleted.size());
    states.addAll(result);
    // transform all deleted terminals so it is clear they disappeared
    for (IFDStatusType next : deleted) {
        IFDStatusType s = new IFDStatusType();
        s.setIFDName(next.getIFDName());
        s.setConnected(Boolean.FALSE);
        // slots must be present too
        for (SlotStatusType nextST : next.getSlotStatus()) {
            SlotStatusType st = new SlotStatusType();
            st.setIndex(nextST.getIndex());
            st.setCardAvailable(Boolean.FALSE);
            s.getSlotStatus().add(st);
        }
        // add new deleted terminal type to states list
        states.add(s);
    }
    this.result = states;
    return states;
}
Also used : ArrayList(java.util.ArrayList) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType)

Example 17 with IFDStatusType

use of iso.std.iso_iec._24727.tech.schema.IFDStatusType in project open-ecard by ecsec.

the class IFDStatusDiff method diff.

public void diff(List<IFDStatusType> others, boolean withNew) {
    result = new LinkedList<IFDStatusType>();
    deleted = new LinkedList<IFDStatusType>(expected);
    for (IFDStatusType next : others) {
        String nextName = next.getIFDName();
        if (expectedContains(nextName)) {
            // check for terminal connection
            IFDStatusType other = expectedGet(nextName);
            Boolean otherCard = other.isConnected();
            boolean otherCardB = (otherCard == null) ? false : otherCard.booleanValue();
            Boolean thisCard = next.isConnected();
            boolean thisCardB = (thisCard == null) ? false : thisCard.booleanValue();
            if (thisCardB != otherCardB) {
                result.add(next);
            } else {
                // check for card insertions or removals
                if (other.getSlotStatus().size() == next.getSlotStatus().size()) {
                    for (SlotStatusType nextSlot : next.getSlotStatus()) {
                        BigInteger thisSlotIdx = nextSlot.getIndex();
                        SlotStatusType otherSlot = null;
                        for (SlotStatusType nextOtherSlot : other.getSlotStatus()) {
                            if (thisSlotIdx.equals(nextOtherSlot.getIndex())) {
                                otherSlot = nextOtherSlot;
                                break;
                            }
                        }
                        // no equivalent slot, only occurs on evolving terminals ;-)
                        if (otherSlot == null) {
                            result.add(next);
                            break;
                        }
                        // compare card status of slot
                        if (nextSlot.isCardAvailable() != otherSlot.isCardAvailable()) {
                            result.add(next);
                            break;
                        }
                        // compare if there are different cards in slot
                        byte[] nextATR = nextSlot.getATRorATS();
                        byte[] otherATR = otherSlot.getATRorATS();
                        if (!(nextATR == null && otherATR == null) && !(IFDStatusDiff.arrayEquals(nextATR, otherATR))) {
                            result.add(next);
                            break;
                        }
                    }
                }
            }
            // delete card from deleted list
            deleted.remove(expectedGet(nextName));
        } else if (withNew) {
            result.add(next);
        }
    }
    merge(deleted);
}
Also used : BigInteger(java.math.BigInteger) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType)

Aggregations

IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)16 SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)9 ArrayList (java.util.ArrayList)7 Nonnull (javax.annotation.Nonnull)6 SCIOException (org.openecard.common.ifd.scio.SCIOException)5 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)4 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)4 GetStatus (iso.std.iso_iec._24727.tech.schema.GetStatus)3 BigInteger (java.math.BigInteger)3 LinkedList (java.util.LinkedList)3 Result (oasis.names.tc.dss._1_0.core.schema.Result)3 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 WaitResponse (iso.std.iso_iec._24727.tech.schema.WaitResponse)2 List (java.util.List)2 CancelResponse (iso.std.iso_iec._24727.tech.schema.CancelResponse)1 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)1 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)1