PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PBase64 Class Reference

This class is used to encode/decode data using the MIME standard base64 encoding mechanism as defined in RFC1521. More...

#include <cypher.h>

Inheritance diagram for PBase64:
Collaboration diagram for PBase64:

Public Member Functions

 PBase64 ()
 Construct a base 64 encoder/decoder and initialise both encode and decode members as in StartEncoding() and StartDecoding(). More...
 
void StartEncoding (bool useCRLFs=true, PINDEX width=76)
 
void StartEncoding (const char *endOfLine, PINDEX width=76)
 
void ProcessEncoding (const PString &str)
 
void ProcessEncoding (const char *cstr)
 
void ProcessEncoding (const PBYTEArray &data)
 
void ProcessEncoding (const void *dataBlock, PINDEX length)
 
PString GetEncodedString ()
 Get the partial Base64 string for the data encoded so far. More...
 
PString CompleteEncoding ()
 Complete the base 64 encoding and return the remainder of the encoded Base64 string. More...
 
void StartDecoding ()
 
PBoolean ProcessDecoding (const PString &str)
 Incorporate the specified data into the base 64 decoding. More...
 
PBoolean ProcessDecoding (const char *cstr)
 
PBoolean GetDecodedData (void *dataBlock, PINDEX length)
 Get the data decoded so far from the Base64 strings processed. More...
 
PBYTEArray GetDecodedData ()
 
PBoolean IsDecodeOK ()
 Return a flag to indicate that the input was decoded without any extraneous or illegal characters in it that were ignored. More...
 
- Public Member Functions inherited from PObject
unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
void SetTraceContextIdentifier (unsigned id)
 
void GetTraceContextIdentifier (PObject &obj)
 
void GetTraceContextIdentifier (PObject *obj)
 
void SetTraceContextIdentifier (const PObject &obj)
 
void SetTraceContextIdentifier (const PObject *obj)
 
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
__inline const PObjectPTraceObjectInstance () const
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Static Public Member Functions

static PString Encode (const PString &str, const char *endOfLine="\n", PINDEX width=76)
 
static PString Encode (const char *cstr, const char *endOfLine="\n", PINDEX width=76)
 
static PString Encode (const PBYTEArray &data, const char *endOfLine="\n", PINDEX width=76)
 
static PString Encode (const void *dataBlock, PINDEX length, const char *endOfLine="\n", PINDEX width=76)
 
static PString Decode (const PString &str)
 Convert a printable text string to binary data using the Internet MIME standard base 64 content transfer encoding. More...
 
static PBoolean Decode (const PString &str, PBYTEArray &data)
 
static PBoolean Decode (const PString &str, void *dataBlock, PINDEX length)
 
- Static Public Member Functions inherited from PObject
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 

Additional Inherited Members

- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 
- Friends inherited from PObject

Detailed Description

This class is used to encode/decode data using the MIME standard base64 encoding mechanism as defined in RFC1521.

To encode a large block of data use the following seqeunce:


      PBase64 base;
      base.StartEncoding();
      while (Read(dataChunk)) {
        base.ProcessEncoding(dataChunk);
        out << base.GetEncodedString();
      }
      out << base.CompleteEncoding();
if smaller blocks that fit easily in memory are to be encoded the
<code>Encode()</code> functions can be used to everything in one go.

To decode a large block of data use the following sequence:
      PBase64 base;
      base.StartDecoding();
      while (Read(str) && ProcessDecoding(str))
        Write(base.GetDecodedData());
      Write(base.GetDecodedData());
if smaller blocks that fit easily in memory are to be decoded the
<code>Decode()</code> functions can be used to everything in one go.

Constructor & Destructor Documentation

PBase64::PBase64 ( )

Construct a base 64 encoder/decoder and initialise both encode and decode members as in StartEncoding() and StartDecoding().

Member Function Documentation

PString PBase64::CompleteEncoding ( )

Complete the base 64 encoding and return the remainder of the encoded Base64 string.

Returns
Base64 encoded string for the processed data.
static PString PBase64::Decode ( const PString str)
static

Convert a printable text string to binary data using the Internet MIME standard base 64 content transfer encoding.

The base64 string is checked and true returned if all perfectly correct. If false is returned then the string had extraneous or illegal characters in it that were ignored. This does not mean that the data is not valid, only that it is suspect.

Returns
Base 64 string decoded from input string.
static PBoolean PBase64::Decode ( const PString str,
PBYTEArray data 
)
static
static PBoolean PBase64::Decode ( const PString str,
void *  dataBlock,
PINDEX  length 
)
static
static PString PBase64::Encode ( const PString str,
const char *  endOfLine = "\n",
PINDEX  width = 76 
)
static
Parameters
strString to be encoded to Base64
endOfLineString to use for end of line.
widthLine widths if endOfLine non empty

Referenced by PMessageDigest::Result::AsBase64().

static PString PBase64::Encode ( const char *  cstr,
const char *  endOfLine = "\n",
PINDEX  width = 76 
)
static
Parameters
cstrC String to be encoded to Base64
endOfLineString to use for end of line.
widthLine widths if endOfLine non empty
static PString PBase64::Encode ( const PBYTEArray data,
const char *  endOfLine = "\n",
PINDEX  width = 76 
)
static
Parameters
dataData block to be encoded to Base64
endOfLineString to use for end of line.
widthLine widths if endOfLine non empty
static PString PBase64::Encode ( const void *  dataBlock,
PINDEX  length,
const char *  endOfLine = "\n",
PINDEX  width = 76 
)
static
Parameters
dataBlockPointer to data to be encoded to Base64
lengthLength of the data block.
endOfLineString to use for end of line.
widthLine widths if endOfLine non empty
PBoolean PBase64::GetDecodedData ( void *  dataBlock,
PINDEX  length 
)

Get the data decoded so far from the Base64 strings processed.

Returns
Decoded data for the processed Base64 string.
PBYTEArray PBase64::GetDecodedData ( )
PString PBase64::GetEncodedString ( )

Get the partial Base64 string for the data encoded so far.

Returns
Base64 encoded string for the processed data.
PBoolean PBase64::IsDecodeOK ( )
inline

Return a flag to indicate that the input was decoded without any extraneous or illegal characters in it that were ignored.

This does not mean that the data is not valid, only that it is suspect.

Returns
Decoded data for the processed Base64 string.
PBoolean PBase64::ProcessDecoding ( const PString str)

Incorporate the specified data into the base 64 decoding.

Returns
true if block was last in the Base64 encoded string.
PBoolean PBase64::ProcessDecoding ( const char *  cstr)
void PBase64::ProcessEncoding ( const PString str)
void PBase64::ProcessEncoding ( const char *  cstr)
void PBase64::ProcessEncoding ( const PBYTEArray data)
void PBase64::ProcessEncoding ( const void *  dataBlock,
PINDEX  length 
)
void PBase64::StartDecoding ( )
void PBase64::StartEncoding ( bool  useCRLFs = true,
PINDEX  width = 76 
)
Parameters
useCRLFsUse CR, LF pairs in end of line characters.
widthLine widths if usCRLF true
void PBase64::StartEncoding ( const char *  endOfLine,
PINDEX  width = 76 
)
Parameters
endOfLineString to use for end of line.
widthLine widths if endOfLine non empty

The documentation for this class was generated from the following file: