#ifndef OverbyteIcsJoseTst1H
#define OverbyteIcsJoseTst1H

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.Dialogs.hpp>

#include "OverbyteIcsTypes.hpp"
#include "OverbyteIcsSslBase.hpp"
#include "OverbyteIcsSslX509Utils.hpp"
#include "OverbyteIcsSslJose.hpp"

#include <memory>
#include <vector>

class TJsonDemoForm : public TForm
{
__published:
    TLabel *Label18;
    TMemo *LogWin;
    TPageControl *PageControl;
    //JSON/XML tab
    TTabSheet *TabSheetJson;
    TListView *JsonGrid;
    TMemo *JsonInput;
    TPanel *PanelButtons;
    TLabel *Label33;
    TButton *doParseJson;
    TButton *doLoadFile;
    TButton *doParseXML;
    TCheckBox *CompactXML;
    TCheckBox *LogJson;
    //Jose tab
    TTabSheet *TabSheetJose;
    TLabel *Label25;
    TLabel *Label26;
    TLabel *Label27;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *LabelPKey;
    TLabel *Label5;
    TMemo *JoseTextLines;
    TEdit *TestHmacKey;
    TButton *doTestSign;
    TButton *doJWSCreate;
    TButton *doSignHmac;
    TComboBox *TestPrivKeyFile;
    TButton *doJWKCreate;
    TMemo *RawJWK;
    TButton *doJKWRead;
    TCheckBox *ShowRawKey;
    TButton *doNewPrivKey;
    TButton *doClear;
    TBitBtn *SelFile;
    TButton *doJWSRead;
    TCheckBox *JwkPrivate;
    TButton *doLoadKeyFile;
    TButton *doKeyParams;
    TCheckBox *SignECDSAIEEE;
    TListBox *NewprivKey;
    TListBox *TestJWSAlg;
    TButton *doEncryptPkeyExt;
    //Transcode tab
    TTabSheet *TabSheet1;
    TLabel *Label6;
    TLabel *Label7;
    TLabel *Label8;
    TLabel *Label9;
    TLabel *Label4;
    TMemo *CodeTextLines;
    TButton *doBase64Enc;
    TButton *doB64URLEn;
    TButton *doTestUrlEnc;
    TButton *doHexEncode;
    TButton *doEncodeURL;
    TButton *doBase64Dec;
    TButton *doB64URLDec;
    TButton *doHashDigest;
    TButton *doHexDec;
    TButton *doDecodeURL;
    TEdit *HexText;
    TEdit *URLText;
    TEdit *Base64Text;
    //Cryptography tab
    TTabSheet *TabSheetCrypto;
    TLabel *Label3;
    TLabel *Label10;
    TLabel *LabelCipher;
    TLabel *Label11;
    TLabel *Label12;
    TLabel *Label13;
    TLabel *Label14;
    TLabel *Label15;
    TLabel *Label16;
    TLabel *Label17;
    TLabel *Label19;
    TLabel *Label20;
    TLabel *Label21;
    TButton *doEncryprPWText;
    TButton *doEncryptPkeyNew;
    TButton *doEncryprPWFile;
    TListBox *ListCiphers;
    TMemo *CryptTextIn;
    TEdit *CipherRawKey;
    TRadioGroup *EncKeyType;
    TEdit *CipherRawIV;
    TEdit *CipherPassword;
    TButton *doCheckCrypt;
    TButton *doEncryptText;
    TButton *doDecryptText;
    TMemo *CryptTextOut;
    TEdit *CipherName;
    TEdit *CipherPwSalt;
    TRadioGroup *CipherBFBits;
    TListBox *CipherICsTypes;
    TBitBtn *SelCiphFile;
    TEdit *CipherAEAD;
    TButton *doQuickEncrypt;
    TButton *doEncryptStream;
    TButton *doEncryptFile;
    TEdit *CipherFileName;
    TCheckBox *CipherRandomSalt;
    TOpenDialog *OpenDlg;
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall doClearClick(TObject *Sender);
    void __fastcall doParseClick(TObject *Sender);
    void __fastcall doLoadFileClick(TObject *Sender);
    void __fastcall JsonGridDblClick(TObject *Sender);
    void __fastcall JoseTextLinesDblClick(TObject *Sender);
    void __fastcall CodeTextLinesDblClick(TObject *Sender);
    void __fastcall NewprivKeyClick(TObject *Sender);
    void __fastcall TestJWSAlgoldChange(TObject *Sender);
    void __fastcall TestPrivKeyFileChange(TObject *Sender);
    void __fastcall SelFileClick(TObject *Sender);
    void __fastcall doNewPrivKeyClick(TObject *Sender);
    void __fastcall doLoadKeyFileClick(TObject *Sender);
    void __fastcall doKeyParamsClick(TObject *Sender);
    void __fastcall doSignHmacClick(TObject *Sender);
    void __fastcall doTestSignClick(TObject *Sender);
    void __fastcall doJWKCreateClick(TObject *Sender);
    void __fastcall doJKWReadClick(TObject *Sender);
    void __fastcall doJWSCreateClick(TObject *Sender);
    void __fastcall doJWSReadClick(TObject *Sender);
    void __fastcall doEncryptPkeyExtClick(TObject *Sender);
    void __fastcall doBase64EncClick(TObject *Sender);
    void __fastcall doBase64DecClick(TObject *Sender);
    void __fastcall doB64URLEnClick(TObject *Sender);
    void __fastcall doB64URLDecClick(TObject *Sender);
    void __fastcall doTestUrlEncClick(TObject *Sender);
    void __fastcall doHexEncodeClick(TObject *Sender);
    void __fastcall doHexDecClick(TObject *Sender);
    void __fastcall doEncodeURLClick(TObject *Sender);
    void __fastcall doDecodeURLClick(TObject *Sender);
    void __fastcall doHashDigestClick(TObject *Sender);
    void __fastcall doEncryprPWTextClick(TObject *Sender);
    void __fastcall doEncryprPWFileClick(TObject *Sender);
    void __fastcall doEncryptPkeyClick(TObject *Sender);
    void __fastcall ListCiphersClick(TObject *Sender);
    void __fastcall CipherICsTypesClick(TObject *Sender);
    void __fastcall CipherNameClick(TObject *Sender);
    void __fastcall CipherBFBitsClick(TObject *Sender);
    void __fastcall SelCiphFileClick(TObject *Sender);
    void __fastcall doCheckCryptClick(TObject *Sender);
    void __fastcall doEncryptTextClick(TObject *Sender);
    void __fastcall doDecryptTextClick(TObject *Sender);
    void __fastcall doQuickEncryptClick(TObject *Sender);
    void __fastcall doEncryptStreamClick(TObject *Sender);
    void __fastcall doEncryptFileClick(TObject *Sender);

private:
    std::unique_ptr<TSslCertTools> FPrivateKey;
    std::unique_ptr<TX509Base> FVerifyPKey;
    std::unique_ptr<TIcsSymCrypto> FSymCrypto;
    String FIniFileName;
    bool FInitialized = false;
    bool FPkeyFromFile = false;
    std::vector<String> FJArrayItems;

    bool LoadPKeyFile(const String &FileName);
    void ClearPrivateKey();
    void GetCiphers();
    void ReportCipherInfo();
    void RsaEncryptDecrypt(TX509Base *PubKey);
    void SaveSettings();

public:
    __fastcall TJsonDemoForm(TComponent *Owner);
    __fastcall ~TJsonDemoForm();
    void AddLog(const String &S);
};

extern PACKAGE TJsonDemoForm *JsonDemoForm;

#endif
