Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Help me understand a piece of code well

JavaCard Applet Development Related Questions and Answers.
Harten
Posts: 12
Joined: Tue Nov 17, 2015 7:41 am
Points :96
Contact:

Help me understand a piece of code well

Post by Harten » Fri Mar 11, 2016 4:02 am

I saw a piece of code from other website. But I don't know what this code does. Please help me to understand this well. Thanks a lot.

Code: Select all

short lc = (short) (a[ISO7816.OFFSET_LC] & 0xff);
short read = apdu.setIncomingAndReceive();
while(read < lc)
{
read += apdu.receiveBytes(read);
}

User avatar
vermont
Posts: 13
Joined: Tue May 26, 2015 10:18 pm
Points :6
Contact:

Re: Help me understand a piece of code well

Post by vermont » Fri Mar 18, 2016 11:29 pm

Here is the comments version.

Code: Select all

// Get the Lc from a standard length APDU. In JC2.2.2 use the Apdu methods for Lc.
short lc = (short) (a[ISO7816.OFFSET_LC] & 0xff);
// Ask the OS to read the incoming APDU.
short read = apdu.setIncomingAndReceive();
// Check how much was read. The OS may not be able to read the entire APDU in one call.
while(read < lc) {
// Keep reading until the OS has read all of the data in the APDU buffer.
    read += apdu.receiveBytes(read);
}

pitbar
Posts: 22
Joined: Wed Dec 02, 2015 5:39 am
Points :93
Contact:

Re: Help me understand a piece of code well

Post by pitbar » Sat Mar 19, 2016 3:53 am

Code: Select all

short lc = (short) (a[ISO7816.OFFSET_LC] & 0xff);

It's the standard way to compute Lc byte.

Code: Select all

short read = apdu.setIncomingAndReceive();

This line is to get at least the beginning of the incoming data in the APDU buffer.

Code: Select all

while(read < lc) 
{
    read += apdu.receiveBytes(read);
}

Appends whatever additional bytes receiveBytes returns, update read as this process goes.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 27 guests

JavaCard OS : Disclaimer