#ifndef DK_CMD_EXTERNAL_AUTHENTICATE_H
#define DK_CMD_EXTERNAL_AUTHENTICATE_H

#include <sec_apdu.h>

#include "dk_apdu.h"
#include "dk_common.h"
#include "dk_log.h"
#include "dk_constants.h"
#include "dk_scp_common.h"
#include "dk_scp_utils.h"
#include "dk_utils.h"


DK_Result external_authenticate(
    scp_context* ctx,
    byte* apdu,
    size_t* apdu_len,
    byte* wrapped_apdu,
    size_t* wrapped_apdu_len,
    byte cla);

/**
 * Generates an APDU with the External Authenticate command. It returs a "raw" buffer
 * and a signed or "wrapped" buffer containing the APDU.
 * 
 * @param ctx The SCP context
 * @param apdu The buffer that will hold the generated APDU
 * @param apdu_len The length of the generated APDU buffer
 * @param wrapped_apdu A buffer that will hold the signed APDU
 * @param apdu_len The length of the generated signed APDU buffer
 * 
 * @return DK_SUCCESS on success, an error code otherwise
*/
DK_Result gen_apdu_scp_03_external_authenticate(
    scp_context* ctx, 
    byte* apdu, 
    size_t* apdu_len, 
    byte* wrapped_apdu, 
    size_t* wrapped_apdu_len,
    byte cla);

/**
 * Handles the response of the External Authenticate command.
 * 
 * @param rpdu A buffer containing the response APDU
 * @param rpdu_len The length of the RPDU buffer
 * 
 * @return DK_SUCCESS on success, an error code otherwise
*/
DK_Result handle_external_authenticate_rpdu(
    byte* rpdu, 
    size_t* rpdu_len);

#endif