/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

#ifndef __ESTOOL_UTILS_H__
#define __ESTOOL_UTILS_H__

#define DEV_ROOT      "ROOT"
#define RVL_ROOT      "REVOLUTION_SDK_ROOT"
#define PKI_PATH_1    "/usr/etc/pki_data/"
#define PKI_PATH_2    "/X86/bin/pki_data/"

extern int utilFillSig(const char* rsaFile, int sigSize, u8* data, int dataSize);
extern int utilFillEccSig(const char* rsaFile, u8* data, int dataSize);
extern int utilVerify(const char* certFile, int sigSize, u8* data, int size);
extern int utilVerify2(const void* cert, int certSize, int sigSize, u8* data, int size, int useRootCert);
extern void utilFread(const char* name, u8* data, int size);
extern void utilFwrite(const char* name, u8* data, int size);

#define utilDumpCert1(c, t) \
    printf("cert sigType: %lx\n", (unsigned long)ntohl(*((u32*)(c))));  \
    printf("cert signature: "); \
    ptr = ((t*)(c))->sig.sig; \
    for (i=0; i<sigSize; i++) { \
        printf("0x%02x ", *ptr); ptr++; \
    } \
    printf("\n"); \
    printf("cert issuer: %s\n", ((t*)(c))->sig.issuer); \
    printf("cert pubKeyType: %ld\n", (unsigned long)ntohl(((t*)(c))->head.pubKeyType)); \
    printf("cert pubKey: "); \
    ptr = ((t*)(c))->pubKey; \
    for (i=0; i<keySize; i++) { \
        printf("0x%02x ", *ptr); ptr++; \
    } \
    printf("\n"); \
    printf("cert date: %ld\n", (unsigned long)ntohl(((t*)(c))->head.date)); \
    if (sizeof(t)==sizeof(IOSCRsa2048EccCert))  \
        printf("cert name: %s\n", ((t*)(c))->head.name.deviceId); \
    else \
        printf("cert name: %s\n", ((t*)(c))->head.name.serverId);

#define utilDumpCert2(c, t) \
    ptr = ((t*)(c))->exponent; \
    printf("cert exponent: "); \
    for (i=0; i<sizeof(IOSCRsaExponent); i++) {    \
        printf("0x%02x ", *ptr); ptr++; \
    } \
    printf("\n"); \

#endif /* __ESTOOL_UTILS_H__ */
