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

Commit a814dd9

Browse files
docs: update prepareReadRecord methods documentation, remove NoSuchElementException (#14)
Closes #13
1 parent a4fd4cf commit a814dd9

File tree

8 files changed

+130
-97
lines changed

8 files changed

+130
-97
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Documentation of `prepareReadRecord` methods (issue [#13]).
10+
- Signature of methods throwing `NoSuchElementException` (issue [#13]).
811

912
## [1.0.2] - 2021-11-22
1013
### Deprecated
@@ -25,6 +28,7 @@ This is the initial release.
2528
[1.0.1]: https://github.com/calypsonet/calypsonet-terminal-calypso-java-api/compare/1.0.0...1.0.1
2629
[1.0.0]: https://github.com/calypsonet/calypsonet-terminal-calypso-java-api/releases/tag/1.0.0
2730

31+
[#13]: https://github.com/calypsonet/calypsonet-terminal-calypso-java-api/issues/13
2832
[#11]: https://github.com/calypsonet/calypsonet-terminal-calypso-java-api/issues/11
2933
[#9]: https://github.com/calypsonet/calypsonet-terminal-calypso-java-api/issues/9
3034
[#7]: https://github.com/calypsonet/calypsonet-terminal-calypso-java-api/issues/7

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
group = org.calypsonet.terminal
22
title = Calypsonet Terminal Calypso API
33
description = API defining the needed interfaces to manage Calypso cards
4-
version = 1.0.2
4+
version = 1.0.3
55

66
javaSourceLevel = 1.6
77
javaTargetLevel = 1.6

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import java.util.List;
1515
import java.util.Map;
16-
import java.util.NoSuchElementException;
1716
import org.calypsonet.terminal.reader.selection.spi.SmartCard;
1817

1918
/**
@@ -166,8 +165,7 @@ public interface CalypsoCard extends SmartCard {
166165
* modifications, which can be canceled if the secure session fails.
167166
*
168167
* @param sfi The SFI to search.
169-
* @return a not null reference.
170-
* @throws NoSuchElementException if requested EF is not found.
168+
* @return Null if the requested EF is not found.
171169
* @since 1.0.0
172170
*/
173171
ElementaryFile getFileBySfi(byte sfi);
@@ -179,8 +177,7 @@ public interface CalypsoCard extends SmartCard {
179177
* modifications, which can be canceled if the secure session fails.
180178
*
181179
* @param lid The LID to search.
182-
* @return a not null reference.
183-
* @throws NoSuchElementException if requested EF is not found.
180+
* @return Null if the requested EF is not found.
184181
* @since 1.0.0
185182
*/
186183
ElementaryFile getFileByLid(short lid);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ public interface CalypsoCardSelection extends CardSelection {
165165
/**
166166
* Adds a command APDU to read a single record from the indicated EF.
167167
*
168+
* <p>Once this command is processed, the result is available in {@link CalypsoCard} if the
169+
* requested file and record exist in the file structure of the card (best effort behavior).
170+
*
168171
* @param sfi The SFI of the EF to read
169172
* @param recordNumber The record number to read.
170173
* @return The object instance.

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
************************************************************************************** */
1212
package org.calypsonet.terminal.calypso.card;
1313

14-
import java.util.NoSuchElementException;
1514
import java.util.SortedMap;
1615

1716
/**
@@ -25,8 +24,7 @@ public interface FileData {
2524
* Gets a reference to the known content of record #1.<br>
2625
* For a Binary file, it means all the bytes of the file.
2726
*
28-
* @return a not empty reference to the record content.
29-
* @throws NoSuchElementException if record #1 is not set.
27+
* @return an empty array if the record #1 is not set.
3028
* @since 1.0.0
3129
*/
3230
byte[] getContent();
@@ -35,8 +33,7 @@ public interface FileData {
3533
* Gets a reference to the known content of a specific record.
3634
*
3735
* @param numRecord The record number.
38-
* @return a not empty reference to the record content.
39-
* @throws NoSuchElementException if record #numRecord is not set.
36+
* @return an empty array if the requested record is not set.
4037
* @since 1.0.0
4138
*/
4239
byte[] getContent(int numRecord);
@@ -47,9 +44,9 @@ public interface FileData {
4744
* @param numRecord The record number.
4845
* @param dataOffset The offset index (should be {@code >=} 0).
4946
* @param dataLength The data length (should be {@code >=} 1).
50-
* @return a copy not empty of the record subset content.
47+
* @return a not empty copy of the record subset content when the record is set, an empty array
48+
* when the record is not set.
5149
* @throws IllegalArgumentException if dataOffset {@code <} 0 or dataLength {@code <} 1.
52-
* @throws NoSuchElementException if record #numRecord is not set.
5350
* @throws IndexOutOfBoundsException if dataOffset {@code >=} content length or (dataOffset +
5451
* dataLength) {@code >} content length.
5552
* @since 1.0.0
@@ -71,23 +68,21 @@ public interface FileData {
7168
* e.g. if numCounter == 2, then value is extracted from bytes indexes [3,4,5].
7269
*
7370
* @param numCounter The counter number (should be {@code >=} 1).
74-
* @return The counter value or 0 if record #1 or numCounter is not set.
71+
* @return The counter value or null if record #1 or numCounter is not set.
7572
* @throws IllegalArgumentException if numCounter is {@code <} 1.
76-
* @throws NoSuchElementException if record #1 or numCounter is not set.
7773
* @throws IndexOutOfBoundsException if numCounter has a truncated value (when size of record #1
7874
* modulo 3 != 0).
7975
* @since 1.0.0
8076
*/
81-
int getContentAsCounterValue(int numCounter);
77+
Integer getContentAsCounterValue(int numCounter);
8278

8379
/**
8480
* Gets all known counters value.<br>
8581
* The counters values are extracted from record #1.<br>
8682
* If last counter has a truncated value (when size of record #1 modulo 3 != 0), then last counter
8783
* value is not returned.
8884
*
89-
* @return a not empty object.
90-
* @throws NoSuchElementException if record #1 is not set.
85+
* @return an empty map if record #1 is not set.
9186
* @since 1.0.0
9287
*/
9388
SortedMap<Integer, Integer> getAllCountersValue();

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

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.calypsonet.terminal.calypso.WriteAccessLevel;
1717
import org.calypsonet.terminal.calypso.card.CalypsoCard;
1818
import org.calypsonet.terminal.calypso.card.ElementaryFile;
19-
import org.calypsonet.terminal.calypso.card.FileData;
2019
import org.calypsonet.terminal.reader.CardReader;
2120

2221
/**
@@ -125,14 +124,29 @@ public interface CardTransactionManager {
125124
*
126125
* <p>Once this command is processed, the result is available in {@link CalypsoCard}.
127126
*
128-
* <p>See the method {@link CalypsoCard#getFileBySfi(byte)}, the objects {@link ElementaryFile},
129-
* {@link FileData} and their specialized methods according to the type of expected data: e.g.
130-
* {@link FileData#getContent(int)}.
127+
* <p>Depending on whether or not we are inside a secure session, there are two types of behavior
128+
* following this command:
129+
*
130+
* <ul>
131+
* <li>Outside a secure session (best effort mode): the following "process" command will not
132+
* fail whatever the existence of the targeted file or record (the {@link CalypsoCard}
133+
* object may not be filled).
134+
* <li>Inside a secure session in contactless mode (strict mode): the following "process"
135+
* command will fail if the targeted file or record does not exist (the {@link CalypsoCard}
136+
* object is always filled or an exception is raised when the reading failed).
137+
* </ul>
138+
*
139+
* <p><b>This method should not be used inside a secure session in contact mode</b> because
140+
* additional exchanges with the card will be operated and will corrupt the security of the
141+
* session. Instead, use the method {@link #prepareReadRecordFile(byte, int, int, int)} for this
142+
* case and provide valid parameters.
131143
*
132144
* @param sfi The SFI of the EF to read.
133145
* @param recordNumber The record number to read.
134146
* @return The current instance.
135147
* @throws IllegalArgumentException If one of the provided arguments is out of range.
148+
* @throws IllegalStateException If this method is invoked inside a secure session in contact
149+
* mode.
136150
* @since 1.0.0
137151
*/
138152
CardTransactionManager prepareReadRecordFile(byte sfi, int recordNumber);
@@ -143,12 +157,22 @@ public interface CardTransactionManager {
143157
*
144158
* <p>Once this command is processed, the result is available in {@link CalypsoCard}.
145159
*
146-
* <p>See the method {@link CalypsoCard#getFileBySfi(byte)}, the objects {@link ElementaryFile},
147-
* {@link FileData} and their specialized methods according to the type of expected data: e.g.
148-
* {@link FileData#getContent()}.
160+
* <p>Depending on whether or not we are inside a secure session, there are two types of behavior
161+
* following this command:
162+
*
163+
* <ul>
164+
* <li>Outside a secure session (best effort mode): the following "process" command will not
165+
* fail whatever the existence of the targeted file or record (the {@link CalypsoCard}
166+
* object may not be filled).
167+
* <li>Inside a secure session (strict mode): the following "process" command will fail if the
168+
* targeted file or record does not exist (the {@link CalypsoCard} object is always filled
169+
* or an exception is raised when the reading failed).<br>
170+
* Invalid parameters could lead to additional exchanges with the card and thus corrupt the
171+
* security of the session.
172+
* </ul>
149173
*
150174
* @param sfi The SFI of the EF.
151-
* @param firstRecordNumber The record number to read (or first record to read in case of several.
175+
* @param firstRecordNumber The record number to read (or first record to read in case of several
152176
* records)
153177
* @param numberOfRecords The number of records expected.
154178
* @param recordSize The record length.
@@ -164,13 +188,23 @@ CardTransactionManager prepareReadRecordFile(
164188
* which should be a counter file.
165189
*
166190
* <p>The record will be read up to the counter location indicated in parameter.<br>
167-
* Thus all previous counters will also be read.
191+
* Thus, all previous counters will also be read.
168192
*
169193
* <p>Once this command is processed, the result is available in {@link CalypsoCard}.
170194
*
171-
* <p>See the method {@link CalypsoCard#getFileBySfi(byte)}, the objects {@link ElementaryFile},
172-
* {@link FileData} and their specialized methods according to the type of expected data: e.g.
173-
* {@link FileData#getAllCountersValue()} (int)}.
195+
* <p>Depending on whether or not we are inside a secure session, there are two types of behavior
196+
* following this command:
197+
*
198+
* <ul>
199+
* <li>Outside a secure session (best effort mode): the following "process" command will not
200+
* fail whatever the existence of the targeted file or counter (the {@link CalypsoCard}
201+
* object may not be filled).
202+
* <li>Inside a secure session (strict mode): the following "process" command will fail if the
203+
* targeted file or counter does not exist (the {@link CalypsoCard} object is always filled
204+
* or an exception is raised when the reading failed).<br>
205+
* Invalid parameters could lead to additional exchanges with the card and thus corrupt the
206+
* security of the session.
207+
* </ul>
174208
*
175209
* @param sfi The SFI of the EF.
176210
* @param countersNumber The number of the last counter to be read.

src/main/uml/api_class_diagram.puml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@startuml
22
title
3-
Calypsonet - calypsonet-terminal-calypso-java-api - 1.0.+ (26/07/2021)
3+
Calypsonet - calypsonet-terminal-calypso-java-api - 1.0.+ (13/12/2021)
44
end title
55

66
' == THEME ==
@@ -80,7 +80,7 @@ package "org.calypsonet.terminal.calypso" as api {
8080
+CalypsoCardSelection filterByDfName (String aid)
8181
+CalypsoCardSelection setFileOccurrence (FileOccurrence fileOccurrence)
8282
+CalypsoCardSelection setFileControlInformation (FileControlInformation fileControlInformation)
83-
+CalypsoCardSelection addSuccessfulStatusWord (int statusWord)
83+
+<s>CalypsoCardSelection addSuccessfulStatusWord (int statusWord)</s>
8484

8585
+CalypsoCardSelection acceptInvalidatedCard ()
8686

@@ -182,7 +182,7 @@ package "org.calypsonet.terminal.calypso" as api {
182182
+byte[] getContent (int numRecord, int dataOffset, int dataLength)
183183
+SortedMap<Integer, byte[]> getAllRecordsContent ()
184184

185-
+int getContentAsCounterValue (int numCounter)
185+
+Integer getContentAsCounterValue (int numCounter)
186186
+SortedMap<Integer, Integer> getAllCountersValue ()
187187
}
188188
+enum "ProductType" as CardProductType {

0 commit comments

Comments
 (0)