/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Created in Samsung Ukraine R&D Center (SRK) under a contract between
 * LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine)
 * and "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
 */

/**
 * @file TigerCore.h
 * @brief TigerTa
 * @author Viktor Kopp (v.kopp@samsung.com)
 * @date Created Apr 26, 2016
 */

#ifndef TIGERCORE_H_
#define TIGERCORE_H_

#include "TigerTci.h"
#include "TzwCommon.h"

TEE_Result processCommand(const void* request, const uint32_t sizeRequest,
                          void* response, const uint32_t sizeResponse);


/**
 * @brief Generates an RSA key pair and stores it in TEE Storage
 *      Manages the link between the generated key and the parent key, i.e. key
 *      with which the certificate of the generated key has to be signed
 * @param[in] key alias;
 * @param[in] UID of calling process;
 * @return status of the operation, e.g. TEE_SUCCESS on success:
 */
TEE_Result generateKeyPair(const TciGenerateKeyPairMessage_t* const args);

/**
 * @brief Removes a key pair stored in TEE Storage.
 * @param[in] key alias;
 * @param[in] UID of calling process;
 * @return status of the operation, e.g. TEE_SUCCESS on success:
 */
TEE_Result deleteKeyPair(const TciKeyAlias_t* const alias, TciProcessUid_t callingUid);

/**
 * @brief Exports a public part of a key pair stored in TEE Storage.
 * @param[in] key alias;
 * @param[in] UID of calling process;
 * @param[out] public key;
 * @return status of the operation, e.g. TEE_SUCCESS on success:
 */
TEE_Result exportKey(const TciKeyAlias_t* const alias, TciProcessUid_t callingUid, TciExportedData_t* key);

/**
 * @brief Removes all persistent objects from TEE Storage
 * @return status of the operation, e.g. TEE_SUCCESS on success
 */
TEE_Result clearAll(bool removeAttkCertificates);

/**
 * @brief Checks the existence of a key pair with the given alias
 * @param[in] alias of a key pair to check
 * @return TEE_Result status: TEE_SUCCESS if key exists, TEE_ITEM_NOT FOUND if it does not,
 * or any other generic error code if failure happened
 */
TEE_Result existKey(const TciKeyAlias_t * const alias, TciProcessUid_t callingUid);

/**
 * @brief Returns user's uids who had/have generated keys in Tiger Storage
 * @[out] a set of byte-encoded TciProcessUid_t
 * @[out] size of the usersBuf with uids encoded (nbUsers = usersBufSize / sizeof(TciProcessUid_t))
 */
TEE_Result getClientUids(uint8_t* usersBuf, uint32_t* usersBufSize);

/**
 * @brief Removes all key-pairs, generated by uid.
 * @param[in] User identifier,
 * @return status of the operation, e.g. TEE_SUCCESS on success
 */
TEE_Result clearClientKeys(TciProcessUid_t uid);

/**
 * @brief get device status for soter service
 * @param[out] status DeviceKey status.
 * @return status of the operation, e.g. TEE_SUCCESS on success.
 */
TEE_Result getRegistrationStatus(TciDeviceStatus_t* deviceStatus);

#endif /* TIGERCORE_H_ */
