1//
2// Base64Decoder.h
3//
4// Library: Foundation
5// Package: Streams
6// Module: Base64
7//
8// Definition of class Base64Decoder.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Base64Decoder_INCLUDED
18#define Foundation_Base64Decoder_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/UnbufferedStreamBuf.h"
23#include <istream>
24
25
26namespace Poco {
27
28
29class Foundation_API Base64DecoderBuf: public UnbufferedStreamBuf
30 /// This streambuf base64-decodes all data read
31 /// from the istream connected to it.
32 ///
33 /// Note: For performance reasons, the characters
34 /// are read directly from the given istream's
35 /// underlying streambuf, so the state
36 /// of the istream will not reflect that of
37 /// its streambuf.
38{
39public:
40 Base64DecoderBuf(std::istream& istr, int options = 0);
41 ~Base64DecoderBuf();
42
43private:
44 int readFromDevice();
45 int readOne();
46
47 int _options;
48 unsigned char _group[3];
49 int _groupLength;
50 int _groupIndex;
51 std::streambuf& _buf;
52 const unsigned char* _pInEncoding;
53
54 static unsigned char IN_ENCODING[256];
55 static bool IN_ENCODING_INIT;
56 static unsigned char IN_ENCODING_URL[256];
57 static bool IN_ENCODING_URL_INIT;
58
59private:
60 Base64DecoderBuf(const Base64DecoderBuf&);
61 Base64DecoderBuf& operator = (const Base64DecoderBuf&);
62};
63
64
65class Foundation_API Base64DecoderIOS: public virtual std::ios
66 /// The base class for Base64Decoder.
67 ///
68 /// This class is needed to ensure the correct initialization
69 /// order of the stream buffer and base classes.
70{
71public:
72 Base64DecoderIOS(std::istream& istr, int options = 0);
73 ~Base64DecoderIOS();
74 Base64DecoderBuf* rdbuf();
75
76protected:
77 Base64DecoderBuf _buf;
78
79private:
80 Base64DecoderIOS(const Base64DecoderIOS&);
81 Base64DecoderIOS& operator = (const Base64DecoderIOS&);
82};
83
84
85class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream
86 /// This istream base64-decodes all data
87 /// read from the istream connected to it.
88 ///
89 /// The class implements RFC 4648 - https://tools.ietf.org/html/rfc4648
90 ///
91 /// Note: For performance reasons, the characters
92 /// are read directly from the given istream's
93 /// underlying streambuf, so the state
94 /// of the istream will not reflect that of
95 /// its streambuf.
96{
97public:
98 Base64Decoder(std::istream& istr, int options = 0);
99 ~Base64Decoder();
100
101private:
102 Base64Decoder(const Base64Decoder&);
103 Base64Decoder& operator = (const Base64Decoder&);
104};
105
106
107} // namespace Poco
108
109
110#endif // Foundation_Base64Decoder_INCLUDED
111