E-MailRelay
gbase64.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // ===
17 ///
18 /// \file gbase64.h
19 ///
20 
21 #ifndef G_BASE64_H
22 #define G_BASE64_H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27 
28 namespace G
29 {
30  class Base64 ;
31 }
32 
33 /// \class G::Base64
34 /// A base64 codec class.
35 /// \see RFC-1341 section 5.2
36 ///
37 class G::Base64
38 {
39 public:
40  G_EXCEPTION( Error , "base64 encoding error" ) ;
41 
42  static std::string encode( const std::string & s , const std::string & line_break ) ;
43  ///< Encodes the given string.
44 
45  static std::string encode( const std::string & ) ;
46  ///< Encodes the given string. Uses carriage-return-line-feed
47  ///< as the line-break string.
48 
49  static std::string decode( const std::string & , bool strict = false ) ;
50  ///< Decodes the given string. Throws an exception
51  ///< if strict and not a valid encoding.
52 
53  static bool valid( const std::string & ) ;
54  ///< Returns true if the string can be decoded without
55  ///< any strict errors. An empty string is valid.
56 
57 private:
58  Base64() ;
59 } ;
60 
61 #endif
62 
static bool valid(const std::string &)
Returns true if the string can be decoded without any strict errors.
Definition: gbase64.cpp:66
static std::string decode(const std::string &, bool strict=false)
Decodes the given string.
Definition: gbase64.cpp:57
Low-level classes.
Definition: garg.h:29
A base64 codec class.
Definition: gbase64.h:37
static std::string encode(const std::string &s, const std::string &line_break)
Encodes the given string.
Definition: gbase64.cpp:52