@@ -395,6 +395,20 @@ private void verify(APDU apdu) {
395
395
ISOException .throwIt ((short ) (SW_PIN_FAILED_00 + pins [pinOffset ].getTriesRemaining ()));
396
396
}
397
397
398
+ /**
399
+ * Udpate the PIN and its length in a transaction.
400
+ * @param pinId which PIN will be updated.
401
+ * @param data contains the new PIN.
402
+ * @param dataOffset first byte of the new PIN in the data array.
403
+ * @param newLength the new PIN length.
404
+ */
405
+ private void updatePIN (short pinId , byte [] data , short dataOffset , byte newLength ) {
406
+ JCSystem .beginTransaction ();
407
+ pins [pinId ].update (data , dataOffset , newLength );
408
+ pinLength [pinId ] = newLength ;
409
+ JCSystem .commitTransaction ();
410
+ }
411
+
398
412
/**
399
413
* CHANGE REFERENCE DATA APDU implementation.
400
414
*/
@@ -426,9 +440,8 @@ private void changeReferenceData(APDU apdu) {
426
440
pinSubmitted [0 ] = false ;
427
441
ISOException .throwIt ((short ) (SW_PIN_FAILED_00 + pins [pinOffset ].getTriesRemaining ()));
428
442
}
429
- pins [pinOffset ].update (buffer , (short ) (ISO7816 .OFFSET_CDATA + currentLength ),
430
- (byte ) (length - currentLength ));
431
- pinLength [pinOffset ] = (byte ) (length - currentLength );
443
+ updatePIN (pinOffset , buffer , (short ) (ISO7816 .OFFSET_CDATA + currentLength ),
444
+ (byte ) (length - currentLength ));
432
445
}
433
446
434
447
/**
@@ -455,9 +468,8 @@ private void resetRetryCounter(APDU apdu) {
455
468
ISOException .throwIt (ISO7816 .SW_WRONG_LENGTH );
456
469
}
457
470
if (pins [PIN_INDEX_RC ].check (buffer , ISO7816 .OFFSET_CDATA , rcLength )) {
458
- pins [PIN_INDEX_PW1 ].update (buffer , (short ) (ISO7816 .OFFSET_CDATA + rcLength ),
459
- (byte ) (length - rcLength ));
460
- pinLength [PIN_INDEX_PW1 ] = (byte ) (length - rcLength );
471
+ updatePIN (PIN_INDEX_PW1 , buffer , (short ) (ISO7816 .OFFSET_CDATA + rcLength ),
472
+ (byte ) (length - rcLength ));
461
473
} else {
462
474
ISOException .throwIt ((short ) (SW_PIN_FAILED_00 + pins [PIN_INDEX_RC ].getTriesRemaining ()));
463
475
}
@@ -469,8 +481,7 @@ private void resetRetryCounter(APDU apdu) {
469
481
if (length < MIN_PIN1_LENGTH || length > MAX_PIN_LENGTH ) {
470
482
ISOException .throwIt (ISO7816 .SW_WRONG_LENGTH );
471
483
}
472
- pins [PIN_INDEX_PW1 ].update (buffer , ISO7816 .OFFSET_CDATA , (byte ) length );
473
- pinLength [PIN_INDEX_PW1 ] = (byte ) length ;
484
+ updatePIN (PIN_INDEX_PW1 , buffer , ISO7816 .OFFSET_CDATA , (byte ) length );
474
485
} else {
475
486
ISOException .throwIt (ISO7816 .SW_INCORRECT_P1P2 );
476
487
}
@@ -779,8 +790,7 @@ private void putData(APDU apdu) {
779
790
if (length > MAX_PIN_LENGTH || (length != (byte ) 0 && length < (byte ) 8 )) {
780
791
ISOException .throwIt (ISO7816 .SW_WRONG_LENGTH );
781
792
}
782
- pinLength [PIN_INDEX_RC ] = buffer [0 ];
783
- pins [PIN_INDEX_RC ].update (buffer , (short ) 1 , buffer [0 ]);
793
+ updatePIN (PIN_INDEX_RC , buffer , (short ) 1 , buffer [0 ]);
784
794
break ;
785
795
786
796
default :
0 commit comments