endContactCAPKLoad

Commits all staged contact CAPKs to the EMV contact kernel.

This method finalizes the contact CAPK loading sequence by validating, processing, and activating all Certificate Authority Public Keys that were previously loaded via setContactCAPKs calls. It saves the CAPK data to persistent storage and configures the contact EMV kernel with the cryptographic keys required for offline data authentication.

Prerequisites:

Operations performed:

  1. Data validation - Verifies all loaded CAPKs for completeness and correctness

  2. Buffer persistence - Saves current contact CAPK data buffer to XML storage

  3. Kernel configuration - Loads validated CAPKs into the contact EMV kernel

Post-conditions:

  • All staged contact CAPKs are committed and active in the contact kernel

  • Contact EMV kernel is ready for offline data authentication

  • CAPK configurations are persisted to storage for future transactions

  • Contact transaction processing can proceed with cryptographic verification

Thread safety: This method should be called from the same thread that performed the setContactCAPKs calls to ensure data consistency and prevent CAPK corruption.

Exceptions: This function MUST NOT throw any exception. Any error must be indicated through NexusRet Any unexpected error must be mapped as NexusRet.INTERR

Implementation notes:

  • Validate that at least one contact CAPK was loaded before finalizing

  • Log detailed information about the number of CAPKs committed and their RID+Index pairs

  • Ensure atomic operation where possible (all CAPKs committed or none)

Return

NexusRet indicating the finalization result:

  • NexusRet.OK: All contact CAPKs committed successfully to the kernel

  • NexusRet.INTERR: Internal error during finalization or kernel configuration

  • Other values: Specific validation errors, cryptographic errors, or kernel failures

Usage sequence: This method must be called after all desired setContactCAPKs calls:

// Load multiple contact CAPKs for different payment schemes
emvPort.setContactCAPKs(visaContactCAPK1)
emvPort.setContactCAPKs(visaContactCAPK2)
emvPort.setContactCAPKs(mastercardContactCAPK1)
emvPort.setContactCAPKs(amexContactCAPK1)

// Finalize and commit all contact CAPKs
val result = emvPort.endContactCAPKLoad()

if (result == NexusRet.OK) {
// All contact CAPKs committed successfully
println("Contact EMV kernel configured with all CAPK data")
// Kernel is now ready for contact offline data authentication
} else {
// Handle finalization failure
println("Failed to finalize contact CAPK data: $result")
// May need to reset and reload CAPK configurations
}

Timber log suggestion: Log total count of contact CAPKs committed, their RID+Index pairs, and any validation errors.