Page 1 of 1
Help me understand a piece of code well
Posted: Fri Mar 11, 2016 4:02 am
by Harten
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);
}
Re: Help me understand a piece of code well
Posted: Fri Mar 18, 2016 11:29 pm
by vermont
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);
}
Re: Help me understand a piece of code well
Posted: Sat Mar 19, 2016 3:53 am
by pitbar
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.