mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-24 17:30:44 +02:00
Base64Encoder/Decoder: added support for 'base64url' encoding
Conflicts: Foundation/src/Base64Decoder.cpp Foundation/src/Base64Encoder.cpp
This commit is contained in:
@@ -37,21 +37,25 @@ class Foundation_API Base64DecoderBuf: public UnbufferedStreamBuf
|
||||
/// its streambuf.
|
||||
{
|
||||
public:
|
||||
Base64DecoderBuf(std::istream& istr);
|
||||
Base64DecoderBuf(std::istream& istr, int options = 0);
|
||||
~Base64DecoderBuf();
|
||||
|
||||
|
||||
private:
|
||||
int readFromDevice();
|
||||
int readOne();
|
||||
|
||||
int _options;
|
||||
unsigned char _group[3];
|
||||
int _groupLength;
|
||||
int _groupIndex;
|
||||
std::streambuf& _buf;
|
||||
|
||||
const unsigned char* _pInEncoding;
|
||||
|
||||
static unsigned char IN_ENCODING[256];
|
||||
static bool IN_ENCODING_INIT;
|
||||
|
||||
static unsigned char IN_ENCODING_URL[256];
|
||||
static bool IN_ENCODING_URL_INIT;
|
||||
|
||||
private:
|
||||
Base64DecoderBuf(const Base64DecoderBuf&);
|
||||
Base64DecoderBuf& operator = (const Base64DecoderBuf&);
|
||||
@@ -65,13 +69,13 @@ class Foundation_API Base64DecoderIOS: public virtual std::ios
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
Base64DecoderIOS(std::istream& istr);
|
||||
Base64DecoderIOS(std::istream& istr, int options = 0);
|
||||
~Base64DecoderIOS();
|
||||
Base64DecoderBuf* rdbuf();
|
||||
|
||||
protected:
|
||||
Base64DecoderBuf _buf;
|
||||
|
||||
|
||||
private:
|
||||
Base64DecoderIOS(const Base64DecoderIOS&);
|
||||
Base64DecoderIOS& operator = (const Base64DecoderIOS&);
|
||||
@@ -89,7 +93,7 @@ class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream
|
||||
/// its streambuf.
|
||||
{
|
||||
public:
|
||||
Base64Decoder(std::istream& istr);
|
||||
Base64Decoder(std::istream& istr, int options = 0);
|
||||
~Base64Decoder();
|
||||
|
||||
private:
|
||||
|
||||
@@ -26,6 +26,19 @@
|
||||
namespace Poco {
|
||||
|
||||
|
||||
enum Base64EncodingOptions
|
||||
{
|
||||
BASE64_URL_ENCODING = 0x01,
|
||||
/// Use the URL and filename-safe alphabet,
|
||||
/// replacing '+' with '-' and '/' with '_'.
|
||||
///
|
||||
/// Will also set line length to unlimited.
|
||||
|
||||
BASE64_NO_PADDING = 0x02
|
||||
/// Do not append padding characters ('=') at end.
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API Base64EncoderBuf: public UnbufferedStreamBuf
|
||||
/// This streambuf base64-encodes all data written
|
||||
/// to it and forwards it to a connected
|
||||
@@ -37,9 +50,9 @@ class Foundation_API Base64EncoderBuf: public UnbufferedStreamBuf
|
||||
/// not updated to match the buffer's state.
|
||||
{
|
||||
public:
|
||||
Base64EncoderBuf(std::ostream& ostr);
|
||||
Base64EncoderBuf(std::ostream& ostr, int options = 0);
|
||||
~Base64EncoderBuf();
|
||||
|
||||
|
||||
int close();
|
||||
/// Closes the stream buffer.
|
||||
|
||||
@@ -53,18 +66,21 @@ public:
|
||||
|
||||
int getLineLength() const;
|
||||
/// Returns the currently set line length.
|
||||
|
||||
|
||||
private:
|
||||
int writeToDevice(char c);
|
||||
|
||||
int _options;
|
||||
unsigned char _group[3];
|
||||
int _groupLength;
|
||||
int _pos;
|
||||
int _lineLength;
|
||||
std::streambuf& _buf;
|
||||
|
||||
const unsigned char* _pOutEncoding;
|
||||
|
||||
static const unsigned char OUT_ENCODING[64];
|
||||
|
||||
static const unsigned char OUT_ENCODING_URL[64];
|
||||
|
||||
friend class Base64DecoderBuf;
|
||||
|
||||
Base64EncoderBuf(const Base64EncoderBuf&);
|
||||
@@ -79,7 +95,7 @@ class Foundation_API Base64EncoderIOS: public virtual std::ios
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
Base64EncoderIOS(std::ostream& ostr);
|
||||
Base64EncoderIOS(std::ostream& ostr, int options = 0);
|
||||
~Base64EncoderIOS();
|
||||
int close();
|
||||
Base64EncoderBuf* rdbuf();
|
||||
@@ -107,7 +123,7 @@ class Foundation_API Base64Encoder: public Base64EncoderIOS, public std::ostream
|
||||
/// not updated to match the buffer's state.
|
||||
{
|
||||
public:
|
||||
Base64Encoder(std::ostream& ostr);
|
||||
Base64Encoder(std::ostream& ostr, int options = 0);
|
||||
~Base64Encoder();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user