Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit f28a6e9

Browse files
docs: improve javadoc for CalypsoCard, selection and transaction managers
1 parent 585a469 commit f28a6e9

File tree

3 files changed

+116
-20
lines changed

3 files changed

+116
-20
lines changed

src/main/java/org/calypsonet/terminal/calypso/card/CalypsoCard.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Set;
17+
import org.calypsonet.terminal.calypso.GetDataTag;
18+
import org.calypsonet.terminal.calypso.SelectFileControl;
19+
import org.calypsonet.terminal.calypso.WriteAccessLevel;
20+
import org.calypsonet.terminal.calypso.transaction.CardTransactionManager;
21+
import org.calypsonet.terminal.calypso.transaction.SvAction;
22+
import org.calypsonet.terminal.calypso.transaction.SvOperation;
1723
import org.calypsonet.terminal.reader.selection.spi.SmartCard;
1824

1925
/**
@@ -174,6 +180,8 @@ public interface CalypsoCard extends SmartCard {
174180
* <p>The returned array contains the software issuer ID and the discretionary data.
175181
*
176182
* @return An empty array if the traceability information is not available.
183+
* @see CalypsoCardSelection#prepareGetData(GetDataTag)
184+
* @see CardTransactionManager#prepareGetData(GetDataTag)
177185
* @since 1.1.0
178186
*/
179187
byte[] getTraceabilityInformation();
@@ -182,6 +190,10 @@ public interface CalypsoCard extends SmartCard {
182190
* Returns the metadata of the current DF.
183191
*
184192
* @return Null if is not set.
193+
* @see CalypsoCardSelection#prepareSelectFile(short)
194+
* @see CalypsoCardSelection#prepareSelectFile(SelectFileControl)
195+
* @see CardTransactionManager#prepareSelectFile(short)
196+
* @see CardTransactionManager#prepareSelectFile(SelectFileControl)
185197
* @since 1.0.0
186198
*/
187199
DirectoryHeader getDirectoryHeader();
@@ -192,6 +204,9 @@ public interface CalypsoCard extends SmartCard {
192204
* <p>Note that if a secure session is actually running, then the object contains all session
193205
* modifications, which can be canceled if the secure session fails.
194206
*
207+
* <p>The file structure of the card image is updated as a result of file read and write
208+
* operations.
209+
*
195210
* @param sfi The SFI to search.
196211
* @return Null if the requested EF is not found or if the SFI is equal to 0.
197212
* @since 1.0.0
@@ -204,6 +219,9 @@ public interface CalypsoCard extends SmartCard {
204219
* <p>Note that if a secure session is actually running, then the object contains all session
205220
* modifications, which can be canceled if the secure session fails.
206221
*
222+
* <p>The file structure of the card image is updated as a result of file read and write
223+
* operations.
224+
*
207225
* @param lid The LID to search.
208226
* @return Null if the requested EF is not found.
209227
* @since 1.0.0
@@ -230,6 +248,9 @@ public interface CalypsoCard extends SmartCard {
230248
* <p>Note that if a secure session is actually running, then the set contains all session
231249
* modifications, which can be canceled if the secure session fails.
232250
*
251+
* <p>The file structure of the card image is updated as a result of file read and write
252+
* operations.
253+
*
233254
* @return A not null reference (it may be empty if no one EF is set).
234255
* @since 1.1.0
235256
*/
@@ -240,6 +261,8 @@ public interface CalypsoCard extends SmartCard {
240261
*
241262
* @return True if the card has been ratified.
242263
* @throws IllegalStateException If no session has been opened.
264+
* @see CalypsoCardSelection#preparePreOpenSecureSession(WriteAccessLevel)
265+
* @see CardTransactionManager#prepareOpenSecureSession(WriteAccessLevel)
243266
* @since 1.0.0
244267
*/
245268
boolean isDfRatified();
@@ -254,6 +277,8 @@ public interface CalypsoCard extends SmartCard {
254277
*
255278
* @return A positive value.
256279
* @throws IllegalStateException If no session has been opened.
280+
* @see CalypsoCardSelection#preparePreOpenSecureSession(WriteAccessLevel)
281+
* @see CardTransactionManager#prepareOpenSecureSession(WriteAccessLevel)
257282
* @since 1.2.0
258283
*/
259284
int getTransactionCounter();
@@ -307,6 +332,8 @@ public interface CalypsoCard extends SmartCard {
307332
*
308333
* @return True if the PIN status is blocked
309334
* @throws IllegalStateException If the PIN has not been checked.
335+
* @see CardTransactionManager#prepareCheckPinStatus()
336+
* @see CardTransactionManager#prepareVerifyPin(byte[])
310337
* @since 1.0.0
311338
*/
312339
boolean isPinBlocked();
@@ -316,6 +343,8 @@ public interface CalypsoCard extends SmartCard {
316343
*
317344
* @return The number of remaining attempts.
318345
* @throws IllegalStateException If the PIN has not been checked.
346+
* @see CardTransactionManager#prepareCheckPinStatus()
347+
* @see CardTransactionManager#prepareVerifyPin(byte[])
319348
* @since 1.0.0
320349
*/
321350
int getPinAttemptRemaining();
@@ -335,6 +364,11 @@ public interface CalypsoCard extends SmartCard {
335364
*
336365
* @return An int
337366
* @throws IllegalStateException If no SV Get command has been executed.
367+
* @see CardTransactionManager#prepareSvGet(SvOperation, SvAction)
368+
* @see CardTransactionManager#prepareSvDebit(int)
369+
* @see CardTransactionManager#prepareSvDebit(int, byte[], byte[])
370+
* @see CardTransactionManager#prepareSvReload(int)
371+
* @see CardTransactionManager#prepareSvReload(int, byte[], byte[], byte[])
338372
* @since 1.0.0
339373
*/
340374
int getSvBalance();
@@ -344,6 +378,11 @@ public interface CalypsoCard extends SmartCard {
344378
*
345379
* @return An int
346380
* @throws IllegalStateException If no SV Get command has been executed.
381+
* @see CardTransactionManager#prepareSvGet(SvOperation, SvAction)
382+
* @see CardTransactionManager#prepareSvDebit(int)
383+
* @see CardTransactionManager#prepareSvDebit(int, byte[], byte[])
384+
* @see CardTransactionManager#prepareSvReload(int)
385+
* @see CardTransactionManager#prepareSvReload(int, byte[], byte[], byte[])
347386
* @since 1.0.0
348387
*/
349388
int getSvLastTNum();
@@ -352,6 +391,11 @@ public interface CalypsoCard extends SmartCard {
352391
* Gets a reference to the last {@link SvLoadLogRecord}
353392
*
354393
* @return A last SV load log record object or null if not available.
394+
* @see CardTransactionManager#prepareSvGet(SvOperation, SvAction)
395+
* @see CardTransactionManager#prepareSvDebit(int)
396+
* @see CardTransactionManager#prepareSvDebit(int, byte[], byte[])
397+
* @see CardTransactionManager#prepareSvReload(int)
398+
* @see CardTransactionManager#prepareSvReload(int, byte[], byte[], byte[])
355399
* @since 1.0.0
356400
*/
357401
SvLoadLogRecord getSvLoadLogRecord();
@@ -360,6 +404,11 @@ public interface CalypsoCard extends SmartCard {
360404
* Gets a reference to the last {@link SvDebitLogRecord}
361405
*
362406
* @return A last SV debit log record object or null if not available.
407+
* @see CardTransactionManager#prepareSvGet(SvOperation, SvAction)
408+
* @see CardTransactionManager#prepareSvDebit(int)
409+
* @see CardTransactionManager#prepareSvDebit(int, byte[], byte[])
410+
* @see CardTransactionManager#prepareSvReload(int)
411+
* @see CardTransactionManager#prepareSvReload(int, byte[], byte[], byte[])
363412
* @since 1.0.0
364413
*/
365414
SvDebitLogRecord getSvDebitLogLastRecord();
@@ -368,6 +417,11 @@ public interface CalypsoCard extends SmartCard {
368417
* Gets list of references to the {@link SvDebitLogRecord} read from the card.
369418
*
370419
* @return An empty list if no log records are available.
420+
* @see CardTransactionManager#prepareSvGet(SvOperation, SvAction)
421+
* @see CardTransactionManager#prepareSvDebit(int)
422+
* @see CardTransactionManager#prepareSvDebit(int, byte[], byte[])
423+
* @see CardTransactionManager#prepareSvReload(int)
424+
* @see CardTransactionManager#prepareSvReload(int, byte[], byte[], byte[])
371425
* @since 1.0.0
372426
*/
373427
List<SvDebitLogRecord> getSvDebitLogAllRecords();

src/main/java/org/calypsonet/terminal/calypso/card/CalypsoCardSelection.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public interface CalypsoCardSelection extends CardSelection {
211211
* Adds a command APDU to read a single record from the indicated EF.
212212
*
213213
* <p>Once this command is processed, the result is available in {@link CalypsoCard} if the
214-
* requested file and record exist in the file structure of the card (best effort behavior).
214+
* requested file and record exist in the file structure of the card (best-effort mode).
215215
*
216216
* <p>Caution: the resulting APDU command must be compliant with PRIME revision 3 cards.
217217
* Therefore, the command may be rejected by some earlier revision cards.
@@ -289,8 +289,43 @@ public interface CalypsoCardSelection extends CardSelection {
289289
* feature, this optimizes future exchanges with the card in the case of secure sessions intended
290290
* to be executed in a single step.
291291
*
292-
* <p>Caution: the resulting APDU command is compliant with PRIME revision 3 cards supporting the
293-
* extended mode. Therefore, the command may be rejected by some earlier revision cards.
292+
* <p>The objective of the pre-opening is to allow the grouping of all the commands of a secure
293+
* session. This functionality is only relevant in the case of a distributed system where the
294+
* ticketing processing is done remotely in order to allow a complete secure session to be carried
295+
* out in a single exchange between the server and the terminal.
296+
*
297+
* <p>This mechanism is based on the anticipation of the APDU responses of the card.
298+
*
299+
* <p>In order to achieve the objective of a single exchange, it is essential to read locally
300+
* beforehand (out of session) all the data that will have to be read in session. If not,
301+
* additional exchanges will be made.
302+
*
303+
* <p>Then, the remote ticketing processing must prepare all the commands of the session (from
304+
* opening to closing) before executing it.
305+
*
306+
* <p>Example:
307+
*
308+
* <pre>{@code
309+
* transaction
310+
* .prepareOpenSecureSession(...)
311+
* .prepare...
312+
* [...]
313+
* .prepare...
314+
* .prepareCloseSecureSession()
315+
* .processCommands(...);
316+
* }</pre>
317+
*
318+
* <b>Caution</b>: this feature will be ineffective in the following cases:
319+
*
320+
* <ul>
321+
* <li>the card or the SAM does not support the extended mode
322+
* <li>the session contains commands that necessarily require exchanges with the card during the
323+
* session (e.g. PIN, Stored Value, encryption, early mutual authentication, data not
324+
* previously read outside the session)
325+
* <li>the session is opened with an access level different from the pre-opening one
326+
* <li>an intermediate "processCommand(...)" call has been made
327+
* <li>the session uses asymmetric cryptography
328+
* </ul>
294329
*
295330
* @param writeAccessLevel The write access level.
296331
* @return The object instance.

src/main/java/org/calypsonet/terminal/calypso/transaction/CardTransactionManager.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -706,9 +706,12 @@ CardTransactionManager prepareDecreaseCounters(
706706
* Schedules the execution of a <b>SV Reload</b> command to increase the current SV balance and
707707
* using the provided additional data.
708708
*
709-
* <p>Note #1: a communication with the SAM is done here.
709+
* <p>Once this command is processed, the SV data is updated in {@link CalypsoCard}.
710710
*
711-
* <p>Note #2: the key used is the reload key.
711+
* <p>See the methods {@link CalypsoCard#getSvBalance()}, {@link
712+
* CalypsoCard#getSvLoadLogRecord()}.
713+
*
714+
* <p>Note #1: the key used is the reload key.
712715
*
713716
* @param amount The value to be reloaded, positive or negative integer in the range.
714717
* -8388608..8388607
@@ -732,11 +735,14 @@ CardTransactionManager prepareDecreaseCounters(
732735
/**
733736
* Schedules the execution of a <b>SV Reload</b> command to increase the current SV balance.
734737
*
735-
* <p>Note #1: the optional SV additional data are set to zero.
738+
* <p>Once this command is processed, the SV data is updated in {@link CalypsoCard}.
736739
*
737-
* <p>Note #2: a communication with the SAM is done here.
740+
* <p>See the methods {@link CalypsoCard#getSvBalance()}, {@link
741+
* CalypsoCard#getSvLoadLogRecord()}.
742+
*
743+
* <p>Note #1: the optional SV additional data are set to zero.
738744
*
739-
* <p>Note #3: the key used is the reload key.
745+
* <p>Note #2: the key used is the reload key.
740746
*
741747
* @param amount The value to be reloaded, positive integer in the range 0..8388607 for a DO.
742748
* action, in the range 0..8388608 for an UNDO action.
@@ -763,9 +769,12 @@ CardTransactionManager prepareDecreaseCounters(
763769
* previous debit according to the type operation chosen in when invoking the previous SV Get
764770
* command.
765771
*
766-
* <p>Note #1: a communication with the SAM is done here.
772+
* <p>Once this command is processed, the SV data is updated in {@link CalypsoCard}.
767773
*
768-
* <p>Note #2: the key used is the reload key.
774+
* <p>See the methods {@link CalypsoCard#getSvBalance()}, {@link
775+
* CalypsoCard#getSvDebitLogLastRecord()}, {@link CalypsoCard#getSvDebitLogAllRecords()}.
776+
*
777+
* <p>Note #1: the key used is the debit key
769778
*
770779
* @param amount The amount to be subtracted or added, positive integer in the range 0..32767 when
771780
* subtracted and 0..32768 when added.
@@ -793,18 +802,14 @@ CardTransactionManager prepareDecreaseCounters(
793802
* <p>It consists in decreasing the current balance of the SV by a certain amount or canceling a
794803
* previous debit.
795804
*
796-
* <p>Note #1: the optional SV additional data are set to zero.
805+
* <p>Once this command is processed, the SV data is updated in {@link CalypsoCard}.
797806
*
798-
* <p>Note #2: a communication with the SAM is done here.
799-
*
800-
* <p>Note #3: the key used is the reload key.The information fields such as date and time are set
801-
* to 0. The extraInfo field propagated in Logs are automatically generated with the type of
802-
* transaction and amount.
807+
* <p>See the methods {@link CalypsoCard#getSvBalance()}, {@link
808+
* CalypsoCard#getSvDebitLogLastRecord()}, {@link CalypsoCard#getSvDebitLogAllRecords()}.
803809
*
804-
* <p>Note #4: operations that would result in a negative balance are forbidden (SV Exception
805-
* raised).
810+
* <p>Note #1: the optional SV additional data are set to zero.
806811
*
807-
* <p>Note #5: the key used is the debit key
812+
* <p>Note #2: the key used is the debit key
808813
*
809814
* @param amount The amount to be subtracted or added, positive integer in the range 0..32767 when
810815
* subtracted and 0..32768 when added.
@@ -1275,7 +1280,7 @@ CardTransactionManager prepareChangeKey(
12751280
*
12761281
* <p>Note that if the next prepared command is a "Read One Record" or "Read One Or More
12771282
* Counters", then it will by default be merged with the "Open Secure Session" command for
1278-
* optimization purposes.
1283+
* optimization purposes except if the "pre-open" mode is active.
12791284
*
12801285
* <p>This mechanism may in some cases be incompatible with the security constraints and can be
12811286
* disabled via the {@link CardSecuritySetting#disableReadOnSessionOpening()} method.
@@ -1290,6 +1295,8 @@ CardTransactionManager prepareChangeKey(
12901295
* <li>A secure session is already opened
12911296
* </ul>
12921297
*
1298+
* @see
1299+
* org.calypsonet.terminal.calypso.card.CalypsoCardSelection#preparePreOpenSecureSession(WriteAccessLevel)
12931300
* @since 1.6.0
12941301
*/
12951302
CardTransactionManager prepareOpenSecureSession(WriteAccessLevel writeAccessLevel);

0 commit comments

Comments
 (0)