mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-17 07:13:27 +02:00
Base32 Encoder/Decoder
Base 32 Encoder/Decoder
This commit is contained in:
parent
12a7813e01
commit
9b89394b5b
@ -553,6 +553,14 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Decoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base32Encoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Decoder.cpp"
|
||||
>
|
||||
@ -733,6 +741,14 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Decoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Encoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base64Decoder.h"
|
||||
>
|
||||
|
@ -290,6 +290,8 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Ascii.cpp" />
|
||||
<ClCompile Include="src\AtomicCounter.cpp" />
|
||||
<ClCompile Include="src\Base32Decoder.cpp" />
|
||||
<ClCompile Include="src\Base32Encoder.cpp" />
|
||||
<ClCompile Include="src\Bugcheck.cpp" />
|
||||
<ClCompile Include="src\ByteOrder.cpp" />
|
||||
<ClCompile Include="src\Checksum.cpp" />
|
||||
@ -977,6 +979,8 @@
|
||||
<ClInclude Include="include\Poco\AtomicCounter.h" />
|
||||
<ClInclude Include="include\Poco\AutoPtr.h" />
|
||||
<ClInclude Include="include\Poco\AutoReleasePool.h" />
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h" />
|
||||
<ClInclude Include="include\Poco\Buffer.h" />
|
||||
<ClInclude Include="include\Poco\Bugcheck.h" />
|
||||
<ClInclude Include="include\Poco\ByteOrder.h" />
|
||||
|
@ -888,6 +888,12 @@
|
||||
<ClCompile Include="src\Error.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Encoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\Poco\Any.h">
|
||||
@ -1838,6 +1844,12 @@
|
||||
<ClInclude Include="include\Poco\Error.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="src\pocomsg.rc">
|
||||
|
@ -390,6 +390,8 @@
|
||||
<ClCompile Include="src\Var.cpp" />
|
||||
<ClCompile Include="src\VarHolder.cpp" />
|
||||
<ClCompile Include="src\Void.cpp" />
|
||||
<ClCompile Include="src\Base32Decoder.cpp" />
|
||||
<ClCompile Include="src\Base32Encoder.cpp" />
|
||||
<ClCompile Include="src\Base64Decoder.cpp" />
|
||||
<ClCompile Include="src\Base64Encoder.cpp" />
|
||||
<ClCompile Include="src\BinaryReader.cpp" />
|
||||
@ -1041,6 +1043,8 @@
|
||||
<ClInclude Include="include\Poco\UTFString.h" />
|
||||
<ClInclude Include="include\Poco\Version.h" />
|
||||
<ClInclude Include="include\Poco\Void.h" />
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h" />
|
||||
<ClInclude Include="include\Poco\Base64Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base64Encoder.h" />
|
||||
<ClInclude Include="include\Poco\BinaryReader.h" />
|
||||
|
@ -270,6 +270,12 @@
|
||||
<ClCompile Include="src\Void.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Encoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base64Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -1046,6 +1052,12 @@
|
||||
<ClInclude Include="include\Poco\Void.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base64Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -951,6 +951,12 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\Base32Decoder.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base32Encoder.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Decoder.cpp">
|
||||
</File>
|
||||
@ -1084,6 +1090,12 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Decoder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Encoder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base64Decoder.h">
|
||||
</File>
|
||||
|
@ -1267,6 +1267,14 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Decoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base32Encoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Decoder.cpp"
|
||||
>
|
||||
@ -1447,6 +1455,14 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Decoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Encoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base64Decoder.h"
|
||||
>
|
||||
|
@ -1264,6 +1264,14 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Decoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base32Encoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Decoder.cpp"
|
||||
>
|
||||
@ -1444,6 +1452,14 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Decoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Encoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base64Decoder.h"
|
||||
>
|
||||
|
@ -390,6 +390,8 @@
|
||||
<ClCompile Include="src\Var.cpp" />
|
||||
<ClCompile Include="src\VarHolder.cpp" />
|
||||
<ClCompile Include="src\Void.cpp" />
|
||||
<ClCompile Include="src\Base32Decoder.cpp" />
|
||||
<ClCompile Include="src\Base32Encoder.cpp" />
|
||||
<ClCompile Include="src\Base64Decoder.cpp" />
|
||||
<ClCompile Include="src\Base64Encoder.cpp" />
|
||||
<ClCompile Include="src\BinaryReader.cpp" />
|
||||
@ -1038,6 +1040,8 @@
|
||||
<ClInclude Include="include\Poco\UTF32Encoding.h" />
|
||||
<ClInclude Include="include\Poco\Version.h" />
|
||||
<ClInclude Include="include\Poco\Void.h" />
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h" />
|
||||
<ClInclude Include="include\Poco\Base64Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base64Encoder.h" />
|
||||
<ClInclude Include="include\Poco\BinaryReader.h" />
|
||||
|
@ -270,6 +270,12 @@
|
||||
<ClCompile Include="src\Void.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Encoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base64Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -1046,6 +1052,12 @@
|
||||
<ClInclude Include="include\Poco\Void.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base64Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -396,6 +396,8 @@
|
||||
<ClCompile Include="src\Var.cpp" />
|
||||
<ClCompile Include="src\VarHolder.cpp" />
|
||||
<ClCompile Include="src\Void.cpp" />
|
||||
<ClCompile Include="src\Base32Decoder.cpp" />
|
||||
<ClCompile Include="src\Base32Encoder.cpp" />
|
||||
<ClCompile Include="src\Base64Decoder.cpp" />
|
||||
<ClCompile Include="src\Base64Encoder.cpp" />
|
||||
<ClCompile Include="src\BinaryReader.cpp" />
|
||||
@ -1044,6 +1046,8 @@
|
||||
<ClInclude Include="include\Poco\UTF32Encoding.h" />
|
||||
<ClInclude Include="include\Poco\Version.h" />
|
||||
<ClInclude Include="include\Poco\Void.h" />
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h" />
|
||||
<ClInclude Include="include\Poco\Base64Decoder.h" />
|
||||
<ClInclude Include="include\Poco\Base64Encoder.h" />
|
||||
<ClInclude Include="include\Poco\BinaryReader.h" />
|
||||
|
@ -270,6 +270,12 @@
|
||||
<ClCompile Include="src\Void.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Encoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base64Decoder.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -1046,6 +1052,12 @@
|
||||
<ClInclude Include="include\Poco\Void.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base32Encoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="include\Poco\Base64Decoder.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -1266,6 +1266,14 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Decoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base32Encoder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Decoder.cpp"
|
||||
>
|
||||
@ -1442,6 +1450,14 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Decoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base32Encoder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Base64Decoder.h"
|
||||
>
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = ArchiveStrategy Ascii ASCIIEncoding AsyncChannel Base64Decoder Base64Encoder \
|
||||
objects = ArchiveStrategy Ascii ASCIIEncoding AsyncChannel \
|
||||
Base32Decoder Base32Encoder Base64Decoder Base64Encoder \
|
||||
BinaryReader BinaryWriter Bugcheck ByteOrder Channel Checksum Configurable ConsoleChannel \
|
||||
CountingStream DateTime LocalDateTime DateTimeFormat DateTimeFormatter DateTimeParser \
|
||||
Debugger DeflatingStream DigestEngine DigestStream DirectoryIterator DirectoryWatcher \
|
||||
|
126
Foundation/include/Poco/Base32Decoder.h
Normal file
126
Foundation/include/Poco/Base32Decoder.h
Normal file
@ -0,0 +1,126 @@
|
||||
//
|
||||
// Base32Decoder.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Base32Decoder.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: Base32
|
||||
//
|
||||
// Definition of class Base32Decoder.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Base32Decoder_INCLUDED
|
||||
#define Foundation_Base32Decoder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/UnbufferedStreamBuf.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Base32DecoderBuf: public UnbufferedStreamBuf
|
||||
/// This streambuf base32-decodes all data read
|
||||
/// from the istream connected to it.
|
||||
///
|
||||
/// Note: For performance reasons, the characters
|
||||
/// are read directly from the given istream's
|
||||
/// underlying streambuf, so the state
|
||||
/// of the istream will not reflect that of
|
||||
/// its streambuf.
|
||||
{
|
||||
public:
|
||||
Base32DecoderBuf(std::istream& istr);
|
||||
~Base32DecoderBuf();
|
||||
|
||||
private:
|
||||
int readFromDevice();
|
||||
int readOne();
|
||||
|
||||
unsigned char _group[8];
|
||||
int _groupLength;
|
||||
int _groupIndex;
|
||||
std::streambuf& _buf;
|
||||
|
||||
static unsigned char IN_ENCODING[256];
|
||||
static bool IN_ENCODING_INIT;
|
||||
|
||||
private:
|
||||
Base32DecoderBuf(const Base32DecoderBuf&);
|
||||
Base32DecoderBuf& operator = (const Base32DecoderBuf&);
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API Base32DecoderIOS: public virtual std::ios
|
||||
/// The base class for Base32Decoder.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
Base32DecoderIOS(std::istream& istr);
|
||||
~Base32DecoderIOS();
|
||||
Base32DecoderBuf* rdbuf();
|
||||
|
||||
protected:
|
||||
Base32DecoderBuf _buf;
|
||||
|
||||
private:
|
||||
Base32DecoderIOS(const Base32DecoderIOS&);
|
||||
Base32DecoderIOS& operator = (const Base32DecoderIOS&);
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API Base32Decoder: public Base32DecoderIOS, public std::istream
|
||||
/// This istream base32-decodes all data
|
||||
/// read from the istream connected to it.
|
||||
///
|
||||
/// Note: For performance reasons, the characters
|
||||
/// are read directly from the given istream's
|
||||
/// underlying streambuf, so the state
|
||||
/// of the istream will not reflect that of
|
||||
/// its streambuf.
|
||||
{
|
||||
public:
|
||||
Base32Decoder(std::istream& istr);
|
||||
~Base32Decoder();
|
||||
|
||||
private:
|
||||
Base32Decoder(const Base32Decoder&);
|
||||
Base32Decoder& operator = (const Base32Decoder&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Base32Decoder_INCLUDED
|
131
Foundation/include/Poco/Base32Encoder.h
Normal file
131
Foundation/include/Poco/Base32Encoder.h
Normal file
@ -0,0 +1,131 @@
|
||||
//
|
||||
// Base32Encoder.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/include/Poco/Base32Encoder.h#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: Base32
|
||||
//
|
||||
// Definition of class Base32Encoder.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Foundation_Base32Encoder_INCLUDED
|
||||
#define Foundation_Base32Encoder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "Poco/UnbufferedStreamBuf.h"
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
class Foundation_API Base32EncoderBuf: public UnbufferedStreamBuf
|
||||
/// This streambuf base32-encodes all data written
|
||||
/// to it and forwards it to a connected
|
||||
/// ostream.
|
||||
///
|
||||
/// Note: The characters are directly written
|
||||
/// to the ostream's streambuf, thus bypassing
|
||||
/// the ostream. The ostream's state is therefore
|
||||
/// not updated to match the buffer's state.
|
||||
{
|
||||
public:
|
||||
Base32EncoderBuf(std::ostream& ostr);
|
||||
~Base32EncoderBuf();
|
||||
|
||||
int close();
|
||||
/// Closes the stream buffer.
|
||||
|
||||
private:
|
||||
int writeToDevice(char c);
|
||||
|
||||
unsigned char _group[5];
|
||||
int _groupLength;
|
||||
std::streambuf& _buf;
|
||||
|
||||
static const unsigned char OUT_ENCODING[32];
|
||||
|
||||
friend class Base32DecoderBuf;
|
||||
|
||||
Base32EncoderBuf(const Base32EncoderBuf&);
|
||||
Base32EncoderBuf& operator = (const Base32EncoderBuf&);
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API Base32EncoderIOS: public virtual std::ios
|
||||
/// The base class for Base32Encoder.
|
||||
///
|
||||
/// This class is needed to ensure the correct initialization
|
||||
/// order of the stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
Base32EncoderIOS(std::ostream& ostr);
|
||||
~Base32EncoderIOS();
|
||||
int close();
|
||||
Base32EncoderBuf* rdbuf();
|
||||
|
||||
protected:
|
||||
Base32EncoderBuf _buf;
|
||||
|
||||
private:
|
||||
Base32EncoderIOS(const Base32EncoderIOS&);
|
||||
Base32EncoderIOS& operator = (const Base32EncoderIOS&);
|
||||
};
|
||||
|
||||
|
||||
class Foundation_API Base32Encoder: public Base32EncoderIOS, public std::ostream
|
||||
/// This ostream base32-encodes all data
|
||||
/// written to it and forwards it to
|
||||
/// a connected ostream.
|
||||
/// Always call close() when done
|
||||
/// writing data, to ensure proper
|
||||
/// completion of the encoding operation.
|
||||
///
|
||||
/// Note: The characters are directly written
|
||||
/// to the ostream's streambuf, thus bypassing
|
||||
/// the ostream. The ostream's state is therefore
|
||||
/// not updated to match the buffer's state.
|
||||
{
|
||||
public:
|
||||
Base32Encoder(std::ostream& ostr);
|
||||
~Base32Encoder();
|
||||
|
||||
private:
|
||||
Base32Encoder(const Base32Encoder&);
|
||||
Base32Encoder& operator = (const Base32Encoder&);
|
||||
};
|
||||
|
||||
|
||||
} // namespace Poco
|
||||
|
||||
|
||||
#endif // Foundation_Base32Encoder_INCLUDED
|
181
Foundation/src/Base32Decoder.cpp
Normal file
181
Foundation/src/Base32Decoder.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
//
|
||||
// Base32Decoder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Base32Decoder.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: Base32
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Base32Decoder.h"
|
||||
#include "Poco/Base32Encoder.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
unsigned char Base32DecoderBuf::IN_ENCODING[256];
|
||||
bool Base32DecoderBuf::IN_ENCODING_INIT = false;
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static FastMutex mutex;
|
||||
}
|
||||
|
||||
|
||||
Base32DecoderBuf::Base32DecoderBuf(std::istream& istr):
|
||||
_groupLength(0),
|
||||
_groupIndex(0),
|
||||
_buf(*istr.rdbuf())
|
||||
{
|
||||
FastMutex::ScopedLock lock(mutex);
|
||||
if (!IN_ENCODING_INIT)
|
||||
{
|
||||
for (unsigned i = 0; i < sizeof(IN_ENCODING); i++)
|
||||
{
|
||||
IN_ENCODING[i] = 0xFF;
|
||||
}
|
||||
for (unsigned i = 0; i < sizeof(Base32EncoderBuf::OUT_ENCODING); i++)
|
||||
{
|
||||
IN_ENCODING[Base32EncoderBuf::OUT_ENCODING[i]] = i;
|
||||
}
|
||||
IN_ENCODING[static_cast<unsigned char>('=')] = '\0';
|
||||
IN_ENCODING_INIT = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Base32DecoderBuf::~Base32DecoderBuf()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Base32DecoderBuf::readFromDevice()
|
||||
{
|
||||
if (_groupIndex < _groupLength)
|
||||
{
|
||||
return _group[_groupIndex++];
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char buffer[8];
|
||||
memset(buffer, '=', sizeof(buffer));
|
||||
int c;
|
||||
|
||||
// per RFC-4648, Section 6, permissible block lengths are:
|
||||
// 2, 4, 5, 7, and 8 bytes. Any other length is malformed.
|
||||
//
|
||||
do {
|
||||
if ((c = readOne()) == -1) return -1;
|
||||
buffer[0] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[0]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) throw DataFormatException();
|
||||
buffer[1] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[1]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) break;
|
||||
buffer[2] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[2]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) throw DataFormatException();
|
||||
buffer[3] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[3]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) break;
|
||||
buffer[4] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[4]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) break;
|
||||
buffer[5] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[5]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) throw DataFormatException();
|
||||
buffer[6] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[6]] == 0xFF) throw DataFormatException();
|
||||
if ((c = readOne()) == -1) break;
|
||||
buffer[7] = (unsigned char) c;
|
||||
if (IN_ENCODING[buffer[7]] == 0xFF) throw DataFormatException();
|
||||
} while (false);
|
||||
|
||||
_group[0] = (IN_ENCODING[buffer[0]] << 3) | (IN_ENCODING[buffer[1]] >> 2);
|
||||
_group[1] = ((IN_ENCODING[buffer[1]] & 0x03) << 6) | (IN_ENCODING[buffer[2]] << 1) | (IN_ENCODING[buffer[3]] >> 4);
|
||||
_group[2] = ((IN_ENCODING[buffer[3]] & 0x0F) << 4) | (IN_ENCODING[buffer[4]] >> 1);
|
||||
_group[3] = ((IN_ENCODING[buffer[4]] & 0x01) << 7) | (IN_ENCODING[buffer[5]] << 2) | (IN_ENCODING[buffer[6]] >> 3);
|
||||
_group[4] = ((IN_ENCODING[buffer[6]] & 0x07) << 5) | IN_ENCODING[buffer[7]];
|
||||
|
||||
if (buffer[2] == '=')
|
||||
_groupLength = 1;
|
||||
else if (buffer[4] == '=')
|
||||
_groupLength = 2;
|
||||
else if (buffer[5] == '=')
|
||||
_groupLength = 3;
|
||||
else if (buffer[7] == '=')
|
||||
_groupLength = 4;
|
||||
else
|
||||
_groupLength = 5;
|
||||
_groupIndex = 1;
|
||||
return _group[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Base32DecoderBuf::readOne()
|
||||
{
|
||||
int ch = _buf.sbumpc();
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
Base32DecoderIOS::Base32DecoderIOS(std::istream& istr): _buf(istr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
Base32DecoderIOS::~Base32DecoderIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base32DecoderBuf* Base32DecoderIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
Base32Decoder::Base32Decoder(std::istream& istr): Base32DecoderIOS(istr), std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base32Decoder::~Base32Decoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
223
Foundation/src/Base32Encoder.cpp
Normal file
223
Foundation/src/Base32Encoder.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
//
|
||||
// Base32Encoder.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/src/Base32Encoder.cpp#2 $
|
||||
//
|
||||
// Library: Foundation
|
||||
// Package: Streams
|
||||
// Module: Base32
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Base32Encoder.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
|
||||
const unsigned char Base32EncoderBuf::OUT_ENCODING[32] =
|
||||
{
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', '2', '3', '4', '5', '6', '8',
|
||||
};
|
||||
|
||||
|
||||
Base32EncoderBuf::Base32EncoderBuf(std::ostream& ostr):
|
||||
_groupLength(0),
|
||||
_buf(*ostr.rdbuf())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base32EncoderBuf::~Base32EncoderBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Base32EncoderBuf::writeToDevice(char c)
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
_group[_groupLength++] = (unsigned char) c;
|
||||
if (_groupLength == 5)
|
||||
{
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 3;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x07) << 2) | (_group[1] >> 6);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x3E) >> 1);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x01) << 4) | (_group[2] >> 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[2] & 0x0F) << 1) | (_group[3] >> 7);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[3] & 0x7C) >> 2);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[3] & 0x03) << 3) | (_group[4] >> 5);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = (_group[4] & 0x1F);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
_groupLength = 0;
|
||||
}
|
||||
return charToInt(c);
|
||||
}
|
||||
|
||||
|
||||
int Base32EncoderBuf::close()
|
||||
{
|
||||
static const int eof = std::char_traits<char>::eof();
|
||||
|
||||
if (sync() == eof) return eof;
|
||||
if (_groupLength == 1)
|
||||
{
|
||||
_group[1] = 0;
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 3;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x07) << 2);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
#if 0
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
#endif
|
||||
}
|
||||
else if (_groupLength == 2)
|
||||
{
|
||||
_group[2] = 0;
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 3;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x07) << 2) | (_group[1] >> 6);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x3E) >> 1);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x01) << 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
#if 0
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
#endif
|
||||
}
|
||||
else if (_groupLength == 3)
|
||||
{
|
||||
_group[3] = 0;
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 3;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x07) << 2) | (_group[1] >> 6);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x3E) >> 1);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x01) << 4) | (_group[2] >> 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[2] & 0x0F) << 1);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
#if 0
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
#endif
|
||||
}
|
||||
else if (_groupLength == 4)
|
||||
{
|
||||
_group[4] = 0;
|
||||
unsigned char idx;
|
||||
idx = _group[0] >> 3;
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[0] & 0x07) << 2) | (_group[1] >> 6);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x3E) >> 1);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[1] & 0x01) << 4) | (_group[2] >> 4);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[2] & 0x0F) << 1) | (_group[3] >> 7);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[3] & 0x7C) >> 2);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
idx = ((_group[3] & 0x03) << 3);
|
||||
if (_buf.sputc(OUT_ENCODING[idx]) == eof) return eof;
|
||||
#if 0
|
||||
if (_buf.sputc('=') == eof) return eof;
|
||||
#endif
|
||||
}
|
||||
_groupLength = 0;
|
||||
return _buf.pubsync();
|
||||
}
|
||||
|
||||
|
||||
Base32EncoderIOS::Base32EncoderIOS(std::ostream& ostr): _buf(ostr)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
Base32EncoderIOS::~Base32EncoderIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int Base32EncoderIOS::close()
|
||||
{
|
||||
return _buf.close();
|
||||
}
|
||||
|
||||
|
||||
Base32EncoderBuf* Base32EncoderIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
Base32Encoder::Base32Encoder(std::ostream& ostr): Base32EncoderIOS(ostr), std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base32Encoder::~Base32Encoder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace Poco
|
@ -9,8 +9,8 @@
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = ActiveMethodTest ActivityTest ActiveDispatcherTest \
|
||||
AutoPtrTest ArrayTest SharedPtrTest AutoReleasePoolTest Base64Test \
|
||||
BinaryReaderWriterTest LineEndingConverterTest \
|
||||
AutoPtrTest ArrayTest SharedPtrTest AutoReleasePoolTest \
|
||||
Base32Test Base64Test BinaryReaderWriterTest LineEndingConverterTest \
|
||||
ByteOrderTest ChannelTest ClassLoaderTest CoreTest CoreTestSuite \
|
||||
CountingStreamTest CryptTestSuite DateTimeFormatterTest \
|
||||
DateTimeParserTest DateTimeTest LocalDateTimeTest DateTimeTestSuite DigestStreamTest \
|
||||
|
@ -774,6 +774,10 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.cpp"
|
||||
>
|
||||
@ -834,6 +838,10 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.h"
|
||||
>
|
||||
|
@ -304,6 +304,7 @@
|
||||
<ClCompile Include="src\ArrayTest.cpp" />
|
||||
<ClCompile Include="src\AutoPtrTest.cpp" />
|
||||
<ClCompile Include="src\AutoReleasePoolTest.cpp" />
|
||||
<ClCompile Include="src\Base32Test.cpp" />
|
||||
<ClCompile Include="src\ByteOrderTest.cpp" />
|
||||
<ClCompile Include="src\CoreTest.cpp" />
|
||||
<ClCompile Include="src\CoreTestSuite.cpp" />
|
||||
@ -437,6 +438,7 @@
|
||||
<ClInclude Include="src\ArrayTest.h" />
|
||||
<ClInclude Include="src\AutoPtrTest.h" />
|
||||
<ClInclude Include="src\AutoReleasePoolTest.h" />
|
||||
<ClInclude Include="src\Base32Test.h" />
|
||||
<ClInclude Include="src\ByteOrderTest.h" />
|
||||
<ClInclude Include="src\CoreTest.h" />
|
||||
<ClInclude Include="src\CoreTestSuite.h" />
|
||||
|
@ -573,6 +573,9 @@
|
||||
<ClCompile Include="src\FIFOBufferStreamTest.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\AnyTest.h">
|
||||
@ -965,5 +968,8 @@
|
||||
<ClInclude Include="src\ArrayTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base32Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -330,6 +330,7 @@
|
||||
<ClCompile Include="src\StringTokenizerTest.cpp" />
|
||||
<ClCompile Include="src\TuplesTest.cpp" />
|
||||
<ClCompile Include="src\TypeListTest.cpp" />
|
||||
<ClCompile Include="src\Base32Test.cpp" />
|
||||
<ClCompile Include="src\Base64Test.cpp" />
|
||||
<ClCompile Include="src\BinaryReaderWriterTest.cpp" />
|
||||
<ClCompile Include="src\CountingStreamTest.cpp" />
|
||||
@ -463,6 +464,7 @@
|
||||
<ClInclude Include="src\StringTokenizerTest.h" />
|
||||
<ClInclude Include="src\TuplesTest.h" />
|
||||
<ClInclude Include="src\TypeListTest.h" />
|
||||
<ClInclude Include="src\Base32Test.h" />
|
||||
<ClInclude Include="src\Base64Test.h" />
|
||||
<ClInclude Include="src\BinaryReaderWriterTest.h" />
|
||||
<ClInclude Include="src\CountingStreamTest.h" />
|
||||
|
@ -240,6 +240,9 @@
|
||||
<ClCompile Include="src\TypeListTest.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base64Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -635,6 +638,9 @@
|
||||
<ClInclude Include="src\TypeListTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base32Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base64Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -547,6 +547,9 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.cpp">
|
||||
</File>
|
||||
@ -590,6 +593,9 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.h">
|
||||
</File>
|
||||
|
@ -743,6 +743,10 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.cpp"
|
||||
>
|
||||
@ -803,6 +807,10 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.h"
|
||||
>
|
||||
|
@ -729,6 +729,10 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.cpp"
|
||||
>
|
||||
@ -789,6 +793,10 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.h"
|
||||
>
|
||||
|
@ -324,6 +324,7 @@
|
||||
<ClCompile Include="src\StringTokenizerTest.cpp" />
|
||||
<ClCompile Include="src\TuplesTest.cpp" />
|
||||
<ClCompile Include="src\TypeListTest.cpp" />
|
||||
<ClCompile Include="src\Base32Test.cpp" />
|
||||
<ClCompile Include="src\Base64Test.cpp" />
|
||||
<ClCompile Include="src\BinaryReaderWriterTest.cpp" />
|
||||
<ClCompile Include="src\CountingStreamTest.cpp" />
|
||||
@ -458,6 +459,7 @@
|
||||
<ClInclude Include="src\StringTokenizerTest.h" />
|
||||
<ClInclude Include="src\TuplesTest.h" />
|
||||
<ClInclude Include="src\TypeListTest.h" />
|
||||
<ClInclude Include="src\Base32Test.h" />
|
||||
<ClInclude Include="src\Base64Test.h" />
|
||||
<ClInclude Include="src\BinaryReaderWriterTest.h" />
|
||||
<ClInclude Include="src\CountingStreamTest.h" />
|
||||
|
@ -240,6 +240,9 @@
|
||||
<ClCompile Include="src\TypeListTest.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base64Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -638,6 +641,9 @@
|
||||
<ClInclude Include="src\TypeListTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base32Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base64Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -330,6 +330,7 @@
|
||||
<ClCompile Include="src\StringTokenizerTest.cpp" />
|
||||
<ClCompile Include="src\TuplesTest.cpp" />
|
||||
<ClCompile Include="src\TypeListTest.cpp" />
|
||||
<ClCompile Include="src\Base32Test.cpp" />
|
||||
<ClCompile Include="src\Base64Test.cpp" />
|
||||
<ClCompile Include="src\BinaryReaderWriterTest.cpp" />
|
||||
<ClCompile Include="src\CountingStreamTest.cpp" />
|
||||
@ -464,6 +465,7 @@
|
||||
<ClInclude Include="src\StringTokenizerTest.h" />
|
||||
<ClInclude Include="src\TuplesTest.h" />
|
||||
<ClInclude Include="src\TypeListTest.h" />
|
||||
<ClInclude Include="src\Base32Test.h" />
|
||||
<ClInclude Include="src\Base64Test.h" />
|
||||
<ClInclude Include="src\BinaryReaderWriterTest.h" />
|
||||
<ClInclude Include="src\CountingStreamTest.h" />
|
||||
|
@ -240,6 +240,9 @@
|
||||
<ClCompile Include="src\TypeListTest.cpp">
|
||||
<Filter>Core\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base32Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Base64Test.cpp">
|
||||
<Filter>Streams\Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -638,6 +641,9 @@
|
||||
<ClInclude Include="src\TypeListTest.h">
|
||||
<Filter>Core\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base32Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\Base64Test.h">
|
||||
<Filter>Streams\Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -719,6 +719,10 @@
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.cpp"
|
||||
>
|
||||
@ -775,6 +779,10 @@
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Base32Test.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Base64Test.h"
|
||||
>
|
||||
|
197
Foundation/testsuite/src/Base32Test.cpp
Normal file
197
Foundation/testsuite/src/Base32Test.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
//
|
||||
// Base32Test.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/testsuite/src/Base32Test.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Base32Test.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Base32Encoder.h"
|
||||
#include "Poco/Base32Decoder.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::Base32Encoder;
|
||||
using Poco::Base32Decoder;
|
||||
using Poco::DataFormatException;
|
||||
|
||||
|
||||
Base32Test::Base32Test(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Base32Test::~Base32Test()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Base32Test::testEncoder()
|
||||
{
|
||||
{
|
||||
std::ostringstream str;
|
||||
Base32Encoder encoder(str);
|
||||
encoder << std::string("\00\01\02\03\04\05", 6);
|
||||
encoder.close();
|
||||
assert (str.str() == "AAAQEAYEAU");
|
||||
}
|
||||
{
|
||||
std::ostringstream str;
|
||||
Base32Encoder encoder(str);
|
||||
encoder << std::string("\00\01\02\03", 4);
|
||||
encoder.close();
|
||||
assert (str.str() == "AAAQEAY");
|
||||
}
|
||||
{
|
||||
std::ostringstream str;
|
||||
Base32Encoder encoder(str);
|
||||
encoder << "ABCDEF";
|
||||
encoder.close();
|
||||
assert (str.str() == "IFBEGRCFIY");
|
||||
}
|
||||
{
|
||||
std::ostringstream str;
|
||||
Base32Encoder encoder(str);
|
||||
encoder << "ABCDE";
|
||||
encoder.close();
|
||||
assert (str.str() == "IFBEGRCF");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Base32Test::testDecoder()
|
||||
{
|
||||
{
|
||||
std::istringstream istr("AAAQEAYEAU");
|
||||
Base32Decoder decoder(istr);
|
||||
assert (decoder.good() && decoder.get() == 0);
|
||||
assert (decoder.good() && decoder.get() == 1);
|
||||
assert (decoder.good() && decoder.get() == 2);
|
||||
assert (decoder.good() && decoder.get() == 3);
|
||||
assert (decoder.good() && decoder.get() == 4);
|
||||
assert (decoder.good() && decoder.get() == 5);
|
||||
assert (decoder.good() && decoder.get() == -1);
|
||||
}
|
||||
{
|
||||
std::istringstream istr("AAAQEAYE");
|
||||
Base32Decoder decoder(istr);
|
||||
assert (decoder.good() && decoder.get() == 0);
|
||||
assert (decoder.good() && decoder.get() == 1);
|
||||
assert (decoder.good() && decoder.get() == 2);
|
||||
assert (decoder.good() && decoder.get() == 3);
|
||||
assert (decoder.good() && decoder.get() == 4);
|
||||
assert (decoder.good() && decoder.get() == -1);
|
||||
}
|
||||
{
|
||||
std::istringstream istr("AAAQEAY");
|
||||
Base32Decoder decoder(istr);
|
||||
assert (decoder.good() && decoder.get() == 0);
|
||||
assert (decoder.good() && decoder.get() == 1);
|
||||
assert (decoder.good() && decoder.get() == 2);
|
||||
assert (decoder.good() && decoder.get() == 3);
|
||||
assert (decoder.good() && decoder.get() == -1);
|
||||
}
|
||||
{
|
||||
std::istringstream istr("IFBEGRCFIY");
|
||||
Base32Decoder decoder(istr);
|
||||
std::string s;
|
||||
decoder >> s;
|
||||
assert (s == "ABCDEF");
|
||||
assert (decoder.eof());
|
||||
assert (!decoder.fail());
|
||||
}
|
||||
{
|
||||
std::istringstream istr("QUJD#REVG");
|
||||
Base32Decoder decoder(istr);
|
||||
std::string s;
|
||||
try
|
||||
{
|
||||
decoder >> s;
|
||||
assert (decoder.bad());
|
||||
}
|
||||
catch (DataFormatException&)
|
||||
{
|
||||
}
|
||||
assert (!decoder.eof());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Base32Test::testEncodeDecode()
|
||||
{
|
||||
{
|
||||
std::stringstream str;
|
||||
Base32Encoder encoder(str);
|
||||
encoder << "The quick brown fox ";
|
||||
encoder << "jumped over the lazy dog.";
|
||||
encoder.close();
|
||||
Base32Decoder decoder(str);
|
||||
std::string s;
|
||||
int c = decoder.get();
|
||||
while (c != -1) { s += char(c); c = decoder.get(); }
|
||||
assert (s == "The quick brown fox jumped over the lazy dog.");
|
||||
}
|
||||
{
|
||||
std::string src;
|
||||
for (int i = 0; i < 255; ++i) src += char(i);
|
||||
std::stringstream str;
|
||||
Base32Encoder encoder(str);
|
||||
encoder.write(src.data(), (std::streamsize) src.size());
|
||||
encoder.close();
|
||||
Base32Decoder decoder(str);
|
||||
std::string s;
|
||||
int c = decoder.get();
|
||||
while (c != -1) { s += char(c); c = decoder.get(); }
|
||||
assert (s == src);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Base32Test::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Base32Test::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* Base32Test::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("Base32Test");
|
||||
|
||||
CppUnit_addTest(pSuite, Base32Test, testEncoder);
|
||||
CppUnit_addTest(pSuite, Base32Test, testDecoder);
|
||||
CppUnit_addTest(pSuite, Base32Test, testEncodeDecode);
|
||||
|
||||
return pSuite;
|
||||
}
|
62
Foundation/testsuite/src/Base32Test.h
Normal file
62
Foundation/testsuite/src/Base32Test.h
Normal file
@ -0,0 +1,62 @@
|
||||
//
|
||||
// Base32Test.h
|
||||
//
|
||||
// $Id: //poco/1.4/Foundation/testsuite/src/Base32Test.h#1 $
|
||||
//
|
||||
// Definition of the Base32Test class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Base32Test_INCLUDED
|
||||
#define Base32Test_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class Base32Test: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
Base32Test(const std::string& name);
|
||||
~Base32Test();
|
||||
|
||||
void testEncoder();
|
||||
void testDecoder();
|
||||
void testEncodeDecode();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // Base32Test_INCLUDED
|
@ -31,6 +31,7 @@
|
||||
|
||||
|
||||
#include "StreamsTestSuite.h"
|
||||
#include "Base32Test.h"
|
||||
#include "Base64Test.h"
|
||||
#include "HexBinaryTest.h"
|
||||
#include "StreamCopierTest.h"
|
||||
@ -50,6 +51,7 @@ CppUnit::Test* StreamsTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("StreamsTestSuite");
|
||||
|
||||
pSuite->addTest(Base32Test::suite());
|
||||
pSuite->addTest(Base64Test::suite());
|
||||
pSuite->addTest(HexBinaryTest::suite());
|
||||
pSuite->addTest(StreamCopierTest::suite());
|
||||
|
Loading…
x
Reference in New Issue
Block a user