E-MailRelay

gbase64.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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 = std::string() ) ;
43 ///< Encodes the given string, optionally inserting line-breaks
44 ///< to limit the line length.
45
46 static std::string decode( const std::string & , bool throw_on_invalid = false , bool strict = true ) ;
47 ///< Decodes the given string. Either throws an exception if
48 ///< not a valid() encoding, or returns the empty string.
49
50 static bool valid( const std::string & , bool strict = true ) ;
51 ///< Returns true if the string is a valid base64 encoding,
52 ///< possibly allowing for embedded newlines, carriage returns,
53 ///< and space characters. Strict checking permits one or
54 ///< two pad characters at the end to make a multiple of
55 ///< four characters in total, but no newlines, carriage
56 ///< returns or other odd characters. Empty strings
57 ///< are valid; single character strings are not.
58
59 public:
60 Base64() = delete ;
61} ;
62
63#endif
G::Base64
A base64 codec class.
Definition: gbase64.h:38
G::Base64::decode
static std::string decode(const std::string &, bool throw_on_invalid=false, bool strict=true)
Decodes the given string.
Definition: gbase64.cpp:89
G::Base64::encode
static std::string encode(const std::string &s, const std::string &line_break=std::string())
Encodes the given string, optionally inserting line-breaks to limit the line length.
Definition: gbase64.cpp:84
G::Base64::valid
static bool valid(const std::string &, bool strict=true)
Returns true if the string is a valid base64 encoding, possibly allowing for embedded newlines,...
Definition: gbase64.cpp:94
gexception.h
G
Low-level classes.
Definition: galign.h:28