/*
*  Naamari - an AES/SHA-based manual file crypto-synchronizer for cloud transfers
*  Copyright (c) 2015-2017 Sunkware
*  Key FP = 6B6D C8E9 3438 6E9C 3D97  56E5 2CE9 A476 99EF 28F6
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*  See the GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*  ----------------------------------------------------------------
*  WWW:       sunkware.org
*  E-mail:    sunkware@gmail.com
*  ----------------------------------------------------------------
*/

#ifndef TRANSLATOR_H
#define TRANSLATOR_H

#include       "defines.h"
#include       "errors.h"

#include       "contextglob.h"
#include       "stateglob.h"
#include       "hasher.h"
#include       "cipher.h"
#include       "buffer.h"

namespace cryptrav
{


class Translator
{
 private:
  ContextGlob* contextP;
  StateGlob*   stateP;

  int          translateTwoQwords(quint8* salt, qint64* halfFirst, qint64* halfSecond, bool toEncrypt);

  int          decryptPass(QFile* sourceP, QFile* targetP, quint8* salt, bool isWriteEnabled);
// if isWriteEnabled == false, don't touch target (we (re)write it only if hash check is passed)

 public:
  Translator(ContextGlob* pContext, StateGlob* pState);


  int          genRandomen(QString filePath, quint8* randomen);

  int          genSalt(quint8* randomen, quint8* salt);

  int          makeCryptomen(quint8* randomen, quint8* cryptomen);
  QString      makeCryptomenStr(quint8* randomen);

  int          makeBlockKey(quint8* salt, qint64 iBlock, quint8* blockKey);


  int          encryptTwoQwords(quint8* salt, qint64* halfFirst, qint64* halfSecond);
  int          decryptTwoQwords(quint8* salt, qint64* halfFirst, qint64* halfSecond);


  int          encrypt(QFile* sourceP, QFile* targetP, quint8* salt);
  int          decrypt(QFile* sourceP, QFile* targetP, quint8* salt, bool isOnePass);

  int          test(QFile* sourceP, quint8* salt);


  ~Translator();

};


} // namespace "cryptrav"

#endif // TRANSLATOR_H
