1//
2// Base32Decoder.h
3//
4// Library: Foundation
5// Package: Streams
6// Module: Base32
7//
8// Definition of class Base32Decoder.
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_Base32Decoder_INCLUDED
18#define Foundation_Base32Decoder_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 Base32DecoderBuf: public UnbufferedStreamBuf
30 /// This streambuf base32-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 Base32DecoderBuf(std::istream& istr);
41 ~Base32DecoderBuf();
42
43private:
44 int readFromDevice();
45 int readOne();
46
47 unsigned char _group[8];
48 int _groupLength;
49 int _groupIndex;
50 std::streambuf& _buf;
51
52 static unsigned char IN_ENCODING[256];
53 static bool IN_ENCODING_INIT;
54
55private:
56 Base32DecoderBuf(const Base32DecoderBuf&);
57 Base32DecoderBuf& operator = (const Base32DecoderBuf&);
58};
59
60
61class Foundation_API Base32DecoderIOS: public virtual std::ios
62 /// The base class for Base32Decoder.
63 ///
64 /// This class is needed to ensure the correct initialization
65 /// order of the stream buffer and base classes.
66{
67public:
68 Base32DecoderIOS(std::istream& istr);
69 ~Base32DecoderIOS();
70 Base32DecoderBuf* rdbuf();
71
72protected:
73 Base32DecoderBuf _buf;
74
75private:
76 Base32DecoderIOS(const Base32DecoderIOS&);
77 Base32DecoderIOS& operator = (const Base32DecoderIOS&);
78};
79
80
81class Foundation_API Base32Decoder: public Base32DecoderIOS, public std::istream
82 /// This istream base32-decodes all data
83 /// read from the istream connected to it.
84 ///
85 /// The class implements RFC 4648 - https://tools.ietf.org/html/rfc4648
86 ///
87 /// Note: For performance reasons, the characters
88 /// are read directly from the given istream's
89 /// underlying streambuf, so the state
90 /// of the istream will not reflect that of
91 /// its streambuf.
92{
93public:
94 Base32Decoder(std::istream& istr);
95 ~Base32Decoder();
96
97private:
98 Base32Decoder(const Base32Decoder&);
99 Base32Decoder& operator = (const Base32Decoder&);
100};
101
102
103} // namespace Poco
104
105
106#endif // Foundation_Base32Decoder_INCLUDED
107