//
// Created by Ht on 2022/11/15.
//

#ifndef INC_1_LIBDEVCPP_HONGDOUENCRYPT_H
#define INC_1_LIBDEVCPP_HONGDOUENCRYPT_H

#include <openssl/aes.h>
#include <string>
#include <qlibc/ByteUtils.h>

namespace jedge {

    enum CHIPPMessageType {
        CHIPPMessageTypeRes = 0,        // 控制指令响应
        CHIPPMessageTypeReq = 1,        // 状态上报请求
    };

    class JE_API IppMessage {
    public:
        unsigned char ver;
        std::string src;
        std::string dest;
        QQWord msgId;
        CHIPPMessageType msgType;
        std::string content;
    };

    bool decodeIppStructMessage(IppMessage& ippMsg, unsigned char* data, size_t data_len);

    bool makeIppStructMessage(IppMessage& ippMsg, unsigned char** buff,  size_t& len);

    size_t decryptRawBytes(QByte* cypherCode, QByte* iv_key,
                         QByte* payload, int payloadLen, QByte* out);

    size_t encryptRawBytes(QByte* cypherCode, QByte* iv_key,
                         QByte* payload, int payloadLen, QByte* out);
}


#endif //INC_1_LIBDEVCPP_HONGDOUENCRYPT_H
