Esempio n. 1
0
        /// <summary>
        /// Process ERASE instruction (CC3)
        /// <para>
        /// C-APDU: <code>00 0E {offset} {Lc} {length} </code>
        /// </para>
        /// <list type="table">
        ///     <item>
        ///         <term>offset</term>
        ///         <description>offset of first word of the file coded by P1 P2 (WORDS) to be erased.</description>
        ///     </item>
        ///     <item>
        ///         <term>length</term>
        ///         <description>number of words to be erased.</description>
        ///     </item>
        /// </list>
        /// </summary>
        /// <param name="apdu"></param>
        /// <returns></returns>
        private IFakeCardFeedback ProcessErase(CommandAPDU apdu)
        {
            // TODO: check ==> security of current EF

            byte[] apduBuffer = apdu.GetBuffer();
            apdu.SetIncomingAndReceive();

            // Check if Lc ==2
            short lc = APDUHelpers.getIncomingLength(apdu);

            if (lc != 2)
            {
                ISOException.throwIt(JavaCard.ISO7816.SW_WRONG_LENGTH);
            }

            short offset    = Util.getShort(apduBuffer, JavaCard.ISO7816.OFFSET_P1); // in WORDS
            short udcOffset = APDUHelpers.getOffsetCdata(apdu);
            short length    = Util.getShort(apduBuffer, udcOffset);                  // in WORDS

            VerifyOutOfFile(offset, length);

            _currentEF.Erase(offset, length);

            return(FakeCardFeedback.FromSuccess(unchecked ((short)0x9000)));
        }