#ifndef __PARSER_TLV_H__
#define __PARSER_TLV_H__

#include "basedef.h"

#define MAX_GENERAL_SIGNAL_LENGTH                               (950 * 1024)    //950K

#define MAX_SKPM_COMMAND_LENGTH                                 (10 * 1024)
#define MAX_SKPM_RESPONSE_LENGTH                                (10 * 1024)

#define MAX_GENERAL_RSA_ENCRYPTED_DATA_LENGTH                   (256)

// SKPM definition
#define SKPM_KEY_HANDLE_MAGIC_NUMBER_LENGTH      (2)
#define SKPM_KEY_HANDLE_VERSION_LENGTH           (2)
#define SKPM_KEY_HANDLE_ACCESS_TKOEN_LENGTH      (32)
#define SKPM_KEY_HANDLE_MAGIC_NUMBER             0x2C01
#define SKPM_KEY_HANDLE_VERSION                  0x0001

// MSG(RSA decrypted data) definition
static const uint8 MSG_VERSION = 0x01;


// Decryption command
typedef struct {
    uint32 tag;
    uint32 length;
    uint32 offset;

    TlvDecodeData sub1Certificate;          //[M]
    TlvDecodeData leafCertificate;          //[M]
    TlvDecodeData rsaPrivateKeyHandle;      //[M]
    TlvDecodeData rsaEncryptedData;         //[M]
    TlvDecodeData aesEncryptedData;         //[M]
} TlvDecryptionCommand;

// RSA decrypted data
typedef struct {
    TlvDecodeData msgVersion;               //[M]
    TlvDecodeData msgHM;                    //[M]
    TlvDecodeData msgHmacKey;               //[M]
    TlvDecodeData msgAesKey;                //[M]
} TlvRsaDecryptedData;

typedef struct {
    uint32 tag;
    uint32 length;
    uint32 offset;

    TlvDecodeData skpmWrappedData;          //[M]
} TlvSkpmProvisioningCommand;

typedef struct
{
    TlvDecodeData sub1Certificate;          //[M] Sub1 certificate (X.509)
    TlvDecodeData leafCertificate;          //[M] Leaf certificate (X.509)
    TlvDecodeData rsaPrivateKey;            //[M] Leaf RSA private key (RFC 3447)
} TlvSkpmUnwrappedData;

boolean parseDecryptionCommand(const BlobData* pBlobInput, TlvDecryptionCommand* pTlvDecryptionCommand);
boolean parseRsaDecryptedData(const BlobData* pBlobInput, TlvRsaDecryptedData* pTlvRsaDecryptedData);
boolean parseSkpmProvisioningCommand(const BlobData* pBlobInput, TlvSkpmProvisioningCommand* pTlvSkpmProvisioningCommand);
boolean parseSkpmUnwrappedData(const BlobData* pBlobInput, TlvSkpmUnwrappedData* pTlvSkpmUnwrappedData);

#endif  //end of __PARSER_TLV_H__
