/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CBase64.cpp  -  description
                             -------------------
    begin                : July 19 2003
    copyright            : (C) 2003 by Alexey Parshin
    email                : alexeyp@gmail.com
    based on the code    : Mikko Lahteenmaki <Laza@Flashmail.com>
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This 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 Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/
#ifndef __CBASE64_H__
#define __CBASE64_H__

#include <sptk3/CException.h>

/// @addtogroup utility Utility Classes
/// @{

#include <string>
#include <sptk3/sptk.h>
#include <sptk3/CBuffer.h>

/// @brief Base64 encoding/decoding.
///
/// This class is used for encoding and decoding the parts of mail messages. 
/// All the methods of this class are static.
class CBase64 {
public:
   /// @brief Data encoding.
   /// Encodes data (base64) in given buffer bufSource to destination buffer bufDest.
   /// @param bufDest CBuffer Destination buffer
   /// @param bufSource CBuffer Source buffer
   static void encode(CBuffer& bufDest, const CBuffer& bufSource);

   /// @brief Data encoding.
   /// Encodes data (base64) in given buffer bufSource and returns result in std::string.
   /// @param strDest std::string Destination string
   /// @param bufSource CBuffer& Source buffer  
   static void encode(std::string& strDest, const CBuffer& bufSource);

   /// @brief Data decoding. 
   /// Decodes base64 encoded buffer bufSource into buffer bufDest. 
   /// Throws CException in case of error
   /// @param bufDest CBuffer destination buffer
   /// @param bufSource CBuffer source buffer that holds base64 decoded data
   /// @returns length of returned buffer
   static int decode(CBuffer &bufDest, const CBuffer &bufSource) throw(CException);

   /// @brief Data decoding. 
   /// Decodes base64 encoded string strSource into buffer bufDest.
   /// Throws CException in case of error
   /// @param bufDest CBuffer, destination buffer
   /// @param strSource const std::string &, source string that holds base64 decoded data
   /// @returns length of the returned string
   static int decode(CBuffer &bufDest, const std::string &strSource) throw(CException);
};

/// @}

#endif
