/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2010 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstd
 * Version: 1.07
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstd library
 * 
 * mzstd library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstd library 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#ifndef __MZSTD_BASE64_H__
#define __MZSTD_BASE64_H__

#include "mzstdCommon.h"
#include "mzObject.h"
#include "mzString.h"

/*
Tabela znaków w kodowaniu base64:

Value Encoding  Value Encoding  Value Encoding  Value Encoding
   0 A            17 R            34 i            51 z
   1 B            18 S            35 j            52 0
   2 C            19 T            36 k            53 1
   3 D            20 U            37 l            54 2
   4 E            21 V            38 m            55 3
   5 F            22 W            39 n            56 4
   6 G            23 X            40 o            57 5
   7 H            24 Y            41 p            58 6
   8 I            25 Z            42 q            59 7
   9 J            26 a            43 r            60 8
  10 K            27 b            44 s            61 9
  11 L            28 c            45 t            62 +
  12 M            29 d            46 u            63 /
  13 N            30 e            47 v
  14 O            31 f            48 w         (pad) =
  15 P            32 g            49 x
  16 Q            33 h            50 y
*/

// Encoding and decoding Base64 code
class DECLSPEC_MZSTD CBase64 : public CObject {
public:
	// 63rd CHAR used for Base64 code
	WCHAR CHAR_63;
	// 64th CHAR used for Base64 code
	WCHAR CHAR_64;
	// Char used for padding
	WCHAR CHAR_PAD;

    WINAPI CBase64();
    virtual WINAPI ~CBase64();

	// Encodes binary data to Base64 code. Returns size of encoded data.
	LONG WINAPI encode(const UCHAR* inData, LONG dataLength, CString& outCode);
	// Decodes Base64 code to binary data. Returns size of decoded data.
	LONG WINAPI decode(const CString& inCode, UCHAR* outData);
	// Returns maximum size of decoded data based on size of Base64 code.
	LONG WINAPI getDataLength(LONG codeLength);
	// Returns maximum length of Base64 code based on size of uncoded data.
	LONG WINAPI getCodeLength(LONG dataLength);
    // koduje plik do zmiennej
    LONG WINAPI encodeFileToVar(CString fname, CString& outCode);
    // koduje plik w miejscu
    LONG WINAPI encodeFile(CString fname, CString outputFName = L"");
    // dekoduje plik do zmiennej
    LONG WINAPI decodeFileToVar(CString fname, UCHAR* outData);
    // dekoduje plik w miejscu
    LONG WINAPI decodeFile(CString fname, CString outputFName = L"");
    
protected:
    // inicjalizacja
    VOID WINAPI _commonInit();
};

#endif
