/* =========================================================================
 * Copyright (c) 2020 Qualcomm Technologies, Inc.
 * All Rights Reserved.
 * Confidential and Proprietary - Qualcomm Technologies, Inc.
 * =========================================================================
 */

#include <stdbool.h>
#include <string.h>
#include <stringl.h>

#include "check.h"
#include "CPrivacyPreservingID.h"
#include "IPrivacyPreservingID.h"
#include "object.h"
#include "qsee_env.h"
#include "qsee_log.h"
#include "sampleapp.h"

int run_ppid_test(void)
{
    int status = SAMPLEAPP_FAILED;
    uint8_t id[48] = {0};
    uint8_t salt[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
    Object ppid = Object_NULL;
    size_t sizeout = 0;

    CHECK_ELSE(
        Object_isOK(qsee_open(CPrivacyPreservingID_UID, &ppid)),
        ppid = Object_NULL; goto exit);

    status = IPrivacyPreservingID_getDeviceID(ppid, salt, sizeof(salt),
                                              id, sizeof(id), &sizeout);

    if (status == IPrivacyPreservingID_ERROR_FEATURE_NOT_LICENSED)
    {
        qsee_log(QSEE_LOG_MSG_ERROR, "PPID feature not licensed");
        status = Object_OK; // Pass test on unlicensed devices
    }

    status = Object_isOK(status) ? SAMPLEAPP_SUCCESS : SAMPLEAPP_FAILED;

exit:
    Object_ASSIGN_NULL(ppid);
    return status;
}