gbase64.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20 
21 #ifndef G_BASE64_H
22 #define G_BASE64_H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27 
29 namespace G
30 {
31  class Base64 ;
32 }
33 
38 class G::Base64
39 {
40 public:
41  G_EXCEPTION( Error , "base64 encoding error" ) ;
42 
43  static std::string encode( const std::string & s , const std::string & line_break ) ;
45 
46  static std::string encode( const std::string & s ) ;
49 
50  static std::string decode( const std::string & ) ;
53 
54  static bool valid( const std::string & ) ;
56 
57 private:
58  Base64() ;
59  static inline g_uint32_t numeric( char c ) ;
60  static inline void accumulate_8( g_uint32_t & n , std::string::const_iterator & ,
61  std::string::const_iterator , int & ) ;
62  static inline size_t hi_6( g_uint32_t n ) ;
63  static inline void generate_6( g_uint32_t & n , int & i , std::string & result ) ;
64  static inline char to_char( g_uint32_t n ) ;
65  static inline size_t index( char c , bool & error ) ;
66  static inline size_t accumulate_6( g_uint32_t & n , char c_in , int & , bool & error ) ;
67  static inline g_uint32_t hi_8( g_uint32_t n ) ;
68  static inline void generate_8( g_uint32_t & n , int & i , std::string & result ) ;
69  static std::string decode( const std::string & s , bool & error ) ;
70 } ;
71 
72 #endif
73 
static bool valid(const std::string &)
Returns true if the string can be decoded.
Definition: gbase64.cpp:166
Low-level classes.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
static std::string decode(const std::string &)
Decodes the given string.
Definition: gbase64.cpp:131
A base64 codec class.
Definition: gbase64.h:38
static std::string encode(const std::string &s, const std::string &line_break)
Encodes the given string.
Definition: gbase64.cpp:68