diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2013-07-13 12:04:40 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-14 03:20:25 +0200 |
commit | cc741597021dd5e9c7ca2caffaf8a15181f68e89 (patch) | |
tree | 5269f5485422717baedfc651af5decbe5a8b5875 /src/corelib/tools/qbytearray.h | |
parent | 3154e1ccaabfbdb42aa48cbb5805b23442cdc33e (diff) |
Base64: Implement the "base64url" encoding and the stripping of '='
The "base64url" encoding is defined in RFC 4648, which is the newest
version of Base64. There are also a few situations where the ending
'=' is not desired.
Change-Id: I9bb9fa55817b57d125189e4e795d6fde97caea6d
Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 85d1f0ab90..ae8166db81 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -173,6 +173,15 @@ private: typedef QTypedArrayData<char> Data; public: + enum Base64Option { + Base64Encoding = 0, + Base64UrlEncoding = 1, + + KeepTrailingEquals = 0, + OmitTrailingEquals = 2 + }; + Q_DECLARE_FLAGS(Base64Options, Base64Option) + inline QByteArray(); QByteArray(const char *, int size = -1); QByteArray(int size, char c); @@ -317,7 +326,8 @@ public: qulonglong toULongLong(bool *ok = 0, int base = 10) const; float toFloat(bool *ok = 0) const; double toDouble(bool *ok = 0) const; - QByteArray toBase64() const; + QByteArray toBase64(Base64Options options) const; + QByteArray toBase64() const; // ### Qt6 merge with previous QByteArray toHex() const; QByteArray toPercentEncoding(const QByteArray &exclude = QByteArray(), const QByteArray &include = QByteArray(), @@ -339,7 +349,8 @@ public: static QByteArray number(qulonglong, int base = 10); static QByteArray number(double, char f = 'g', int prec = 6); static QByteArray fromRawData(const char *, int size); - static QByteArray fromBase64(const QByteArray &base64); + static QByteArray fromBase64(const QByteArray &base64, Base64Options options); + static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous static QByteArray fromHex(const QByteArray &hexEncoded); static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); @@ -392,6 +403,8 @@ public: inline DataPtr &data_ptr() { return d; } }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QByteArray::Base64Options) + inline QByteArray::QByteArray(): d(Data::sharedNull()) { } inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); } inline int QByteArray::size() const |