The class IBase64Streambuf is a class template, using a FBB::CryptType template non-type parameter. Objects of the class FBB::IBase64Streambuf<FBB::ENCRYPT> base64 encode the information they receive, objects of the class FBB::IBase64Streambuf<FBB::DECRYPT> base64 decode the information they receive. See also section ENUMERATION below.
Overloaded move and/or copy assignment operators are not available.
IBase64Streambuf objects either base64 encode or decode information. IBase64Streambuf objects of the class FBB::IBase64Streambuf<FBB::ENCRYPT> base64 encode the data they receive, IBase64Streambuf objects of the class FBB::IBase64Streambuf<FBB::DECRYPT> base64 decode the data they receive.
The values ENCRYPT and DECRYPT are defined in the enum CryptType, which is defined in the FBB namespace.
- IBase64Streambuf<ENCRYPT> objects perform base64 encoding;
- IBase64Streambuf<DECRYPT> objects perform base64 decoding;
- IBase64Streambuf<CryptType> objects obtain the bytes to encode or
decode from std::istream ∈
- The IFilterStreambuf base class is initialized with a buffer of
size bufSize, using a lower bound of 100.
The constructor uses a configurable buffer size for reading. Characters that were read into the buffer but are not part of the actual base64 encoded data are unavailable after completing the base64 decrypting. If information beyond the base64 input block should remain available, then specify a buffer size of 1.
Copy- and move constructors are not available.
The example shows the construction of IBase64Streambuf<ENCRYPT> objects encode which are used to initialize a std::istream object. The information read from this istream is base64 encoded.
IBase64Streambuf<DECRYPT> objects (decode reads base64 encoded information from std::istream objects and decodes it again).
The std::istream din object is initialized with the IBase64Streambuf<DECRYPT> object, and its contents is sent to std::cout. The information that is presented at std::cin and that appears at std::cout should be identical.
#include <iostream> #include <istream> #include <bobcat/ibase64streambuf> using namespace std; using namespace FBB; int main(int argc, char **argv) { switch (argv[1][0]) { case 'e': { IBase64Streambuf<ENCRYPT> encode(cin); istream ein(&encode); cout << ein.rdbuf(); } break; case 'd': { IBase64Streambuf<DECRYPT> decode(cin); istream din(&decode); cout << din.rdbuf(); } break; case 'b': { IBase64Streambuf<ENCRYPT> encode(cin); istream ein(&encode); IBase64Streambuf<DECRYPT> decode(ein); istream din(&decode); cout << din.rdbuf(); } break; default: cout << "Usage: " << argv[0] << " [edb] < infile > outfile\n" "to base64 -e-ncode, -d-ecode or -b-oth\n"; break; } }