mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Removed old files after creating a submodules [#CLICKHOUSE-2].
This commit is contained in:
parent
14d9a91b6e
commit
b586e2771e
File diff suppressed because it is too large
Load Diff
@ -1,317 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8.0)
|
||||
|
||||
# POCO_BUILD_TYPE
|
||||
# POCO_STATIC
|
||||
# POCO_UNBUNDLED
|
||||
# POCO_NO_LOCALE
|
||||
#
|
||||
# POCO_ENABLE_{COMPONENT}
|
||||
# POCO_ENABLE_TESTS
|
||||
|
||||
project(Poco)
|
||||
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/libversion" SHARED_LIBRARY_VERSION)
|
||||
|
||||
# Read the version information from the VERSION file
|
||||
file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PACKAGE_VERSION )
|
||||
message(STATUS "Poco package version: ${PACKAGE_VERSION}")
|
||||
string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" CPACK_PACKAGE_VERSION_MAJOR ${PACKAGE_VERSION})
|
||||
string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" CPACK_PACKAGE_VERSION_MINOR ${PACKAGE_VERSION})
|
||||
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" CPACK_PACKAGE_VERSION_PATCH ${PACKAGE_VERSION})
|
||||
|
||||
set(COMPLETE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
|
||||
set(RELEASE_NAME "Unstable-trunk")
|
||||
set(PROJECT_VERSION ${COMPLETE_VERSION})
|
||||
|
||||
# Put the libaries and binaries that get built into directories at the
|
||||
# top of the build tree rather than in hard-to-find leaf
|
||||
# directories. This simplifies manual testing and the use of the build
|
||||
# tree rather than installed Boost libraries.
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
# Windows DLLs are "runtime" for CMake. Output them to "bin" like the Visual Studio projects do.
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
|
||||
# Append our module directory to CMake
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
#################################################################################
|
||||
# Setup C/C++ compiler options
|
||||
#################################################################################
|
||||
|
||||
if(NOT MSVC_IDE)
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
|
||||
"Choose the type of build, options are: None Debug Release" FORCE)
|
||||
endif()
|
||||
message(STATUS "Setting Poco build type - ${CMAKE_BUILD_TYPE}")
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "")
|
||||
set( CMAKE_BUILD_TYPE "RelWithDebInfo" )
|
||||
endif ()
|
||||
|
||||
# http://www.cmake.org/Wiki/CMake_Useful_Variables :
|
||||
# CMAKE_BUILD_TYPE
|
||||
# Choose the type of build. CMake has default flags for these:
|
||||
#
|
||||
# * None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used)
|
||||
# * Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG)
|
||||
# * Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE)
|
||||
# * RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
||||
# * MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)
|
||||
|
||||
# For Debug build types, append a "d" to the library names.
|
||||
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
|
||||
|
||||
# Include some common macros to simpilfy the Poco CMake files
|
||||
include(PocoMacros)
|
||||
|
||||
# Allow enabling and disabling components
|
||||
option(POCO_ENABLE_XML "Enable the XML" ON)
|
||||
option(POCO_ENABLE_MONGODB "Enable MongoDB" ON)
|
||||
option(POCO_ENABLE_PDF "Enable PDF" OFF)
|
||||
option(POCO_ENABLE_UTIL "Enable Util" ON)
|
||||
option(POCO_ENABLE_NET "Enable Net" ON)
|
||||
option(POCO_ENABLE_NETSSL "Enable NetSSL" ON)
|
||||
option(POCO_ENABLE_NETSSL_WIN "Enable NetSSL Windows" OFF)
|
||||
option(POCO_ENABLE_CRYPTO "Enable Crypto" ON)
|
||||
option(POCO_ENABLE_DATA "Enable Data" ON)
|
||||
option(POCO_ENABLE_DATA_SQLITE "Enable Data SQlite" OFF)
|
||||
option(POCO_ENABLE_DATA_MYSQL "Enable Data MySQL" OFF)
|
||||
option(POCO_ENABLE_DATA_ODBC "Enable Data ODBC" ON)
|
||||
option(POCO_ENABLE_SEVENZIP "Enable SevenZip" OFF)
|
||||
option(POCO_ENABLE_ZIP "Enable Zip" OFF)
|
||||
option(POCO_ENABLE_APACHECONNECTOR "Enable ApacheConnector" OFF)
|
||||
option(POCO_ENABLE_CPPPARSER "Enable C++ parser" OFF)
|
||||
option(POCO_ENABLE_POCODOC "Enable Poco Documentation Generator" OFF)
|
||||
|
||||
option(FORCE_OPENSSL "Force usage of OpenSSL even under windows" OFF)
|
||||
|
||||
option(POCO_ENABLE_TESTS
|
||||
"Set to OFF|ON (default is OFF) to control build of POCO tests & samples" OFF)
|
||||
|
||||
option(POCO_STATIC
|
||||
"Set to OFF|ON (default is ON) to control build of POCO as STATIC library" ON)
|
||||
|
||||
option(POCO_UNBUNDLED
|
||||
"Set to OFF|ON (default is OFF) to control linking dependencies as external" OFF)
|
||||
|
||||
# Uncomment from next two lines to force statitc or dynamic library, default is autodetection
|
||||
if (POCO_STATIC)
|
||||
add_definitions( -DPOCO_STATIC -DPOCO_NO_AUTOMATIC_LIBS)
|
||||
set( LIB_MODE STATIC )
|
||||
message(STATUS "Building static libraries")
|
||||
else (POCO_STATIC)
|
||||
set( LIB_MODE SHARED )
|
||||
message(STATUS "Building dynamic libraries")
|
||||
endif (POCO_STATIC)
|
||||
|
||||
if (POCO_ENABLE_TESTS)
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
message(STATUS "Building with unittests & samples")
|
||||
else ()
|
||||
message(STATUS "Building without tests & samples")
|
||||
endif ()
|
||||
|
||||
if (POCO_UNBUNDLED)
|
||||
add_definitions( -DPOCO_UNBUNDLED)
|
||||
message(STATUS "Build with using external sqlite, pcre, expat ...")
|
||||
else ()
|
||||
message(STATUS "Build with using internal copy of sqlite, pcre, expat, ...")
|
||||
endif ()
|
||||
|
||||
include(CheckTypeSize)
|
||||
find_package(Cygwin)
|
||||
|
||||
# OS Detection
|
||||
if(WIN32)
|
||||
add_definitions( -DPOCO_OS_FAMILY_WINDOWS -DUNICODE -D_UNICODE)
|
||||
#set(SYSLIBS iphlpapi gdi32 odbc32)
|
||||
endif(WIN32)
|
||||
|
||||
if (UNIX AND NOT ANDROID )
|
||||
add_definitions( -DPOCO_OS_FAMILY_UNIX )
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field -Wno-unused-local-typedef -Wno-for-loop-analysis -Wno-unknown-pragmas -Wno-unused-variable")
|
||||
if (APPLE)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
|
||||
endif ()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unknown-pragmas -Wno-unused-variable")
|
||||
# Standard 'must be' defines
|
||||
if (APPLE)
|
||||
add_definitions( -DPOCO_HAVE_IPv6 -DPOCO_NO_STAT64)
|
||||
set(SYSLIBS ${CMAKE_DL_LIBS})
|
||||
elseif (CMAKE_SYSTEM MATCHES "FreeBSD")
|
||||
add_definitions(-D__BSD_VISIBLE ) # better #include <sys/cdefs.h>
|
||||
add_definitions(-D_XOPEN_SOURCE=700 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_IPv6 -DPOCO_HAVE_FD_POLL)
|
||||
set(SYSLIBS pthread ${CMAKE_DL_LIBS} rt)
|
||||
else ()
|
||||
add_definitions(-D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DPOCO_HAVE_FD_EPOLL -DPOCO_HAVE_IPv6)
|
||||
set(SYSLIBS pthread ${CMAKE_DL_LIBS} rt)
|
||||
endif ()
|
||||
endif(UNIX AND NOT ANDROID )
|
||||
|
||||
if (CMAKE_SYSTEM MATCHES "SunOS")
|
||||
add_definitions( -DPOCO_OS_FAMILY_UNIX )
|
||||
# Standard 'must be' defines
|
||||
add_definitions( -D_XOPEN_SOURCE=500 -D_REENTRANT -D_THREAD_SAFE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 )
|
||||
set(SYSLIBS pthread socket xnet nsl resolv rt ${CMAKE_DL_LIBS})
|
||||
endif(CMAKE_SYSTEM MATCHES "SunOS")
|
||||
|
||||
if (CMAKE_COMPILER_IS_MINGW)
|
||||
add_definitions(-DWC_NO_BEST_FIT_CHARS=0x400 -DPOCO_WIN32_UTF8)
|
||||
add_definitions(-D_WIN32 -DMINGW32 -DWINVER=0x500 -DODBCVER=0x0300 -DPOCO_THREAD_STACK_SIZE)
|
||||
endif (CMAKE_COMPILER_IS_MINGW)
|
||||
|
||||
if (CYGWIN)
|
||||
# add_definitions(-DWC_NO_BEST_FIT_CHARS=0x400 -DPOCO_WIN32_UTF8)
|
||||
endif (CYGWIN)
|
||||
|
||||
# SunPro C++
|
||||
if (${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
|
||||
add_definitions( -D_BSD_SOURCE -library=stlport4)
|
||||
endif (${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
|
||||
|
||||
# iOS
|
||||
if (IOS)
|
||||
add_definitions( -DPOCO_HAVE_IPv6 -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_STAT64 -DPOCO_NO_SHAREDLIBS -DPOCO_NO_NET_IFTYPES )
|
||||
endif (IOS)
|
||||
|
||||
#Android
|
||||
if (ANDROID)
|
||||
add_definitions( -DPOCO_ANDROID -DPOCO_NO_FPENVIRONMENT -DPOCO_NO_WSTRING -DPOCO_NO_SHAREDMEMORY )
|
||||
endif (ANDROID)
|
||||
|
||||
|
||||
# Collect the built libraries and include dirs, the will be used to create the PocoConfig.cmake file
|
||||
set (Poco_COMPONENTS "")
|
||||
|
||||
if (POCO_ENABLE_TESTS)
|
||||
add_subdirectory (CppUnit)
|
||||
endif ()
|
||||
|
||||
add_subdirectory (Foundation)
|
||||
if (POCO_ENABLE_XML)
|
||||
add_subdirectory (XML)
|
||||
list (APPEND Poco_COMPONENTS "XML")
|
||||
endif ()
|
||||
if (POCO_ENABLE_MONGODB)
|
||||
add_subdirectory (MongoDB)
|
||||
list (APPEND Poco_COMPONENTS "MongoDB")
|
||||
endif ()
|
||||
if (POCO_ENABLE_PDF)
|
||||
add_subdirectory (PDF)
|
||||
list (APPEND Poco_COMPONENTS "PDF")
|
||||
endif()
|
||||
if (POCO_ENABLE_UTIL)
|
||||
add_subdirectory (Util)
|
||||
list (APPEND Poco_COMPONENTS "Util")
|
||||
endif ()
|
||||
if (POCO_ENABLE_NET)
|
||||
add_subdirectory (Net)
|
||||
list (APPEND Poco_COMPONENTS "Net")
|
||||
endif ()
|
||||
|
||||
|
||||
#NetSSL
|
||||
|
||||
|
||||
if(WIN32 AND POCO_ENABLE_NETSSL_WIN)
|
||||
add_subdirectory(NetSSL_Win)
|
||||
list(APPEND Poco_COMPONENTS "NetSSL_Win")
|
||||
endif(WIN32 AND POCO_ENABLE_NETSSL_WIN)
|
||||
|
||||
find_package(OpenSSL)
|
||||
if(OPENSSL_FOUND)
|
||||
include_directories("${OPENSSL_INCLUDE_DIR}")
|
||||
if(POCO_ENABLE_NETSSL)
|
||||
add_subdirectory(NetSSL_OpenSSL)
|
||||
list(APPEND Poco_COMPONENTS "NetSSL_OpenSSL")
|
||||
endif()
|
||||
if(POCO_ENABLE_CRYPTO)
|
||||
add_subdirectory(Crypto)
|
||||
list(APPEND Poco_COMPONENTS "Crypto")
|
||||
endif()
|
||||
endif(OPENSSL_FOUND)
|
||||
|
||||
if(POCO_ENABLE_DATA)
|
||||
add_subdirectory(Data)
|
||||
list(APPEND Poco_COMPONENTS "Data")
|
||||
endif()
|
||||
if(POCO_ENABLE_SEVENZIP)
|
||||
add_subdirectory(SevenZip)
|
||||
list(APPEND Poco_COMPONENTS "SevenZip")
|
||||
endif()
|
||||
if(POCO_ENABLE_ZIP)
|
||||
add_subdirectory(Zip)
|
||||
list(APPEND Poco_COMPONENTS "Zip")
|
||||
endif()
|
||||
|
||||
find_package(APR)
|
||||
find_package(Apache2)
|
||||
if(APRUTIL_FOUND AND APACHE_FOUND)
|
||||
include_directories( "${APACHE_INCLUDE_DIR}" "${APRUTIL_INCLUDE_DIR}" )
|
||||
if(POCO_ENABLE_APACHECONNECTOR)
|
||||
add_subdirectory(ApacheConnector)
|
||||
list(APPEND Poco_COMPONENTS "ApacheConnector")
|
||||
endif()
|
||||
endif(APRUTIL_FOUND AND APACHE_FOUND)
|
||||
|
||||
if(POCO_ENABLE_CPPPARSER)
|
||||
add_subdirectory(CppParser)
|
||||
list(APPEND Poco_COMPONENTS "CppParser")
|
||||
endif()
|
||||
|
||||
if(POCO_ENABLE_POCODOC)
|
||||
add_subdirectory(PocoDoc)
|
||||
list(APPEND Poco_COMPONENTS "PocoDoc")
|
||||
endif()
|
||||
|
||||
#############################################################
|
||||
# Uninstall stuff see: http://www.vtk.org/Wiki/CMake_FAQ
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
||||
IMMEDIATE @ONLY)
|
||||
|
||||
add_custom_target(uninstall
|
||||
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
||||
|
||||
#############################################################
|
||||
# Enable packaging
|
||||
|
||||
include(InstallRequiredSystemLibraries)
|
||||
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Poco Libraries")
|
||||
set(CPACK_PACKAGE_VENDOR "Applied Informatics Software Engineering GmbH")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr/local")
|
||||
|
||||
include(CPack)
|
||||
|
||||
#############################################################
|
||||
# cmake config files
|
||||
|
||||
configure_file(cmake/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake" @ONLY)
|
||||
install(
|
||||
FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake
|
||||
DESTINATION
|
||||
"lib/cmake/${PROJECT_NAME}"
|
||||
COMPONENT
|
||||
Devel
|
||||
)
|
||||
|
||||
# in tree build settings
|
||||
#configure_file(PocoBuildTreeSettings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/PocoBuildTreeSettings.cmake @ONLY)
|
||||
|
||||
|
||||
message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
|
||||
message(STATUS "Installation target path: ${CMAKE_INSTALL_PREFIX}")
|
||||
|
||||
foreach(component ${Poco_COMPONENTS})
|
||||
message(STATUS "Building: ${component}")
|
||||
endforeach()
|
||||
|
@ -1,53 +0,0 @@
|
||||
Guenter Obiltschnig
|
||||
Alex Fabijanic
|
||||
Peter Schojer
|
||||
Ferdinand Beyer
|
||||
Krzysztof Burghardt
|
||||
Claus Dabringer
|
||||
Caleb Epstein
|
||||
Eran Hammer-Lahav
|
||||
Chris Johnson
|
||||
Sergey Kholodilov
|
||||
Ryan Kraay
|
||||
Larry Lewis
|
||||
Andrew J. P. Maclean
|
||||
Andrew Marlow
|
||||
Paschal Mushubi
|
||||
Jiang Shan
|
||||
David Shawley
|
||||
Sergey Skorokhodov
|
||||
Tom Tan
|
||||
Sergey N. Yatskevich
|
||||
Marc Chevrier
|
||||
Philippe Cuvillier
|
||||
Marian Krivos
|
||||
Franky Braem
|
||||
Philip Prindeville
|
||||
Anton Yabchinskiy
|
||||
Rangel Reale
|
||||
Fabrizio Duhem
|
||||
Patrick White
|
||||
Mike Naquin
|
||||
Roger Meier
|
||||
Mathaus Mendel
|
||||
Arturo Castro
|
||||
Adrian Imboden
|
||||
Matej Knopp
|
||||
Patrice Tarabbia
|
||||
Lucas Clemente
|
||||
Karl Reid
|
||||
Pascal Bach
|
||||
Cristian Thiago Moecke
|
||||
Sergei Nikulov
|
||||
Aaron Kaluszka
|
||||
Iyed Bennour
|
||||
Scott Davis
|
||||
Kristin Cowalcijk
|
||||
Yuval Kashtan
|
||||
Christopher Baker
|
||||
Scott Davis
|
||||
Jeff Adams
|
||||
Martin Osborne
|
||||
Björn Schramke
|
||||
--
|
||||
$Id$
|
@ -1,77 +0,0 @@
|
||||
//
|
||||
// WinTestRunner.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/include/WinTestRunner/WinTestRunner.h#1 $
|
||||
//
|
||||
// Application shell for CppUnit's TestRunner dialog.
|
||||
//
|
||||
|
||||
|
||||
#ifndef WinTestRunner_H_INCLUDED
|
||||
#define WinTestRunner_H_INCLUDED
|
||||
|
||||
|
||||
#if !defined(POCO_STATIC)
|
||||
#if defined(WinTestRunner_EXPORTS)
|
||||
#define WinTestRunner_API __declspec(dllexport)
|
||||
#else
|
||||
#define WinTestRunner_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define WinTestRunner_API
|
||||
#endif
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include <vector>
|
||||
#include <afxwin.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class Test;
|
||||
|
||||
|
||||
class WinTestRunner_API WinTestRunner
|
||||
{
|
||||
public:
|
||||
WinTestRunner();
|
||||
~WinTestRunner();
|
||||
|
||||
void run();
|
||||
void addTest(Test* pTest);
|
||||
|
||||
private:
|
||||
std::vector<Test*> _tests;
|
||||
};
|
||||
|
||||
|
||||
class WinTestRunner_API WinTestRunnerApp: public CWinApp
|
||||
/// A simple application class that hosts the TestRunner dialog.
|
||||
/// Create a subclass and override the TestMain() method.
|
||||
///
|
||||
/// WinTestRunnerApp supports a batch mode, which runs the
|
||||
/// test using the standard text-based TestRunner from CppUnit.
|
||||
/// To enable batch mode, start the application with the "/b"
|
||||
/// or "/B" argument. Optionally, a filename may be specified
|
||||
/// where the test output will be written to: "/b:<path>" or
|
||||
/// "/B:<path>".
|
||||
///
|
||||
/// When run in batch mode, the exit code of the application
|
||||
/// will denote test success (0) or failure (1).
|
||||
{
|
||||
public:
|
||||
virtual BOOL InitInstance();
|
||||
|
||||
virtual void TestMain() = 0;
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // WinTestRunner_H_INCLUDED
|
||||
|
@ -1,27 +0,0 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by TestRunner.rc
|
||||
//
|
||||
#define IDD_DIALOG_TESTRUNNER 129
|
||||
#define IDC_LIST 1000
|
||||
#define ID_RUN 1001
|
||||
#define ID_STOP 1002
|
||||
#define IDC_PROGRESS 1003
|
||||
#define IDC_INDICATOR 1004
|
||||
#define IDC_COMBO_TEST 1005
|
||||
#define IDC_STATIC_RUNS 1007
|
||||
#define IDC_STATIC_ERRORS 1008
|
||||
#define IDC_STATIC_FAILURES 1009
|
||||
#define IDC_EDIT_TIME 1010
|
||||
#define IDC_CHK_AUTORUN 1013
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 131
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1014
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
@ -1,175 +0,0 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
|
||||
"#define _AFX_NO_OLE_RESOURCES\r\n"
|
||||
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
|
||||
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
|
||||
"\r\n"
|
||||
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
|
||||
"#ifdef _WIN32\r\n"
|
||||
"LANGUAGE 9, 1\r\n"
|
||||
"#pragma code_page(1252)\r\n"
|
||||
"#endif\r\n"
|
||||
"#include ""..\\res\\WinTestRunner.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
|
||||
"#include ""afxres.rc"" // Standard components\r\n"
|
||||
"#endif\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,1
|
||||
PRODUCTVERSION 1,0,0,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "FileDescription", "CppUnit WinTestRunner DLL"
|
||||
VALUE "FileVersion", "1, 0, 0, 1"
|
||||
VALUE "InternalName", "WinTestRunner"
|
||||
VALUE "LegalCopyright", "Copyright (c) 2005"
|
||||
VALUE "OriginalFilename", "TestRunner.dll"
|
||||
VALUE "ProductName", "CppUnit WinTestRunner Dynamic Link Library"
|
||||
VALUE "ProductVersion", "1, 0, 0, 1"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_DIALOG_TESTRUNNER DIALOGEX 0, 0, 512, 300
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "CppUnit WinTestRunner"
|
||||
FONT 8, "MS Sans Serif", 0, 0, 0x0
|
||||
BEGIN
|
||||
COMBOBOX IDC_COMBO_TEST,7,20,424,273,CBS_DROPDOWNLIST |
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
DEFPUSHBUTTON "Run",ID_RUN,455,7,50,14
|
||||
DEFPUSHBUTTON "Stop",ID_STOP,455,24,50,14
|
||||
CONTROL "List1",IDC_LIST,"SysListView32",LVS_REPORT | WS_BORDER |
|
||||
WS_TABSTOP,7,110,498,160
|
||||
PUSHBUTTON "Close",IDOK,455,279,50,14
|
||||
LTEXT "Test Name:",IDC_STATIC,7,9,179,9
|
||||
LTEXT "Progress:",IDC_STATIC,7,55,49,9
|
||||
LTEXT "Errors and Failures:",IDC_STATIC,7,99,67,9
|
||||
LTEXT "Runs:",IDC_STATIC,457,54,26,10
|
||||
LTEXT "Failures:",IDC_STATIC,457,80,26,10
|
||||
LTEXT "Errors:",IDC_STATIC,457,67,26,10
|
||||
RTEXT "0",IDC_STATIC_RUNS,487,54,16,10
|
||||
RTEXT "0",IDC_STATIC_ERRORS,487,67,16,10
|
||||
RTEXT "0",IDC_STATIC_FAILURES,487,80,16,10
|
||||
EDITTEXT IDC_EDIT_TIME,7,281,440,12,ES_AUTOHSCROLL | ES_READONLY |
|
||||
NOT WS_BORDER
|
||||
LTEXT "",IDC_PROGRESS,7,67,424,20,SS_SUNKEN | NOT WS_VISIBLE
|
||||
CONTROL "Auto Run",IDC_CHK_AUTORUN,"Button",BS_AUTOCHECKBOX |
|
||||
BS_LEFTTEXT | WS_TABSTOP,383,38,46,10
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO
|
||||
BEGIN
|
||||
IDD_DIALOG_TESTRUNNER, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 505
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 293
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
#define _AFX_NO_SPLITTER_RESOURCES
|
||||
#define _AFX_NO_OLE_RESOURCES
|
||||
#define _AFX_NO_TRACKER_RESOURCES
|
||||
#define _AFX_NO_PROPERTY_RESOURCES
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE 9, 1
|
||||
#pragma code_page(1252)
|
||||
#endif
|
||||
#include "afxres.rc" // Standard components
|
||||
#endif
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
@ -1,44 +0,0 @@
|
||||
//
|
||||
// ActiveTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ActiveTest.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include <afxwin.h>
|
||||
#include "ActiveTest.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Spawn a thread to a test
|
||||
void ActiveTest::run(TestResult* result)
|
||||
{
|
||||
CWinThread* thread;
|
||||
|
||||
setTestResult(result);
|
||||
_runCompleted.ResetEvent();
|
||||
|
||||
thread = AfxBeginThread(threadFunction, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
|
||||
DuplicateHandle(GetCurrentProcess(), thread->m_hThread, GetCurrentProcess(), &_threadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
|
||||
|
||||
thread->ResumeThread();
|
||||
}
|
||||
|
||||
|
||||
// Simple execution thread. Assuming that an ActiveTest instance
|
||||
// only creates one of these at a time.
|
||||
UINT ActiveTest::threadFunction(LPVOID thisInstance)
|
||||
{
|
||||
ActiveTest* test = (ActiveTest*) thisInstance;
|
||||
|
||||
test->run();
|
||||
test->_runCompleted.SetEvent();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
@ -1,89 +0,0 @@
|
||||
//
|
||||
// ActiveTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ActiveTest.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef ActiveTest_INCLUDED
|
||||
#define ActiveTest_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/TestDecorator.h"
|
||||
#include <afxmt.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
/* A Microsoft-specific active test
|
||||
*
|
||||
* An active test manages its own
|
||||
* thread of execution. This one
|
||||
* is very simple and only sufficient
|
||||
* for the limited use we put it through
|
||||
* in the TestRunner. It spawns a thread
|
||||
* on run (TestResult *) and signals
|
||||
* completion of the test.
|
||||
*
|
||||
* We assume that only one thread
|
||||
* will be active at once for each
|
||||
* instance.
|
||||
*
|
||||
*/
|
||||
class ActiveTest: public TestDecorator
|
||||
{
|
||||
public:
|
||||
ActiveTest(Test* test);
|
||||
~ActiveTest();
|
||||
|
||||
void run(TestResult* result);
|
||||
|
||||
protected:
|
||||
HANDLE _threadHandle;
|
||||
CEvent _runCompleted;
|
||||
TestResult* _currentTestResult;
|
||||
|
||||
void run ();
|
||||
void setTestResult(TestResult* result);
|
||||
static UINT threadFunction(LPVOID thisInstance);
|
||||
};
|
||||
|
||||
|
||||
// Construct the active test
|
||||
inline ActiveTest::ActiveTest(Test *test): TestDecorator(test)
|
||||
{
|
||||
_currentTestResult = NULL;
|
||||
_threadHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
// Pend until the test has completed
|
||||
inline ActiveTest::~ActiveTest()
|
||||
{
|
||||
CSingleLock(&_runCompleted, TRUE);
|
||||
CloseHandle(_threadHandle);
|
||||
}
|
||||
|
||||
|
||||
// Set the test result that we are to run
|
||||
inline void ActiveTest::setTestResult(TestResult* result)
|
||||
{
|
||||
_currentTestResult = result;
|
||||
}
|
||||
|
||||
|
||||
// Run our test result
|
||||
inline void ActiveTest::run()
|
||||
{
|
||||
TestDecorator::run(_currentTestResult);
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // ActiveTest_INCLUDED
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
//
|
||||
// DLLMain.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/DLLMain.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include <afxwin.h>
|
||||
#include <afxdllx.h>
|
||||
|
||||
|
||||
static AFX_EXTENSION_MODULE TestRunnerDLL = { NULL, NULL };
|
||||
|
||||
|
||||
extern "C" int APIENTRY
|
||||
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
|
||||
{
|
||||
// Remove this if you use lpReserved
|
||||
UNREFERENCED_PARAMETER(lpReserved);
|
||||
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
TRACE0("WinTestRunner.DLL Initializing\n");
|
||||
|
||||
// Extension DLL one-time initialization
|
||||
if (!AfxInitExtensionModule(TestRunnerDLL, hInstance))
|
||||
return 0;
|
||||
|
||||
// Insert this DLL into the resource chain
|
||||
// NOTE: If this Extension DLL is being implicitly linked to by
|
||||
// an MFC Regular DLL (such as an ActiveX Control)
|
||||
// instead of an MFC application, then you will want to
|
||||
// remove this line from DllMain and put it in a separate
|
||||
// function exported from this Extension DLL. The Regular DLL
|
||||
// that uses this Extension DLL should then explicitly call that
|
||||
// function to initialize this Extension DLL. Otherwise,
|
||||
// the CDynLinkLibrary object will not be attached to the
|
||||
// Regular DLL's resource chain, and serious problems will
|
||||
// result.
|
||||
|
||||
new CDynLinkLibrary(TestRunnerDLL);
|
||||
}
|
||||
else if (dwReason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
TRACE0("WinTestRunner.DLL Terminating\n");
|
||||
// Terminate the library before destructors are called
|
||||
AfxTermExtensionModule(TestRunnerDLL);
|
||||
}
|
||||
return 1; // ok
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
//
|
||||
// GUITestResult.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/GUITestResult.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "TestRunnerDlg.h"
|
||||
#include "GUITestResult.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
void GUITestResult::addError(Test *test, CppUnitException *e)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
|
||||
TestResult::addError(test, e);
|
||||
_runner->addError(this, test, e);
|
||||
}
|
||||
|
||||
|
||||
void GUITestResult::addFailure(Test *test, CppUnitException *e)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
|
||||
TestResult::addFailure(test, e);
|
||||
_runner->addFailure(this, test, e);
|
||||
}
|
||||
|
||||
|
||||
void GUITestResult::startTest(Test *test)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
|
||||
TestResult::startTest(test);
|
||||
_runner->startTest(test);
|
||||
}
|
||||
|
||||
|
||||
void GUITestResult::endTest(Test *test)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
|
||||
TestResult::endTest(test);
|
||||
_runner->endTest(this, test);
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
@ -1,83 +0,0 @@
|
||||
//
|
||||
// GUITestResult.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/GUITestResult.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef GuiTestResult_INCLUDED
|
||||
#define GuiTestResult_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/TestResult.h"
|
||||
#include <afxmt.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class TestRunnerDlg;
|
||||
|
||||
|
||||
class GUITestResult: public TestResult
|
||||
{
|
||||
public:
|
||||
GUITestResult(TestRunnerDlg* runner);
|
||||
~GUITestResult();
|
||||
|
||||
void addError(Test* test, CppUnitException* e);
|
||||
void addFailure(Test* test, CppUnitException* e);
|
||||
|
||||
void startTest(Test* test);
|
||||
void endTest(Test* test);
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
class LightweightSynchronizationObject: public TestResult::SynchronizationObject
|
||||
{
|
||||
public:
|
||||
void lock()
|
||||
{
|
||||
_syncObject.Lock();
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
_syncObject.Unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
CCriticalSection _syncObject;
|
||||
};
|
||||
|
||||
private:
|
||||
TestRunnerDlg *_runner;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Construct with lightweight synchronization
|
||||
inline GUITestResult::GUITestResult(TestRunnerDlg* runner): _runner(runner)
|
||||
{
|
||||
setSynchronizationObject(new LightweightSynchronizationObject());
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
inline GUITestResult::~GUITestResult()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Override without protection to prevent deadlock
|
||||
inline void GUITestResult::stop()
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // GuiTestResult_INCLUDED
|
@ -1,140 +0,0 @@
|
||||
//
|
||||
// ProgressBar.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ProgressBar.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "ProgressBar.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Paint the progress bar in response to a paint message
|
||||
void ProgressBar::paint(CDC& dc)
|
||||
{
|
||||
paintBackground (dc);
|
||||
paintStatus (dc);
|
||||
}
|
||||
|
||||
|
||||
// Paint the background of the progress bar region
|
||||
void ProgressBar::paintBackground (CDC& dc)
|
||||
{
|
||||
CBrush brshBackground;
|
||||
CPen penGray (PS_SOLID, 1, RGB (128, 128, 128));
|
||||
CPen penWhite (PS_SOLID, 1, RGB (255, 255, 255));
|
||||
|
||||
VERIFY (brshBackground.CreateSolidBrush (::GetSysColor (COLOR_BTNFACE)));
|
||||
|
||||
dc.FillRect (_bounds, &brshBackground);
|
||||
|
||||
CPen *pOldPen;
|
||||
|
||||
pOldPen = dc.SelectObject (&penGray);
|
||||
{
|
||||
dc.MoveTo (_bounds.left, _bounds.top);
|
||||
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top);
|
||||
|
||||
dc.MoveTo (_bounds.left, _bounds.top);
|
||||
dc.LineTo (_bounds.left, _bounds.top + _bounds.Height () -1);
|
||||
|
||||
}
|
||||
dc.SelectObject (&penWhite);
|
||||
{
|
||||
dc.MoveTo (_bounds.left + _bounds.Width () -1, _bounds.top);
|
||||
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
|
||||
|
||||
dc.MoveTo (_bounds.left, _bounds.top + _bounds.Height () -1);
|
||||
dc.LineTo (_bounds.left + _bounds.Width () -1, _bounds.top + _bounds.Height () -1);
|
||||
|
||||
}
|
||||
dc.SelectObject (pOldPen);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Paint the actual status of the progress bar
|
||||
void ProgressBar::paintStatus (CDC& dc)
|
||||
{
|
||||
if (_progress <= 0)
|
||||
return;
|
||||
|
||||
CBrush brshStatus;
|
||||
CRect rect (_bounds.left, _bounds.top,
|
||||
_bounds.left + _progressX, _bounds.bottom);
|
||||
|
||||
COLORREF statusColor = getStatusColor ();
|
||||
|
||||
VERIFY (brshStatus.CreateSolidBrush (statusColor));
|
||||
|
||||
rect.DeflateRect (1, 1);
|
||||
dc.FillRect (rect, &brshStatus);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Paint the current step
|
||||
void ProgressBar::paintStep (int startX, int endX)
|
||||
{
|
||||
// kludge: painting the whole region on each step
|
||||
_baseWindow->RedrawWindow (_bounds);
|
||||
_baseWindow->UpdateWindow ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Setup the progress bar for execution over a total number of steps
|
||||
void ProgressBar::start (int total)
|
||||
{
|
||||
_total = total;
|
||||
reset ();
|
||||
}
|
||||
|
||||
|
||||
// Take one step, indicating whether it was a successful step
|
||||
void ProgressBar::step (bool successful)
|
||||
{
|
||||
_progress++;
|
||||
|
||||
int x = _progressX;
|
||||
|
||||
_progressX = scale (_progress);
|
||||
|
||||
if (!_error && !successful)
|
||||
{
|
||||
_error = true;
|
||||
x = 1;
|
||||
}
|
||||
|
||||
paintStep (x, _progressX);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Map from steps to display units
|
||||
int ProgressBar::scale (int value)
|
||||
{
|
||||
if (_total > 0)
|
||||
return max (1, value * (_bounds.Width () - 1) / _total);
|
||||
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Reset the progress bar
|
||||
void ProgressBar::reset ()
|
||||
{
|
||||
_progressX = 1;
|
||||
_progress = 0;
|
||||
_error = false;
|
||||
|
||||
_baseWindow->RedrawWindow (_bounds);
|
||||
_baseWindow->UpdateWindow ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,74 +0,0 @@
|
||||
//
|
||||
// ProgressBar.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/ProgressBar.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef ProgressBar_INCLUDED
|
||||
#define ProgressBar_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include <afxwin.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
/* A Simple ProgressBar for test execution display
|
||||
*/
|
||||
class ProgressBar
|
||||
{
|
||||
public:
|
||||
ProgressBar(CWnd* baseWindow, CRect& bounds);
|
||||
|
||||
void step(bool successful);
|
||||
void paint(CDC& dc);
|
||||
int scale(int value);
|
||||
void reset();
|
||||
void start(int total);
|
||||
|
||||
protected:
|
||||
void paintBackground(CDC& dc);
|
||||
void paintStatus(CDC& dc);
|
||||
COLORREF getStatusColor();
|
||||
void paintStep(int startX, int endX);
|
||||
|
||||
CWnd* _baseWindow;
|
||||
CRect _bounds;
|
||||
|
||||
bool _error;
|
||||
int _total;
|
||||
int _progress;
|
||||
int _progressX;
|
||||
};
|
||||
|
||||
|
||||
// Construct a ProgressBar
|
||||
inline ProgressBar::ProgressBar(CWnd* baseWindow, CRect& bounds):
|
||||
_baseWindow(baseWindow),
|
||||
_bounds(bounds),
|
||||
_error(false),
|
||||
_total(0),
|
||||
_progress(0),
|
||||
_progressX(0)
|
||||
{
|
||||
WINDOWINFO wi;
|
||||
wi.cbSize = sizeof(WINDOWINFO);
|
||||
baseWindow->GetWindowInfo(&wi);
|
||||
_bounds.OffsetRect(-wi.rcClient.left, -wi.rcClient.top);
|
||||
}
|
||||
|
||||
|
||||
// Get the current color
|
||||
inline COLORREF ProgressBar::getStatusColor()
|
||||
{
|
||||
return _error ? RGB(255, 0, 0) : RGB(0, 255, 0);
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // ProgressBar_INCLUDED
|
@ -1,106 +0,0 @@
|
||||
#ifndef SYNCHRONIZEDTESTRESULTDECORATOR_H
|
||||
#define SYNCHRONIZEDTESTRESULTDECORATOR_H
|
||||
|
||||
#include <afxmt.h>
|
||||
#include "TestResultDecorator.h"
|
||||
|
||||
class SynchronizedTestResult : public TestResultDecorator
|
||||
{
|
||||
public:
|
||||
SynchronizedTestResult (TestResult *result);
|
||||
~SynchronizedTestResult ();
|
||||
|
||||
|
||||
bool shouldStop ();
|
||||
void addError (Test *test, CppUnitException *e);
|
||||
void addFailure (Test *test, CppUnitException *e);
|
||||
void startTest (Test *test);
|
||||
void endTest (Test *test);
|
||||
int runTests ();
|
||||
int testErrors ();
|
||||
int testFailures ();
|
||||
bool wasSuccessful ();
|
||||
void stop ();
|
||||
|
||||
vector<TestFailure *>& errors ();
|
||||
vector<TestFailure *>& failures ();
|
||||
|
||||
private:
|
||||
CCriticalSection m_criticalSection;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Constructor
|
||||
inline SynchronizedTestResult::SynchronizedTestResult (TestResult *result)
|
||||
: TestResultDecorator (result) {}
|
||||
|
||||
// Destructor
|
||||
inline SynchronizedTestResult::~SynchronizedTestResult ()
|
||||
{}
|
||||
|
||||
// Returns whether the test should stop
|
||||
inline bool SynchronizedTestResult::shouldStop ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->shouldStop (); }
|
||||
|
||||
|
||||
// Adds an error to the list of errors. The passed in exception
|
||||
// caused the error
|
||||
inline void SynchronizedTestResult::addError (Test *test, CppUnitException *e)
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->addError (test, e); }
|
||||
|
||||
|
||||
// Adds a failure to the list of failures. The passed in exception
|
||||
// caused the failure.
|
||||
inline void SynchronizedTestResult::addFailure (Test *test, CppUnitException *e)
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->addFailure (test, e); }
|
||||
|
||||
|
||||
// Informs the result that a test will be started.
|
||||
inline void SynchronizedTestResult::startTest (Test *test)
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->startTest (test); }
|
||||
|
||||
|
||||
// Informs the result that a test was completed.
|
||||
inline void SynchronizedTestResult::endTest (Test *test)
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->endTest (test); }
|
||||
|
||||
|
||||
// Gets the number of run tests.
|
||||
inline int SynchronizedTestResult::runTests ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->runTests (); }
|
||||
|
||||
|
||||
// Gets the number of detected errors.
|
||||
inline int SynchronizedTestResult::testErrors ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->testErrors (); }
|
||||
|
||||
|
||||
// Gets the number of detected failures.
|
||||
inline int SynchronizedTestResult::testFailures ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->testFailures (); }
|
||||
|
||||
|
||||
// Returns whether the entire test was successful or not.
|
||||
inline bool SynchronizedTestResult::wasSuccessful ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->wasSuccessful (); }
|
||||
|
||||
|
||||
// Marks that the test run should stop.
|
||||
inline void SynchronizedTestResult::stop ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); m_result->stop (); }
|
||||
|
||||
|
||||
// Returns a vector of the errors.
|
||||
inline vector<TestFailure *>& SynchronizedTestResult::errors ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->errors (); }
|
||||
|
||||
|
||||
// Returns a vector of the failures.
|
||||
inline vector<TestFailure *>& SynchronizedTestResult::failures ()
|
||||
{ CSingleLock sync (&m_criticalSection, TRUE); return m_result->failures (); }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,102 +0,0 @@
|
||||
#ifndef CPP_UNIT_TESTRESULTDECORATOR_H
|
||||
#define CPP_UNIT_TESTRESULTDECORATOR_H
|
||||
|
||||
#include "TestResult.h"
|
||||
|
||||
class TestResultDecorator
|
||||
{
|
||||
public:
|
||||
TestResultDecorator (TestResult *result);
|
||||
virtual ~TestResultDecorator ();
|
||||
|
||||
|
||||
virtual bool shouldStop ();
|
||||
virtual void addError (Test *test, CppUnitException *e);
|
||||
virtual void addFailure (Test *test, CppUnitException *e);
|
||||
virtual void startTest (Test *test);
|
||||
virtual void endTest (Test *test);
|
||||
virtual int runTests ();
|
||||
virtual int testErrors ();
|
||||
virtual int testFailures ();
|
||||
virtual bool wasSuccessful ();
|
||||
virtual void stop ();
|
||||
|
||||
vector<TestFailure *>& errors ();
|
||||
vector<TestFailure *>& failures ();
|
||||
|
||||
protected:
|
||||
TestResult *m_result;
|
||||
};
|
||||
|
||||
|
||||
inline TestResultDecorator::TestResultDecorator (TestResult *result)
|
||||
: m_result (result) {}
|
||||
|
||||
inline TestResultDecorator::~TestResultDecorator ()
|
||||
{}
|
||||
|
||||
// Returns whether the test should stop
|
||||
inline bool TestResultDecorator::shouldStop ()
|
||||
{ return m_result->shouldStop (); }
|
||||
|
||||
|
||||
// Adds an error to the list of errors. The passed in exception
|
||||
// caused the error
|
||||
inline void TestResultDecorator::addError (Test *test, CppUnitException *e)
|
||||
{ m_result->addError (test, e); }
|
||||
|
||||
|
||||
// Adds a failure to the list of failures. The passed in exception
|
||||
// caused the failure.
|
||||
inline void TestResultDecorator::addFailure (Test *test, CppUnitException *e)
|
||||
{ m_result->addFailure (test, e); }
|
||||
|
||||
|
||||
// Informs the result that a test will be started.
|
||||
inline void TestResultDecorator::startTest (Test *test)
|
||||
{ m_result->startTest (test); }
|
||||
|
||||
|
||||
// Informs the result that a test was completed.
|
||||
inline void TestResultDecorator::endTest (Test *test)
|
||||
{ m_result->endTest (test); }
|
||||
|
||||
|
||||
// Gets the number of run tests.
|
||||
inline int TestResultDecorator::runTests ()
|
||||
{ return m_result->runTests (); }
|
||||
|
||||
|
||||
// Gets the number of detected errors.
|
||||
inline int TestResultDecorator::testErrors ()
|
||||
{ return m_result->testErrors (); }
|
||||
|
||||
|
||||
// Gets the number of detected failures.
|
||||
inline int TestResultDecorator::testFailures ()
|
||||
{ return m_result->testFailures (); }
|
||||
|
||||
|
||||
// Returns whether the entire test was successful or not.
|
||||
inline bool TestResultDecorator::wasSuccessful ()
|
||||
{ return m_result->wasSuccessful (); }
|
||||
|
||||
|
||||
// Marks that the test run should stop.
|
||||
inline void TestResultDecorator::stop ()
|
||||
{ m_result->stop (); }
|
||||
|
||||
|
||||
// Returns a vector of the errors.
|
||||
inline vector<TestFailure *>& TestResultDecorator::errors ()
|
||||
{ return m_result->errors (); }
|
||||
|
||||
|
||||
// Returns a vector of the failures.
|
||||
inline vector<TestFailure *>& TestResultDecorator::failures ()
|
||||
{ return m_result->failures (); }
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,439 +0,0 @@
|
||||
//
|
||||
// TestRunnerDlg.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/TestRunnerDlg.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include <afxwin.h>
|
||||
#include <afxext.h>
|
||||
#include <afxcmn.h>
|
||||
#include <mmsystem.h>
|
||||
#include "TestRunnerDlg.h"
|
||||
#include "ActiveTest.h"
|
||||
#include "GUITestResult.h"
|
||||
#include "ProgressBar.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "TestRunnerDlg.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
TestRunnerDlg::TestRunnerDlg(CWnd* pParent): CDialog(TestRunnerDlg::IDD, pParent)
|
||||
{
|
||||
//{{AFX_DATA_INIT(TestRunnerDlg)
|
||||
// NOTE: the ClassWizard will add member initialization here
|
||||
//}}AFX_DATA_INIT
|
||||
|
||||
_testsProgress = 0;
|
||||
_selectedTest = 0;
|
||||
_currentTest = 0;
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(TestRunnerDlg)
|
||||
// NOTE: the ClassWizard will add DDX and DDV calls here
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(TestRunnerDlg, CDialog)
|
||||
//{{AFX_MSG_MAP(TestRunnerDlg)
|
||||
ON_BN_CLICKED(ID_RUN, OnRun)
|
||||
ON_BN_CLICKED(ID_STOP, OnStop)
|
||||
ON_CBN_SELCHANGE(IDC_COMBO_TEST, OnSelchangeComboTest)
|
||||
ON_BN_CLICKED(IDC_CHK_AUTORUN, OnBnClickedAutorun)
|
||||
ON_WM_PAINT()
|
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
BOOL TestRunnerDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
|
||||
CComboBox *comboBox = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
|
||||
|
||||
ASSERT (listCtrl);
|
||||
ASSERT (comboBox);
|
||||
|
||||
CString title;
|
||||
GetWindowText(title);
|
||||
#if defined(_DEBUG)
|
||||
title.Append(" [debug]");
|
||||
#else
|
||||
title.Append(" [release]");
|
||||
#endif
|
||||
SetWindowText(title);
|
||||
|
||||
listCtrl->InsertColumn (0,"Type", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("Type"), 1);
|
||||
listCtrl->InsertColumn (1,"Name", LVCFMT_LEFT, 16 * listCtrl->GetStringWidth ("X"), 2);
|
||||
listCtrl->InsertColumn (2,"Failed Condition", LVCFMT_LEFT, 24 * listCtrl->GetStringWidth ("M"), 3);
|
||||
listCtrl->InsertColumn (3,"Line", LVCFMT_LEFT, 16 + listCtrl->GetStringWidth ("0000"), 4);
|
||||
listCtrl->InsertColumn (4,"File Name", LVCFMT_LEFT, 36 * listCtrl->GetStringWidth ("M"), 5);
|
||||
|
||||
int numberOfCases = 0;
|
||||
|
||||
CWinApp* pApp = AfxGetApp();
|
||||
CString lastTestCS = pApp->GetProfileString("Tests", "lastTest");
|
||||
std::string lastTest((LPCSTR) lastTestCS);
|
||||
int sel = -1;
|
||||
for (std::vector<TestInfo>::iterator it = _tests.begin (); it != _tests.end (); ++it)
|
||||
{
|
||||
std::string cbName(it->level*4, ' ');
|
||||
cbName.append(it->pTest->toString());
|
||||
comboBox->AddString (cbName.c_str ());
|
||||
if (sel < 0)
|
||||
{
|
||||
if (lastTest.empty() || lastTest == it->pTest->toString())
|
||||
{
|
||||
_selectedTest = it->pTest;
|
||||
sel = numberOfCases;
|
||||
}
|
||||
}
|
||||
numberOfCases++;
|
||||
}
|
||||
|
||||
if (numberOfCases > 0)
|
||||
{
|
||||
if (sel < 0)
|
||||
{
|
||||
_selectedTest = _tests[0].pTest;
|
||||
sel = 0;
|
||||
}
|
||||
comboBox->SetCurSel (sel);
|
||||
}
|
||||
else
|
||||
{
|
||||
beRunDisabled ();
|
||||
}
|
||||
CWnd *pProgress = GetDlgItem(IDC_PROGRESS);
|
||||
CRect rect;
|
||||
pProgress->GetWindowRect(&rect);
|
||||
_testsProgress = new ProgressBar (this, rect);
|
||||
|
||||
CButton* autoRunBtn = (CButton*) GetDlgItem(IDC_CHK_AUTORUN);
|
||||
autoRunBtn->SetCheck(pApp->GetProfileInt("Tests", "autoRun", BST_UNCHECKED));
|
||||
|
||||
reset ();
|
||||
|
||||
if (autoRunBtn->GetCheck() == BST_CHECKED)
|
||||
{
|
||||
OnRun();
|
||||
}
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
|
||||
TestRunnerDlg::~TestRunnerDlg ()
|
||||
{
|
||||
freeState ();
|
||||
delete _testsProgress;
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::OnRun()
|
||||
{
|
||||
if (_selectedTest == 0)
|
||||
return;
|
||||
|
||||
freeState ();
|
||||
reset ();
|
||||
|
||||
beRunning ();
|
||||
|
||||
int numberOfTests = _selectedTest->countTestCases ();
|
||||
|
||||
_testsProgress->start (numberOfTests);
|
||||
|
||||
_result = new GUITestResult ((TestRunnerDlg *)this);
|
||||
_activeTest = new ActiveTest (_selectedTest);
|
||||
|
||||
_testStartTime = timeGetTime ();
|
||||
|
||||
_activeTest->run (_result);
|
||||
|
||||
_testEndTime = timeGetTime ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::addListEntry(const std::string& type, TestResult *result, Test *test, CppUnitException *e)
|
||||
{
|
||||
char stage [80];
|
||||
LV_ITEM lvi;
|
||||
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
|
||||
int currentEntry = result->testErrors () + result->testFailures () -1;
|
||||
|
||||
sprintf (stage, "%s", type.c_str ());
|
||||
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = currentEntry;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.pszText = stage;
|
||||
lvi.iImage = 0;
|
||||
lvi.stateMask = 0;
|
||||
lvi.state = 0;
|
||||
|
||||
listCtrl->InsertItem (&lvi);
|
||||
|
||||
// Set class string
|
||||
listCtrl->SetItemText (currentEntry, 1, test->toString ().c_str ());
|
||||
|
||||
// Set the asserted text
|
||||
listCtrl->SetItemText(currentEntry, 2, e->what ());
|
||||
|
||||
// Set the line number
|
||||
if (e->lineNumber () == CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
|
||||
sprintf (stage, "<unknown>");
|
||||
else
|
||||
sprintf (stage, "%ld", e->lineNumber ());
|
||||
|
||||
listCtrl->SetItemText(currentEntry, 3, stage);
|
||||
|
||||
// Set the file name
|
||||
listCtrl->SetItemText(currentEntry, 4, e->fileName ().c_str ());
|
||||
|
||||
listCtrl->RedrawItems (currentEntry, currentEntry);
|
||||
listCtrl->UpdateWindow ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::addError (TestResult *result, Test *test, CppUnitException *e)
|
||||
{
|
||||
addListEntry ("Error", result, test, e);
|
||||
_errors++;
|
||||
|
||||
_currentTest = 0;
|
||||
updateCountsDisplay ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::addFailure (TestResult *result, Test *test, CppUnitException *e)
|
||||
{
|
||||
addListEntry ("Failure", result, test, e);
|
||||
_failures++;
|
||||
|
||||
_currentTest = 0;
|
||||
updateCountsDisplay ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::startTest(Test* test)
|
||||
{
|
||||
_currentTest = test;
|
||||
updateCountsDisplay();
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::endTest (TestResult *result, Test *test)
|
||||
{
|
||||
if (_selectedTest == 0)
|
||||
return;
|
||||
_currentTest = 0;
|
||||
|
||||
_testsRun++;
|
||||
updateCountsDisplay ();
|
||||
_testsProgress->step (_failures == 0 && _errors == 0);
|
||||
|
||||
_testEndTime = timeGetTime ();
|
||||
|
||||
updateCountsDisplay ();
|
||||
|
||||
if (_testsRun >= _selectedTest->countTestCases ())
|
||||
beIdle ();
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::beRunning ()
|
||||
{
|
||||
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
|
||||
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
|
||||
|
||||
runButton->EnableWindow (FALSE);
|
||||
closeButton->EnableWindow (FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::beIdle ()
|
||||
{
|
||||
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
|
||||
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
|
||||
|
||||
runButton->EnableWindow (TRUE);
|
||||
closeButton->EnableWindow (TRUE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::beRunDisabled ()
|
||||
{
|
||||
CButton *runButton = (CButton *)GetDlgItem (ID_RUN);
|
||||
CButton *closeButton = (CButton *)GetDlgItem (IDOK);
|
||||
CButton *stopButton = (CButton *)GetDlgItem (ID_STOP);
|
||||
|
||||
runButton->EnableWindow (FALSE);
|
||||
stopButton->EnableWindow (FALSE);
|
||||
closeButton->EnableWindow (TRUE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::freeState ()
|
||||
{
|
||||
delete _activeTest;
|
||||
delete _result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::reset ()
|
||||
{
|
||||
_testsRun = 0;
|
||||
_errors = 0;
|
||||
_failures = 0;
|
||||
_testEndTime = _testStartTime;
|
||||
|
||||
updateCountsDisplay ();
|
||||
|
||||
_activeTest = 0;
|
||||
_result = 0;
|
||||
|
||||
CListCtrl *listCtrl = (CListCtrl *)GetDlgItem (IDC_LIST);
|
||||
|
||||
listCtrl->DeleteAllItems ();
|
||||
_testsProgress->reset ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::updateCountsDisplay ()
|
||||
{
|
||||
CStatic *statTestsRun = (CStatic *)GetDlgItem (IDC_STATIC_RUNS);
|
||||
CStatic *statErrors = (CStatic *)GetDlgItem (IDC_STATIC_ERRORS);
|
||||
CStatic *statFailures = (CStatic *)GetDlgItem (IDC_STATIC_FAILURES);
|
||||
CEdit *editTime = (CEdit *)GetDlgItem (IDC_EDIT_TIME);
|
||||
|
||||
CString argumentString;
|
||||
|
||||
argumentString.Format ("%d", _testsRun);
|
||||
statTestsRun ->SetWindowText (argumentString);
|
||||
|
||||
argumentString.Format ("%d", _errors);
|
||||
statErrors ->SetWindowText (argumentString);
|
||||
|
||||
argumentString.Format ("%d", _failures);
|
||||
statFailures ->SetWindowText (argumentString);
|
||||
|
||||
if (_currentTest)
|
||||
argumentString.Format ("Execution Time: %3.3lf seconds, Current Test: %s", (_testEndTime - _testStartTime) / 1000.0, _currentTest->toString().c_str());
|
||||
else
|
||||
argumentString.Format ("Execution Time: %3.3lf seconds", (_testEndTime - _testStartTime) / 1000.0);
|
||||
|
||||
editTime ->SetWindowText (argumentString);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::OnStop()
|
||||
{
|
||||
if (_result)
|
||||
_result->stop ();
|
||||
|
||||
beIdle ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::OnOK()
|
||||
{
|
||||
if (_result)
|
||||
_result->stop ();
|
||||
|
||||
CDialog::OnOK ();
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::OnSelchangeComboTest()
|
||||
{
|
||||
CComboBox *testsSelection = (CComboBox *)GetDlgItem (IDC_COMBO_TEST);
|
||||
|
||||
int currentSelection = testsSelection->GetCurSel ();
|
||||
|
||||
if (currentSelection >= 0 && currentSelection < _tests.size ())
|
||||
{
|
||||
_selectedTest = (_tests.begin () + currentSelection)->pTest;
|
||||
beIdle ();
|
||||
CWinApp* pApp = AfxGetApp();
|
||||
pApp->WriteProfileString("Tests", "lastTest", _selectedTest->toString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
_selectedTest = 0;
|
||||
beRunDisabled ();
|
||||
|
||||
}
|
||||
|
||||
freeState ();
|
||||
reset ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::OnBnClickedAutorun()
|
||||
{
|
||||
CButton *autoRunBtn = (CButton *)GetDlgItem (IDC_CHK_AUTORUN);
|
||||
CWinApp* pApp = AfxGetApp();
|
||||
pApp->WriteProfileInt("Tests", "autoRun", autoRunBtn->GetCheck());
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::OnPaint()
|
||||
{
|
||||
CPaintDC dc (this);
|
||||
|
||||
_testsProgress->paint (dc);
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::setTests(const std::vector<Test*>& tests)
|
||||
{
|
||||
_tests.clear();
|
||||
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
|
||||
{
|
||||
addTest(*it, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestRunnerDlg::addTest(Test* pTest, int level)
|
||||
{
|
||||
TestInfo ti;
|
||||
ti.pTest = pTest;
|
||||
ti.level = level;
|
||||
_tests.push_back(ti);
|
||||
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
|
||||
if (pSuite)
|
||||
{
|
||||
const std::vector<Test*>& tests = pSuite->tests();
|
||||
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
|
||||
{
|
||||
addTest(*it, level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,94 +0,0 @@
|
||||
//
|
||||
// TestRunnerDlg.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/TestRunnerDlg.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef TestRunnerDlg_INCLUDED
|
||||
#define TestRunnerDlg_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/CppUnitException.h"
|
||||
#include "ActiveTest.h"
|
||||
#include <vector>
|
||||
#include "../res/Resource.h"
|
||||
#include <afxwin.h>
|
||||
#include "afxwin.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class ProgressBar;
|
||||
|
||||
|
||||
class TestRunnerDlg: public CDialog
|
||||
{
|
||||
public:
|
||||
TestRunnerDlg(CWnd* pParent = NULL);
|
||||
~TestRunnerDlg();
|
||||
|
||||
void setTests(const std::vector<Test*>& tests);
|
||||
|
||||
void addError(TestResult* result, Test* test, CppUnitException* e);
|
||||
void addFailure(TestResult* result, Test* test, CppUnitException* e);
|
||||
void startTest(Test* test);
|
||||
void endTest(TestResult* result, Test* test);
|
||||
|
||||
//{{AFX_DATA(TestRunnerDlg)
|
||||
enum { IDD = IDD_DIALOG_TESTRUNNER };
|
||||
// NOTE: the ClassWizard will add data members here
|
||||
//}}AFX_DATA
|
||||
|
||||
//{{AFX_VIRTUAL(TestRunnerDlg)
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
protected:
|
||||
//{{AFX_MSG(TestRunnerDlg)
|
||||
virtual BOOL OnInitDialog();
|
||||
afx_msg void OnRun();
|
||||
afx_msg void OnStop();
|
||||
virtual void OnOK();
|
||||
afx_msg void OnSelchangeComboTest();
|
||||
afx_msg void OnBnClickedAutorun();
|
||||
afx_msg void OnPaint();
|
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
void addListEntry(const std::string& type, TestResult* result, Test* test, CppUnitException* e);
|
||||
void beIdle();
|
||||
void beRunning();
|
||||
void beRunDisabled();
|
||||
void reset();
|
||||
void freeState();
|
||||
void updateCountsDisplay();
|
||||
void addTest(Test* pTest, int level);
|
||||
|
||||
struct TestInfo
|
||||
{
|
||||
Test* pTest;
|
||||
int level;
|
||||
};
|
||||
std::vector<TestInfo> _tests;
|
||||
ProgressBar* _testsProgress;
|
||||
Test* _selectedTest;
|
||||
ActiveTest* _activeTest;
|
||||
TestResult* _result;
|
||||
int _testsRun;
|
||||
int _errors;
|
||||
int _failures;
|
||||
DWORD _testStartTime;
|
||||
DWORD _testEndTime;
|
||||
Test* _currentTest;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // TestRunnerDlg_INCLUDED
|
||||
|
@ -1,108 +0,0 @@
|
||||
//
|
||||
// WinTestRunner.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/WinTestRunner/src/WinTestRunner.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "TestRunnerDlg.h"
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include <fstream>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
WinTestRunner::WinTestRunner()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
WinTestRunner::~WinTestRunner()
|
||||
{
|
||||
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
|
||||
void WinTestRunner::run()
|
||||
{
|
||||
// Note: The following code is some evil hack to
|
||||
// add batch capability to the MFC based WinTestRunner.
|
||||
|
||||
std::string cmdLine(AfxGetApp()->m_lpCmdLine);
|
||||
if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
|
||||
{
|
||||
TestRunner runner;
|
||||
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
|
||||
runner.addTest((*it)->toString(), *it);
|
||||
_tests.clear();
|
||||
std::vector<std::string> args;
|
||||
args.push_back("WinTestRunner");
|
||||
args.push_back("-all");
|
||||
bool success = runner.run(args);
|
||||
ExitProcess(success ? 0 : 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're running in interactive mode.
|
||||
TestRunnerDlg dlg;
|
||||
dlg.setTests(_tests);
|
||||
dlg.DoModal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WinTestRunner::addTest(Test* pTest)
|
||||
{
|
||||
_tests.push_back(pTest);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(WinTestRunnerApp, CWinApp)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
BOOL WinTestRunnerApp::InitInstance()
|
||||
{
|
||||
std::string cmdLine(AfxGetApp()->m_lpCmdLine);
|
||||
if (cmdLine.size() >= 2 && cmdLine[0] == '/' && (cmdLine[1] == 'b' || cmdLine[1] == 'B'))
|
||||
{
|
||||
// We're running in batch mode.
|
||||
std::string outPath;
|
||||
if (cmdLine.size() > 4 && cmdLine[2] == ':')
|
||||
{
|
||||
outPath = cmdLine.substr(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buffer[1024];
|
||||
GetModuleFileName(NULL, buffer, sizeof(buffer));
|
||||
outPath = buffer;
|
||||
outPath += ".out";
|
||||
}
|
||||
freopen(outPath.c_str(), "w", stdout);
|
||||
freopen(outPath.c_str(), "w", stderr);
|
||||
TestMain();
|
||||
}
|
||||
else
|
||||
{
|
||||
AllocConsole();
|
||||
SetConsoleTitle("CppUnit WinTestRunner Console");
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
freopen("CONIN$", "r", stdin);
|
||||
TestMain();
|
||||
FreeConsole();
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
void WinTestRunnerApp::TestMain()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,75 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
|
||||
<META NAME="Generator" CONTENT="Microsoft Word 97">
|
||||
<TITLE>CppUnit 1.5</TITLE>
|
||||
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
|
||||
</HEAD>
|
||||
<BODY LINK="#0000ff" VLINK="#800080">
|
||||
|
||||
<P><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"></P>
|
||||
<H1>CppUnit 1.5</H1>
|
||||
<P>Last Revision: 12/15/99 - Michael Feathers (mfeathers@acm.org) - written in standard C++, tested under Microsoft Visual C++ 6.0</P>
|
||||
<P><HR></P>
|
||||
<H3>Background</H3>
|
||||
<P>CppUnit is a simple unit test framework for C++. It is a port from JUnit, a testing framework for Java, developed by Kent Beck and Erich Gamma. </P>
|
||||
<H3>Contents</H3>
|
||||
<PRE>README.html this file
|
||||
|
||||
test the source code
|
||||
framework the testing framework
|
||||
		extensions	some framework extension classes
|
||||
textui a command line interface to run tests
|
||||
ms code for a Microsoft specific TestRunner
|
||||
samples some example test cases and extensions to the framework
|
||||
multicaster a sample illustrating a publish/subscribe
|
||||
				multicaster under test
|
||||
doc documentation</PRE>
|
||||
<H3>Installation</H3>
|
||||
<P>To use the test framework, create a makefile or load all files in test\framework into your IDE. In this incarnation of CppUnit, all includes assume the current directory first. A makefile or project can be used to resolve the dependencies. </P>
|
||||
<P>The directory test\textui contains a simple command line example that uses the framework.</P>
|
||||
<H3>Documentation</H3>
|
||||
<P>CppUnit comes with the following documentation: </P>
|
||||
|
||||
<UL>
|
||||
<LI>a cookbook: doc\cookbook.htm </LI>
|
||||
<LI>this file </LI></UL>
|
||||
|
||||
<H3>Samples</H3>
|
||||
<P>You can find several sample test cases in the samples directory: </P>
|
||||
|
||||
<UL>
|
||||
<LI>ExampleTestCase - some simple tests </LI>
|
||||
<LI>Multicaster - test cases for a sample publish/subscribe multicaster class </LI></UL>
|
||||
|
||||
<P>Also, the wiki page <a HREF="http://c2.com/cgi/wiki?ClassHierarchyTestingInCppUnit">http://c2.com/cgi/wiki?ClassHierarchyTestingInCppUnit</a> shows how to automatically apply tests of classes to the classes' subclasses.</P>
|
||||
|
||||
<H3>Extensions</H3>
|
||||
<P>You can find several classes that illustrate framework extensions in the extensions directory: </P>
|
||||
|
||||
<UL>
|
||||
<LI>TestDecorator - A Decorator for Test. You can use it as the base class for decorators that extend test cases. </LI>
|
||||
<LI>TestSetup - A Decorator that can be used to set up and tear down additional fixture state. Subclass TestSetup and insert it into your tests when you want to set up additional state once before the test is run. </LI>
|
||||
<LI>Orthodox - a template class which can be used to verify operations on an arbitrary class.</LI></UL>
|
||||
|
||||
|
||||
<H3>Notes</H3>
|
||||
<P>Porting this framework has been fun. I've tried to maintain the spirit and utility of JUnit in a C++ environment. Naturally, the move from Java to standard C++ forces out several nice JUnit features:</P>
|
||||
<OL>
|
||||
|
||||
<LI>Platform independent GUI.</LI>
|
||||
<LI>Stack traces of test failures</LI>
|
||||
<LI>Active (threaded) tests</LI>
|
||||
<LI>Direct invocation of test cases via reflection</LI>
|
||||
<LI>Run-time loading of new tests</LI></OL>
|
||||
|
||||
<P>In addition, the lack of garbage collection in C++ requires some careful use of the framework classes. In particular, TestSuites are composites that manage the lifetime of any tests added to them. Holding onto a TestResult past the lifetime of the tests which filled it is a bad idea. This is because TestResults hold TestFailures and TestFailures hold pointers to the Tests that generated them.</P>
|
||||
<P>On the plus side, we can use the C++ macro preprocessor to get the exact line at which a failure occurs, along with the actual text inside the assert () call that detected the failure. The features of C++ that enable this are the __LINE__ and __FILE__ preprocessor definitions, along with the <I>stringizing</I> operator. If you find that generating this much literal text bulks up your test executables, you can use the CPP_UNIT_SOURCEANNOT define to disable that portion of the reporting.</P>
|
||||
<P>Note: If you use the C++ macro "assert ()" in your code, or include assert.h, you may have a name clash with CppUnit's assert macro. This can be remedied by changing the name of the macro to "cu_assert ()" in TestCase.h.</P>
|
||||
<P>I'd like to thank Kent Beck and Erich Gamma for the inspiration, design, and a wonderful cookbook that was easily/shamelessly mutated to describe CppUnit. Double thanks to Erich for thinking up a way to implement TestCaller. Additional thanks to Kent, Ward Cunningham, Ron Jeffries, Martin Fowler, and several other netizens of the WikiWikiWeb. I don't think any other bunch of people could have convinced me that rapid development with unit tests can be both effective and easy.</P>
|
||||
<P>Thanks also to Fred Huls for mentioning the idea of template-based testing. The <EM>orthodox</EM> template class demonstrates only a small part of what can be done with templated test cases.</P>
|
||||
<H3>History Of Changes</H3>
|
||||
<P>1.2 -- Added the TestCaller template class. There is now no need to use the CPP_UNIT_TESTCASEDISPATCH macro unless you are using a C++ compiler which does not support templates well. CPP_UNIT_TESTCASEDISPATCH remains in TestCase.h for backward compatibility. I've also kept the use of the macro in the Multicaster sample to leave in an example.</P>
|
||||
<P>1.3 -- Retired the CPP_UNIT_TESTCASEDISPATCH macro and cleaned up the include structure. Fixed bug in the textui version.</P>
|
||||
<P>1.4 -- Removed using directives for std in CppUnit headers. Merged the old AssertionFailedError into CppUnitException. Fixed a memory leak in the TestRunner class of the MS GUI TestRunner. Removed CppUnit.h file. Now headers for each class must be included directly.</P></BODY></HTML>
|
||||
<P>1.5 -- Upgraded projects from VC++ 5.0 to 6.0.</P></BODY></HTML>
|
@ -1,164 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
|
||||
<META NAME="Generator" CONTENT="Microsoft Word 97">
|
||||
<TITLE>CppUnit Cookbook</TITLE>
|
||||
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
|
||||
</HEAD>
|
||||
<BODY LINK="#0000ff" VLINK="#800080">
|
||||
|
||||
<P><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"></P>
|
||||
<H1>CppUnit Cookbook</H1>
|
||||
<P>Here is a short cookbook to help you get started. </P>
|
||||
<H2>Simple Test Case</H2>
|
||||
<P>You want to know whether your code is working. How do you do it? There are many ways. Stepping through a debugger or littering your code with stream output calls are two of the simpler ways, but they both have drawbacks. Stepping through your code is a good idea, but it is not automatic. You have to do it every time you make changes. Streaming out text is also fine, but it makes code ugly and it generates far more information than you need most of the time.</P>
|
||||
<P>Tests in CppUnit can be run automatically. They are easy to set up and once you have written them, they are always there to help you keep confidence in the quality of your code.</P>
|
||||
<P>To make a simple test, here is what you do:</P>
|
||||
<P>Subclass the TestCase class. Override the method "runTest ()". When you want to check a value, call "assert (bool)" and pass in an expression that is true if the test succeeds. </P>
|
||||
<P>For example, to test the equality comparison for a Complex number class, write:</P>
|
||||
<TT><PRE>	class ComplexNumberTest : public TestCase {
|
||||
	public:
|
||||
ComplexNumberTest (string name) : TestCase (name) {}
|
||||
void runTest () {
|
||||
assert (Complex (10, 1) == Complex (10, 1));
|
||||
assert (!(Complex (1, 1) == Complex (2, 2)));
|
||||
}
|
||||
};</PRE>
|
||||
</TT><P>That was a very simple test. Ordinarily, you'll have many little test cases that you'll want to run on the same set of objects. To do this, use a fixture.</P>
|
||||
<P> </P>
|
||||
<H2>Fixture</H2>
|
||||
<P>A fixture is a known set of objects that serves as a base for a set of test cases. Fixtures come in very handy when you are testing as you develop. Let's try out this style of development and learn about fixtures along the away. Suppose that we are really developing a complex number class. Let's start by defining a empty class named Complex.</P>
|
||||
<TT><PRE>	class Complex {}; </PRE>
|
||||
</TT><P>Now create an instance of ComplexNumberTest above, compile the code and see what happens. The first thing we notice is a few compiler errors. The test uses operator==, but it is not defined. Let's fix that.</P>
|
||||
<TT><PRE>	bool operator== (const Complex& a, const Complex& b) { return true; }</PRE>
|
||||
</TT><P>Now compile the test, and run it. This time it compiles but the test fails. We need a bit more to get an operator== working correctly, so we revisit the code.</P>
|
||||
<TT><PRE>	class Complex {
|
||||
friend bool operator== (const Complex& a, const Complex& b);
|
||||
double real, imaginary;
|
||||
public:
|
||||
Complex () {
|
||||
real = imaginary = 0.0;
|
||||
}
|
||||
};
|
||||
|
||||
bool operator== (const Complex& a, const Complex& b)
|
||||
{ return eq(a.real,b.real) && eq(a.imaginary,b.imaginary); }</PRE>
|
||||
</TT><P>If we compile now and run our test it will pass. </P>
|
||||
<P>Now we are ready to add new operations and new tests. At this point a fixture would be handy. We would probably be better off when doing our tests if we decided to instantiate three or four complex numbers and reuse them across our tests. </P>
|
||||
<P>Here is how we do it:</P>
|
||||
<OL>
|
||||
|
||||
<LI>Add member variables for each part of the fixture </LI>
|
||||
<LI>Override "setUp ()" to initialize the variables </LI>
|
||||
<LI>Override "tearDown ()" to release any permanent resources you allocated in "setUp ()"</LI></OL>
|
||||
|
||||
<TT><PRE>	class ComplexNumberTest : public TestCase {
|
||||
	private:
|
||||
Complex 	*m_10_1, *m_1_1; *m_11_2;
|
||||
	protected:
|
||||
	void		setUp () {
|
||||
			 m_10_1 = new Complex (10, 1);
|
||||
			 m_1_1 = new Complex (1, 1);
|
||||
			 m_11_2 = new Complex (11, 2);
|
||||
}
|
||||
	void		tearDown () {
|
||||
			 delete m_10_1, delete m_1_1, delete m_11_2;
|
||||
			}
|
||||
	};</PRE>
|
||||
</TT><P>Once we have this fixture, we can add the complex addition test case any any others that we need over the course of our development.</P>
|
||||
<P> </P>
|
||||
<H2>Test Case</H2>
|
||||
<P>How do you write and invoke individual tests using a fixture? </P>
|
||||
<P>There are two steps to this process:</P>
|
||||
<OL>
|
||||
|
||||
<LI>Write the test case as a method in the fixture class</LI>
|
||||
<LI>Create a TestCaller which runs that particular method</LI></OL>
|
||||
|
||||
<P>Here is our test case class with a few extra case methods:</P>
|
||||
<TT><PRE>	class ComplexNumberTest : public TestCase {
|
||||
	private:
|
||||
Complex 	*m_10_1, *m_1_1; *m_11_2;
|
||||
	protected:
|
||||
	void		setUp () {
|
||||
			 m_10_1 = new Complex (10, 1);
|
||||
			 m_1_1 = new Complex (1, 1);
|
||||
			 m_11_2 = new Complex (11, 2);
|
||||
}
|
||||
	void		tearDown () {
|
||||
			 delete m_10_1, delete m_1_1, delete m_11_2;
|
||||
			}
|
||||
	void		testEquality () {
|
||||
			 assert (*m_10_1 == *m_10_1);
|
||||
			 assert (!(*m_10_1 == *m_11_2));
|
||||
			}
|
||||
	void		testAddition () {
|
||||
			 assert (*m_10_1 + *m_1_1 == *m_11_2);
|
||||
	}
|
||||
	};</PRE>
|
||||
</TT><P>Create and run instances for each test case like this:</P>
|
||||
<TT><PRE>	test = new TestCaller<ComplexNumberTest>("testEquality", ComplexNumberTest::testEquality);
|
||||
test->run (); </PRE>
|
||||
</TT><P>The second argument to the test caller constructor is the address of a method on ComplexNumberTest. When the test caller is run, that specific method will be run.</P>
|
||||
<P>Once you have several tests, organize them into a suite.</P>
|
||||
<P> </P>
|
||||
<H2>Suite</H2>
|
||||
<P>How do you set up your tests so that you can run them all at once?<BR>
|
||||
<BR>
|
||||
CppUnit provides a TestSuite class that runs any number of TestCases together. For example, to run a single test case, you execute:</P>
|
||||
<TT><PRE>	TestResult result;
|
||||
	TestCaller<ComplexNumberTest> test ("testAddition", ComplexNumberTest::testAddition);
|
||||
	Test.run (&result);</PRE>
|
||||
</TT><P> </P>
|
||||
<P>To create a suite of two or more tests, you do the following:</P>
|
||||
<TT><PRE>	TestSuite suite;
|
||||
	TestResult result;
|
||||
	suite.addTest (new TestCaller<ComplexNumberTest>("testEquality", ComplexNumberTest::testEquality));
|
||||
	suite.addTest (new TestCaller<ComplexNumberTest>("testAddition", ComplexNumberTest::testAddition));
|
||||
	suite.run (&result);
|
||||
</PRE>
|
||||
</TT><P>TestSuites don't only have to contain callers for TestCases. They can contain any object that implements the Test interface. For example, you can create a TestSuite in your code and I can create one in mine, and we can run them together by creating a TestSuite that contains both: </P>
|
||||
<TT><PRE>	TestSuite suite;
|
||||
	suite.addTest (ComplexNumberTest.suite ());
|
||||
	suite.addTest (SurrealNumberTest.suite ());
|
||||
	suite.run (&result);</PRE>
|
||||
</TT><P> </P>
|
||||
<H2>TestRunner</H2>
|
||||
<P>How do you run your tests and collect their results? </P>
|
||||
<P>Once you have a test suite, you'll want to run it. CppUnit provides tools to define the suite to be run and to display its results. You make your suite accessible to a TestRunner program with a static method <I>suite</I> that returns a test suite. <BR>
|
||||
For example, to make a ComplexNumberTest suite available to a TestRunner, add the following code to ComplexNumberTest: </P>
|
||||
<TT><PRE>	public: static Test *suite () {
|
||||
	 TestSuite *suiteOfTests = new TestSuite;
|
||||
	 suiteOfTests->addTest (new TestCaller<ComplexNumberTest>("testEquality", testEquality));
|
||||
	 suiteOfTests->addTest (new TestCaller<ComplexNumberTest>("testAddition", testAddition));
|
||||
return suiteOfTests;
|
||||
	}</PRE>
|
||||
</TT><P>CppUnit provides both a textual version of a TestRunner tool, and a Micosoft Visual C++ 5.0 graphical version. If you are running on another platform, take a look at the graphical version. It is easy to port.</P>
|
||||
<P>To use the text version, include the header file for the test in TestRunner.cpp:</P>
|
||||
<TT><PRE>	#include "ExampleTestCase.h"
|
||||
	#include "ComplexNumberTest.h"</PRE>
|
||||
</TT><P>And add a call to "addTest (string, Test *) in the "main ()" function:</P>
|
||||
<TT><PRE>	int main (int ac, char **av) {
|
||||
	 TestRunner runner;
|
||||
	 runner.addTest (ExampleTestCase::suite ());
|
||||
	 runner.addTest (ComplexNumberTest::suite ());
|
||||
	 runner.run ();
|
||||
	 return 0;
|
||||
	}</PRE>
|
||||
</TT><P>The TestRunner will run the tests. If all the tests pass, you'll get an informative message. If any fail, you'll get the following information:</P>
|
||||
<OL>
|
||||
|
||||
<LI>The name of the test case that failed</LI>
|
||||
<LI>The name of the source file that contains the test</LI>
|
||||
<LI>The line number where the failure occurred</LI>
|
||||
<LI>All of the text inside the call to assert which detected the failure</LI></OL>
|
||||
|
||||
<P>CppUnit distinguishes between <I>failures</I> and <I>errors</I>. A failure is anticipated and checked for with assertions. Errors are unanticipated problems like division by zero and other exceptions thrown by the C++ runtime or your code.</P>
|
||||
<P>If you are running MS Developer's Studio, you can build the GUI version rather easily. There are three projects: culib, TestRunner, and HostApp. They make a static library for the framework, a dialog based TestRunner in a DLL and an example Hosting application, respectively. To incorporate a TestRunner in an application you are developing, link with the static library and the TestRunner DLL. Note that the TestRunner DLL must be in the home directory of your application, the system directory or the path. In your application, create an instance of TestRunnerDlg whenever you want to run tests. Pass tests you want to run to the dialog object and then execute.</P>
|
||||
<P>Here is a screen shot of the TestRunner in use:</P>
|
||||
<P><IMG SRC="test.gif" WIDTH=574 HEIGHT=351></P>
|
||||
<P> </P>
|
||||
<P>More notes about the implementation of CppUnit can be found in README.HTML.</P>
|
||||
<P> </P>
|
||||
<P> </P></BODY>
|
||||
</HTML>
|
@ -1,15 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
|
||||
<META NAME="Generator" CONTENT="Microsoft Word 97">
|
||||
<TITLE>License Agreement</TITLE>
|
||||
<META NAME="Template" CONTENT="C:\Program Files\MSOffice\Office\html.dot">
|
||||
</HEAD>
|
||||
<BODY LINK="#0000ff" VLINK="#800080">
|
||||
|
||||
<P>Permission to reproduce and create derivative works from the Software ("Software Derivative Works") is hereby granted to you under the copyright of Michael Feathers. Michael Feathers also grants you the right to distribute the Software and Software Derivative Works. </P>
|
||||
<P>Michael Feathers licenses the Software to you on an "AS IS" basis, without warranty of any kind. Michael Feathers HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using the Software and assume all risks associated with the use and distribution of this Software, including but not limited to the risks of program errors, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. MICHAEL FEATHERS WILL NOT BE LIABLE FOR ANY DIRECT DAMAGES OR FOR ANY SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF MICHAEL FEATHERS HAD BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Michael Feathers will not be liable for the loss of, or damage to, your records or data, or any damages claimed by you based on a third party claim. </P>
|
||||
<P>You agree to distribute the Software and any Software Derivatives under a license agreement that: 1) is sufficient to notify all licensees of the Software and Software Derivatives that Michael Feathers assumes no liability for any claim that may arise regarding the Software or Software Derivatives, and 2) that disclaims all warranties, both express and implied, from Michael Feathers regarding the Software and Software Derivatives. (If you include this Agreement with any distribution of the Software and Software Derivatives you will have meet this requirement). You agree that you will not delete any copyright notices in the Software. </P>
|
||||
<P>This Agreement is the exclusive statement of your rights in the Software as provided by Michael Feathers. Except for the licenses granted to you in the second paragraph above, no other licenses are granted hereunder, by estoppel, implication or otherwise. <BR>
|
||||
</P></BODY>
|
||||
</HTML>
|
Binary file not shown.
Before Width: | Height: | Size: 19 KiB |
@ -1,60 +0,0 @@
|
||||
//
|
||||
// CppUnit.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/CppUnit.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_CppUnit_INCLUDED
|
||||
#define CppUnit_CppUnit_INCLUDED
|
||||
|
||||
|
||||
//
|
||||
// Ensure that POCO_DLL is default unless POCO_STATIC is defined
|
||||
//
|
||||
#if defined(_WIN32) && defined(_DLL)
|
||||
#if !defined(POCO_DLL) && !defined(POCO_STATIC)
|
||||
#define POCO_DLL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the CppUnit_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// CppUnit_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(CppUnit_EXPORTS)
|
||||
#define CppUnit_API __declspec(dllexport)
|
||||
#else
|
||||
#define CppUnit_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(CppUnit_API)
|
||||
#if defined (__GNUC__) && (__GNUC__ >= 4)
|
||||
#define CppUnit_API __attribute__ ((visibility ("default")))
|
||||
#else
|
||||
#define CppUnit_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// Turn off some annoying warnings
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4786) // identifier truncation warning
|
||||
#pragma warning(disable:4503) // decorated name length exceeded - mainly a problem with STLPort
|
||||
#pragma warning(disable:4018) // signed/unsigned comparison
|
||||
#pragma warning(disable:4284) // return type for operator -> is not UDT
|
||||
#pragma warning(disable:4251) // ... needs to have dll-interface warning
|
||||
#pragma warning(disable:4273)
|
||||
#pragma warning(disable:4275) // ... non dll-interface class used as base for dll-interface class
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CppUnit_CppUnit_INCLUDED
|
@ -1,141 +0,0 @@
|
||||
//
|
||||
// CppUnitException.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/CppUnitException.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_CppUnitException_INCLUDED
|
||||
#define CppUnit_CppUnitException_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class CppUnit_API CppUnitException: public std::exception
|
||||
/// CppUnitException is an exception that serves
|
||||
/// descriptive strings through its what() method
|
||||
{
|
||||
public:
|
||||
CppUnitException(const std::string& message = "",
|
||||
long lineNumber = CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CPPUNIT_UNKNOWNFILENAME);
|
||||
CppUnitException(const std::string& message,
|
||||
long lineNumber,
|
||||
long data1lineNumber,
|
||||
const std::string& fileName);
|
||||
CppUnitException(const std::string& message,
|
||||
long lineNumber,
|
||||
long data1lineNumber,
|
||||
long data2lineNumber,
|
||||
const std::string& fileName);
|
||||
CppUnitException(const CppUnitException& other);
|
||||
virtual ~CppUnitException() throw();
|
||||
|
||||
CppUnitException& operator = (const CppUnitException& other);
|
||||
|
||||
const char* what() const throw ();
|
||||
|
||||
long lineNumber() const;
|
||||
long data1LineNumber() const;
|
||||
long data2LineNumber() const;
|
||||
const std::string& fileName() const;
|
||||
|
||||
static const std::string CPPUNIT_UNKNOWNFILENAME;
|
||||
static const int CPPUNIT_UNKNOWNLINENUMBER;
|
||||
|
||||
private:
|
||||
std::string _message;
|
||||
long _lineNumber;
|
||||
long _data1lineNumber;
|
||||
long _data2lineNumber;
|
||||
std::string _fileName;
|
||||
};
|
||||
|
||||
|
||||
inline CppUnitException::CppUnitException(const CppUnitException& other): exception (other)
|
||||
{
|
||||
_message = other._message;
|
||||
_lineNumber = other._lineNumber;
|
||||
_data1lineNumber = other._data1lineNumber;
|
||||
_data2lineNumber = other._data2lineNumber;
|
||||
_fileName = other._fileName;
|
||||
}
|
||||
|
||||
|
||||
inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(CPPUNIT_UNKNOWNLINENUMBER), _fileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline CppUnitException::CppUnitException (const std::string& message, long lineNumber, long data1lineNumber, long data2lineNumber, const std::string& fileName): _message(message), _lineNumber(lineNumber), _data1lineNumber(data1lineNumber), _data2lineNumber(data2lineNumber), _fileName(fileName)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline CppUnitException::~CppUnitException () throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline CppUnitException& CppUnitException::operator = (const CppUnitException& other)
|
||||
{
|
||||
exception::operator= (other);
|
||||
|
||||
if (&other != this)
|
||||
{
|
||||
_message = other._message;
|
||||
_lineNumber = other._lineNumber;
|
||||
_data1lineNumber = other._data1lineNumber;
|
||||
_data2lineNumber = other._data2lineNumber;
|
||||
_fileName = other._fileName;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline const char* CppUnitException::what() const throw ()
|
||||
{
|
||||
return _message.c_str();
|
||||
}
|
||||
|
||||
|
||||
inline long CppUnitException::lineNumber() const
|
||||
{
|
||||
return _lineNumber;
|
||||
}
|
||||
|
||||
|
||||
inline long CppUnitException::data1LineNumber() const
|
||||
{
|
||||
return _data1lineNumber;
|
||||
}
|
||||
|
||||
|
||||
inline long CppUnitException::data2LineNumber() const
|
||||
{
|
||||
return _data2lineNumber;
|
||||
}
|
||||
|
||||
|
||||
// The file in which the error occurred
|
||||
inline const std::string& CppUnitException::fileName() const
|
||||
{
|
||||
return _fileName;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_CppUnitException_INCLUDED
|
@ -1,19 +0,0 @@
|
||||
//
|
||||
// Guards.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/Guards.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_Guards_INCLUDED
|
||||
#define CppUnit_Guards_INCLUDED
|
||||
|
||||
|
||||
// Prevent copy construction and assignment for a class
|
||||
#define REFERENCEOBJECT(className) \
|
||||
private: \
|
||||
className(const className& other); \
|
||||
className& operator = (const className& other);
|
||||
|
||||
|
||||
#endif // CppUnit_Guards_INCLUDED
|
@ -1,105 +0,0 @@
|
||||
//
|
||||
// Orthodox.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/Orthodox.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_Orthodox_INCLUDED
|
||||
#define CppUnit_Orthodox_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
/*
|
||||
* Orthodox performs a simple set of tests on an arbitary
|
||||
* class to make sure that it supports at least the
|
||||
* following operations:
|
||||
*
|
||||
* default construction - constructor
|
||||
* equality/inequality - operator== && operator!=
|
||||
* assignment - operator=
|
||||
* negation - operator!
|
||||
* safe passage - copy construction
|
||||
*
|
||||
* If operations for each of these are not declared
|
||||
* the template will not instantiate. If it does
|
||||
* instantiate, tests are performed to make sure
|
||||
* that the operations have correct semantics.
|
||||
*
|
||||
* Adding an orthodox test to a suite is very
|
||||
* easy:
|
||||
*
|
||||
* public: Test *suite () {
|
||||
* TestSuite *suiteOfTests = new TestSuite;
|
||||
* suiteOfTests->addTest (new ComplexNumberTest ("testAdd");
|
||||
* suiteOfTests->addTest (new TestCaller<Orthodox<Complex> > ());
|
||||
* return suiteOfTests;
|
||||
* }
|
||||
*
|
||||
* Templated test cases be very useful when you are want to
|
||||
* make sure that a group of classes have the same form.
|
||||
*
|
||||
* see TestSuite
|
||||
*/
|
||||
template <class ClassUnderTest>
|
||||
class Orthodox: public TestCase
|
||||
{
|
||||
public:
|
||||
Orthodox(): TestCase("Orthodox")
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
ClassUnderTest call(ClassUnderTest object);
|
||||
void runTest ();
|
||||
};
|
||||
|
||||
|
||||
// Run an orthodoxy test
|
||||
template <class ClassUnderTest>
|
||||
void Orthodox<ClassUnderTest>::runTest()
|
||||
{
|
||||
// make sure we have a default constructor
|
||||
ClassUnderTest a, b, c;
|
||||
|
||||
// make sure we have an equality operator
|
||||
assert (a == b);
|
||||
|
||||
// check the inverse
|
||||
b.operator= (a.operator! ());
|
||||
assert (a != b);
|
||||
|
||||
// double inversion
|
||||
b = !!a;
|
||||
assert (a == b);
|
||||
|
||||
// invert again
|
||||
b = !a;
|
||||
|
||||
// check calls
|
||||
c = a;
|
||||
assert (c == call (a));
|
||||
|
||||
c = b;
|
||||
assert (c == call (b));
|
||||
}
|
||||
|
||||
|
||||
// Exercise a call
|
||||
template <class ClassUnderTest>
|
||||
ClassUnderTest Orthodox<ClassUnderTest>::call(ClassUnderTest object)
|
||||
{
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_Orthodox_INCLUDED
|
@ -1,77 +0,0 @@
|
||||
//
|
||||
// RepeatedTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/RepeatedTest.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_RepeatedTest_INCLUDED
|
||||
#define CppUnit_RepeatedTest_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
#include "CppUnit/TestDecorator.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class Test;
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*
|
||||
* A decorator that runs a test repeatedly.
|
||||
* Does not assume ownership of the test it decorates
|
||||
*
|
||||
*/
|
||||
class CppUnit_API RepeatedTest: public TestDecorator
|
||||
{
|
||||
REFERENCEOBJECT (RepeatedTest)
|
||||
|
||||
public:
|
||||
RepeatedTest(Test* test, int timesRepeat): TestDecorator (test), _timesRepeat (timesRepeat)
|
||||
{
|
||||
}
|
||||
|
||||
int countTestCases();
|
||||
std::string toString();
|
||||
void run(TestResult *result);
|
||||
|
||||
private:
|
||||
const int _timesRepeat;
|
||||
};
|
||||
|
||||
|
||||
// Counts the number of test cases that will be run by this test.
|
||||
inline RepeatedTest::countTestCases ()
|
||||
{
|
||||
return TestDecorator::countTestCases() * _timesRepeat;
|
||||
}
|
||||
|
||||
|
||||
// Returns the name of the test instance.
|
||||
inline std::string RepeatedTest::toString()
|
||||
{
|
||||
return TestDecorator::toString() + " (repeated)";
|
||||
}
|
||||
|
||||
|
||||
// Runs a repeated test
|
||||
inline void RepeatedTest::run(TestResult *result)
|
||||
{
|
||||
for (int n = 0; n < _timesRepeat; n++)
|
||||
{
|
||||
if (result->shouldStop())
|
||||
break;
|
||||
|
||||
TestDecorator::run(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_RepeatedTest_INCLUDED
|
@ -1,65 +0,0 @@
|
||||
//
|
||||
// Test.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/Test.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_Test_INCLUDED
|
||||
#define CppUnit_Test_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*
|
||||
* A Test can be run and collect its results.
|
||||
* See TestResult.
|
||||
*
|
||||
*/
|
||||
class CppUnit_API Test
|
||||
{
|
||||
public:
|
||||
virtual ~Test() = 0;
|
||||
virtual void run(TestResult* result) = 0;
|
||||
virtual int countTestCases() = 0;
|
||||
virtual std::string toString() = 0;
|
||||
};
|
||||
|
||||
|
||||
inline Test::~Test()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Runs a test and collects its result in a TestResult instance.
|
||||
inline void Test::run(TestResult *result)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Counts the number of test cases that will be run by this test.
|
||||
inline int Test::countTestCases()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Returns the name of the test instance.
|
||||
inline std::string Test::toString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_Test_INCLUDED
|
@ -1,95 +0,0 @@
|
||||
//
|
||||
// TestCaller.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestCaller.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestCaller_INCLUDED
|
||||
#define CppUnit_TestCaller_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "Guards.h"
|
||||
#include "TestCase.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
/*
|
||||
* A test caller provides access to a test case method
|
||||
* on a test case class. Test callers are useful when
|
||||
* you want to run an individual test or add it to a
|
||||
* suite.
|
||||
*
|
||||
* Here is an example:
|
||||
*
|
||||
* class MathTest : public TestCase {
|
||||
* ...
|
||||
* public:
|
||||
* void setUp ();
|
||||
* void tearDown ();
|
||||
*
|
||||
* void testAdd ();
|
||||
* void testSubtract ();
|
||||
* };
|
||||
*
|
||||
* Test *MathTest::suite () {
|
||||
* TestSuite *suite = new TestSuite;
|
||||
*
|
||||
* suite->addTest (new TestCaller<MathTest> ("testAdd", testAdd));
|
||||
* return suite;
|
||||
* }
|
||||
*
|
||||
* You can use a TestCaller to bind any test method on a TestCase
|
||||
* class, as long as it returns accepts void and returns void.
|
||||
*
|
||||
* See TestCase
|
||||
*/
|
||||
template <class Fixture>
|
||||
class TestCaller: public TestCase
|
||||
{
|
||||
REFERENCEOBJECT (TestCaller)
|
||||
|
||||
typedef void (Fixture::*TestMethod)();
|
||||
|
||||
public:
|
||||
TestCaller(const std::string& name, TestMethod test):
|
||||
TestCase(name),
|
||||
_test(test),
|
||||
_fixture(new Fixture(name))
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void runTest()
|
||||
{
|
||||
(_fixture.get()->*_test)();
|
||||
}
|
||||
|
||||
void setUp()
|
||||
{
|
||||
_fixture.get()->setUp();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
_fixture.get()->tearDown();
|
||||
}
|
||||
|
||||
private:
|
||||
TestMethod _test;
|
||||
std::unique_ptr<Fixture> _fixture;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#define CppUnit_addTest(suite, cls, mth) \
|
||||
suite->addTest(new CppUnit::TestCaller<cls>(#mth, &cls::mth))
|
||||
|
||||
|
||||
#endif // CppUnit_TestCaller_INCLUDED
|
@ -1,257 +0,0 @@
|
||||
//
|
||||
// TestCase.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestCase.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestCase_INCLUDED
|
||||
#define CppUnit_TestCase_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
#include "CppUnit/Test.h"
|
||||
#include "CppUnit/CppUnitException.h"
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*
|
||||
* A test case defines the fixture to run multiple tests. To define a test case
|
||||
* 1) implement a subclass of TestCase
|
||||
* 2) define instance variables that store the state of the fixture
|
||||
* 3) initialize the fixture state by overriding setUp
|
||||
* 4) clean-up after a test by overriding tearDown.
|
||||
*
|
||||
* Each test runs in its own fixture so there
|
||||
* can be no side effects among test runs.
|
||||
* Here is an example:
|
||||
*
|
||||
* class MathTest : public TestCase {
|
||||
* protected: int m_value1;
|
||||
* protected: int m_value2;
|
||||
*
|
||||
* public: MathTest (std::string name)
|
||||
* : TestCase (name) {
|
||||
* }
|
||||
*
|
||||
* protected: void setUp () {
|
||||
* m_value1 = 2;
|
||||
* m_value2 = 3;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* For each test implement a method which interacts
|
||||
* with the fixture. Verify the expected results with assertions specified
|
||||
* by calling assert on the expression you want to test:
|
||||
*
|
||||
* protected: void testAdd () {
|
||||
* int result = value1 + value2;
|
||||
* assert (result == 5);
|
||||
* }
|
||||
*
|
||||
* Once the methods are defined you can run them. To do this, use
|
||||
* a TestCaller.
|
||||
*
|
||||
* Test *test = new TestCaller<MathTest>("testAdd", MathTest::testAdd);
|
||||
* test->run ();
|
||||
*
|
||||
*
|
||||
* The tests to be run can be collected into a TestSuite. CppUnit provides
|
||||
* different test runners which can run a test suite and collect the results.
|
||||
* The test runners expect a static method suite as the entry
|
||||
* point to get a test to run.
|
||||
*
|
||||
* public: static MathTest::suite () {
|
||||
* TestSuite *suiteOfTests = new TestSuite;
|
||||
* suiteOfTests->addTest(new TestCaller<MathTest>("testAdd", testAdd));
|
||||
* suiteOfTests->addTest(new TestCaller<MathTest>("testDivideByZero", testDivideByZero));
|
||||
* return suiteOfTests;
|
||||
* }
|
||||
*
|
||||
* Note that the caller of suite assumes lifetime control
|
||||
* for the returned suite.
|
||||
*
|
||||
* see TestResult, TestSuite and TestCaller
|
||||
*
|
||||
*/
|
||||
class CppUnit_API TestCase: public Test
|
||||
{
|
||||
REFERENCEOBJECT (TestCase)
|
||||
|
||||
public:
|
||||
TestCase(const std::string& Name);
|
||||
~TestCase();
|
||||
|
||||
virtual void run(TestResult* result);
|
||||
virtual TestResult* run();
|
||||
virtual int countTestCases();
|
||||
const std::string& name() const;
|
||||
std::string toString();
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
protected:
|
||||
virtual void runTest();
|
||||
TestResult* defaultResult();
|
||||
|
||||
void assertImplementation(bool condition,
|
||||
const std::string& conditionExpression = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void loop1assertImplementation(bool condition,
|
||||
const std::string& conditionExpression = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
long dataLineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void loop2assertImplementation(bool condition,
|
||||
const std::string& conditionExpression = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
long data1LineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
long data2LineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void assertEquals(long expected,
|
||||
long actual,
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void assertEquals(double expected,
|
||||
double actual,
|
||||
double delta,
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void assertEquals(const std::string& expected,
|
||||
const std::string& actual,
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void assertEquals(const void* expected,
|
||||
const void* actual,
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
std::string notEqualsMessage(long expected, long actual);
|
||||
std::string notEqualsMessage(double expected, double actual);
|
||||
std::string notEqualsMessage(const void* expected, const void* actual);
|
||||
std::string notEqualsMessage(const std::string& expected, const std::string& actual);
|
||||
|
||||
void assertNotNull(const void* pointer,
|
||||
const std::string& pointerExpression = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void assertNull(const void* pointer,
|
||||
const std::string& pointerExpression = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void fail(const std::string& message = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
void warn(const std::string& message = "",
|
||||
long lineNumber = CppUnitException::CPPUNIT_UNKNOWNLINENUMBER,
|
||||
const std::string& fileName = CppUnitException::CPPUNIT_UNKNOWNFILENAME);
|
||||
|
||||
|
||||
private:
|
||||
const std::string _name;
|
||||
};
|
||||
|
||||
|
||||
// Constructs a test case
|
||||
inline TestCase::TestCase(const std::string& name): _name (name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Destructs a test case
|
||||
inline TestCase::~TestCase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Returns a count of all the tests executed
|
||||
inline int TestCase::countTestCases()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Returns the name of the test case
|
||||
inline const std::string& TestCase::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
// A hook for fixture set up
|
||||
inline void TestCase::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// A hook for fixture tear down
|
||||
inline void TestCase::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Returns the name of the test case instance
|
||||
inline std::string TestCase::toString()
|
||||
{
|
||||
const std::type_info& thisClass = typeid(*this);
|
||||
return std::string(thisClass.name()) + "." + name();
|
||||
}
|
||||
|
||||
|
||||
// A set of macros which allow us to get the line number
|
||||
// and file name at the point of an error.
|
||||
// Just goes to show that preprocessors do have some
|
||||
// redeeming qualities.
|
||||
#undef assert
|
||||
#define assert(condition) \
|
||||
(this->assertImplementation((condition), (#condition), __LINE__, __FILE__))
|
||||
|
||||
#define loop_1_assert(data1line, condition) \
|
||||
(this->loop1assertImplementation((condition), (#condition), __LINE__, data1line, __FILE__))
|
||||
|
||||
#define loop_2_assert(data1line, data2line, condition) \
|
||||
(this->loop2assertImplementation((condition), (#condition), __LINE__, data1line, data2line, __FILE__))
|
||||
|
||||
#define assertEqualDelta(expected, actual, delta) \
|
||||
(this->assertEquals((expected), (actual), (delta), __LINE__, __FILE__))
|
||||
|
||||
#define assertEqual(expected, actual) \
|
||||
(this->assertEquals((expected), (actual), __LINE__, __FILE__))
|
||||
|
||||
#define assertNullPtr(ptr) \
|
||||
(this->assertNull((ptr), #ptr, __LINE__, __FILE__))
|
||||
|
||||
#define assertNotNullPtr(ptr) \
|
||||
(this->assertNotNull((ptr), #ptr, __LINE__, __FILE__))
|
||||
|
||||
#define failmsg(msg) \
|
||||
(this->fail(msg, __LINE__, __FILE__))
|
||||
|
||||
#define warnmsg(msg) \
|
||||
(this->fail(msg, __LINE__, __FILE__))
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TestCase_INCLUDED
|
@ -1,52 +0,0 @@
|
||||
//
|
||||
// TestDecorator.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestDecorator.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestDecorator_INCLUDED
|
||||
#define CppUnit_TestDecorator_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
#include "CppUnit/Test.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*
|
||||
* A Decorator for Tests
|
||||
*
|
||||
* Does not assume ownership of the test it decorates
|
||||
*
|
||||
*/
|
||||
class CppUnit_API TestDecorator: public Test
|
||||
{
|
||||
REFERENCEOBJECT(TestDecorator)
|
||||
|
||||
public:
|
||||
TestDecorator(Test* test);
|
||||
|
||||
virtual ~TestDecorator();
|
||||
|
||||
int countTestCases();
|
||||
|
||||
void run(TestResult* result);
|
||||
|
||||
std::string toString();
|
||||
|
||||
protected:
|
||||
Test* _test;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TestDecorator_INCLUDED
|
@ -1,86 +0,0 @@
|
||||
//
|
||||
// TestFailure.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestFailure.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestFailure_INCLUDED
|
||||
#define CppUnit_TestFailure_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/CppUnitException.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class Test;
|
||||
|
||||
|
||||
/*
|
||||
* A TestFailure collects a failed test together with
|
||||
* the caught exception.
|
||||
*
|
||||
* TestFailure assumes lifetime control for any exception
|
||||
* passed to it. The lifetime of tests is handled by
|
||||
* their TestSuite (if they have been added to one) or
|
||||
* whomever creates them.
|
||||
*
|
||||
* see TestResult
|
||||
* see TestSuite
|
||||
*
|
||||
*/
|
||||
class CppUnit_API TestFailure
|
||||
{
|
||||
REFERENCEOBJECT (TestFailure)
|
||||
|
||||
public:
|
||||
TestFailure(Test* failedTest, CppUnitException* thrownException);
|
||||
~TestFailure();
|
||||
|
||||
Test* failedTest();
|
||||
CppUnitException* thrownException();
|
||||
std::string toString();
|
||||
|
||||
protected:
|
||||
Test* _failedTest;
|
||||
CppUnitException *_thrownException;
|
||||
};
|
||||
|
||||
|
||||
// Constructs a TestFailure with the given test and exception.
|
||||
inline TestFailure::TestFailure(Test* failedTest, CppUnitException* thrownException): _failedTest(failedTest), _thrownException(thrownException)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Deletes the owned exception.
|
||||
inline TestFailure::~TestFailure()
|
||||
{
|
||||
delete _thrownException;
|
||||
}
|
||||
|
||||
|
||||
// Gets the failed test.
|
||||
inline Test* TestFailure::failedTest()
|
||||
{
|
||||
return _failedTest;
|
||||
}
|
||||
|
||||
|
||||
// Gets the thrown exception.
|
||||
inline CppUnitException* TestFailure::thrownException()
|
||||
{
|
||||
return _thrownException;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TestFailure_INCLUDED
|
||||
|
||||
|
@ -1,231 +0,0 @@
|
||||
//
|
||||
// TestResult.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestResult.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestResult_INCLUDED
|
||||
#define CppUnit_TestResult_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
#include "CppUnit/TestFailure.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class CppUnitException;
|
||||
class Test;
|
||||
|
||||
|
||||
/*
|
||||
* A TestResult collects the results of executing a test case. It is an
|
||||
* instance of the Collecting Parameter pattern.
|
||||
*
|
||||
* The test framework distinguishes between failures and errors.
|
||||
* A failure is anticipated and checked for with assertions. Errors are
|
||||
* unanticipated problems signified by exceptions that are not generated
|
||||
* by the framework.
|
||||
*
|
||||
* TestResult supplies a template method 'setSynchronizationObject ()'
|
||||
* so that subclasses can provide mutual exclusion in the face of multiple
|
||||
* threads. This can be useful when tests execute in one thread and
|
||||
* they fill a subclass of TestResult which effects change in another
|
||||
* thread. To have mutual exclusion, override setSynchronizationObject ()
|
||||
* and make sure that you create an instance of ExclusiveZone at the
|
||||
* beginning of each method.
|
||||
*
|
||||
* see Test
|
||||
*/
|
||||
class CppUnit_API TestResult
|
||||
{
|
||||
REFERENCEOBJECT (TestResult)
|
||||
|
||||
public:
|
||||
TestResult();
|
||||
virtual ~TestResult();
|
||||
|
||||
virtual void addError(Test* test, CppUnitException* e);
|
||||
virtual void addFailure(Test* test, CppUnitException* e);
|
||||
virtual void startTest(Test* test);
|
||||
virtual void endTest(Test* test);
|
||||
virtual int runTests();
|
||||
virtual int testErrors();
|
||||
virtual int testFailures();
|
||||
virtual bool wasSuccessful();
|
||||
virtual bool shouldStop();
|
||||
virtual void stop();
|
||||
|
||||
virtual std::vector<TestFailure*>& errors();
|
||||
virtual std::vector<TestFailure*>& failures();
|
||||
|
||||
class SynchronizationObject
|
||||
{
|
||||
public:
|
||||
SynchronizationObject()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~SynchronizationObject()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void lock()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void unlock()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ExclusiveZone
|
||||
{
|
||||
SynchronizationObject* m_syncObject;
|
||||
|
||||
public:
|
||||
ExclusiveZone(SynchronizationObject* syncObject): m_syncObject(syncObject)
|
||||
{
|
||||
m_syncObject->lock();
|
||||
}
|
||||
|
||||
~ExclusiveZone()
|
||||
{
|
||||
m_syncObject->unlock();
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
virtual void setSynchronizationObject(SynchronizationObject* syncObject);
|
||||
|
||||
std::vector<TestFailure*> _errors;
|
||||
std::vector<TestFailure*> _failures;
|
||||
int _runTests;
|
||||
bool _stop;
|
||||
SynchronizationObject* _syncObject;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Construct a TestResult
|
||||
inline TestResult::TestResult(): _syncObject(new SynchronizationObject())
|
||||
{
|
||||
_runTests = 0;
|
||||
_stop = false;
|
||||
}
|
||||
|
||||
|
||||
// Adds an error to the list of errors. The passed in exception
|
||||
// caused the error
|
||||
inline void TestResult::addError(Test* test, CppUnitException* e)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
_errors.push_back(new TestFailure(test, e));
|
||||
}
|
||||
|
||||
|
||||
// Adds a failure to the list of failures. The passed in exception
|
||||
// caused the failure.
|
||||
inline void TestResult::addFailure(Test* test, CppUnitException* e)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
_failures.push_back(new TestFailure(test, e));
|
||||
}
|
||||
|
||||
|
||||
// Informs the result that a test will be started.
|
||||
inline void TestResult::startTest(Test* test)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
_runTests++;
|
||||
}
|
||||
|
||||
|
||||
// Informs the result that a test was completed.
|
||||
inline void TestResult::endTest(Test* test)
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
}
|
||||
|
||||
|
||||
// Gets the number of run tests.
|
||||
inline int TestResult::runTests()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return _runTests;
|
||||
}
|
||||
|
||||
|
||||
// Gets the number of detected errors.
|
||||
inline int TestResult::testErrors()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return (int) _errors.size();
|
||||
}
|
||||
|
||||
|
||||
// Gets the number of detected failures.
|
||||
inline int TestResult::testFailures()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return (int) _failures.size();
|
||||
}
|
||||
|
||||
|
||||
// Returns whether the entire test was successful or not.
|
||||
inline bool TestResult::wasSuccessful()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return _failures.size() == 0 && _errors.size () == 0;
|
||||
}
|
||||
|
||||
|
||||
// Returns a std::vector of the errors.
|
||||
inline std::vector<TestFailure*>& TestResult::errors()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return _errors;
|
||||
}
|
||||
|
||||
|
||||
// Returns a std::vector of the failures.
|
||||
inline std::vector<TestFailure*>& TestResult::failures()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return _failures;
|
||||
}
|
||||
|
||||
|
||||
// Returns whether testing should be stopped
|
||||
inline bool TestResult::shouldStop()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
return _stop;
|
||||
}
|
||||
|
||||
|
||||
// Stop testing
|
||||
inline void TestResult::stop()
|
||||
{
|
||||
ExclusiveZone zone(_syncObject);
|
||||
_stop = true;
|
||||
}
|
||||
|
||||
|
||||
// Accept a new synchronization object for protection of this instance
|
||||
// TestResult assumes ownership of the object
|
||||
inline void TestResult::setSynchronizationObject(SynchronizationObject* syncObject)
|
||||
{
|
||||
delete _syncObject;
|
||||
_syncObject = syncObject;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TestResult_INCLUDED
|
@ -1,103 +0,0 @@
|
||||
//
|
||||
// TestRunner.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestRunner.h#2 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestRunner_INCLUDED
|
||||
#define CppUnit_TestRunner_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#if defined(POCO_VXWORKS)
|
||||
#include <cstdarg>
|
||||
#endif
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class Test;
|
||||
|
||||
|
||||
/*
|
||||
* A command line based tool to run tests.
|
||||
* TestRunner expects as its only argument the name of a TestCase class.
|
||||
* TestRunner prints out a trace as the tests are executed followed by a
|
||||
* summary at the end.
|
||||
*
|
||||
* You can add to the tests that the TestRunner knows about by
|
||||
* making additional calls to "addTest (...)" in main.
|
||||
*
|
||||
* Here is the synopsis:
|
||||
*
|
||||
* TestRunner [-all] [-print] [-wait] ExampleTestCase
|
||||
*
|
||||
*/
|
||||
class CppUnit_API TestRunner
|
||||
{
|
||||
typedef std::pair<std::string, Test*> Mapping;
|
||||
typedef std::vector<Mapping> Mappings;
|
||||
|
||||
public:
|
||||
TestRunner();
|
||||
TestRunner(std::ostream& ostr);
|
||||
~TestRunner();
|
||||
|
||||
bool run(const std::vector<std::string>& args);
|
||||
void addTest(const std::string& name, Test* test);
|
||||
|
||||
protected:
|
||||
bool run(Test* test);
|
||||
void printBanner();
|
||||
void print(const std::string& name, Test* pTest, int indent);
|
||||
Test* find(const std::string& name, Test* pTest, const std::string& testName);
|
||||
|
||||
private:
|
||||
std::ostream& _ostr;
|
||||
Mappings _mappings;
|
||||
};
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#if defined(POCO_VXWORKS)
|
||||
#define CppUnitMain(testCase) \
|
||||
int testCase##Runner(const char* arg0, ...) \
|
||||
{ \
|
||||
std::vector<std::string> args; \
|
||||
args.push_back(#testCase "Runner"); \
|
||||
args.push_back(std::string(arg0)); \
|
||||
va_list vargs; \
|
||||
va_start(vargs, arg0); \
|
||||
const char* arg = va_arg(vargs, const char*); \
|
||||
while (arg) \
|
||||
{ \
|
||||
args.push_back(std::string(arg)); \
|
||||
arg = va_arg(vargs, const char*); \
|
||||
} \
|
||||
va_end(vargs); \
|
||||
CppUnit::TestRunner runner; \
|
||||
runner.addTest(#testCase, testCase::suite()); \
|
||||
return runner.run(args) ? 0 : 1; \
|
||||
}
|
||||
#else
|
||||
#define CppUnitMain(testCase) \
|
||||
int main(int ac, char **av) \
|
||||
{ \
|
||||
std::vector<std::string> args; \
|
||||
for (int i = 0; i < ac; ++i) \
|
||||
args.push_back(std::string(av[i])); \
|
||||
CppUnit::TestRunner runner; \
|
||||
runner.addTest(#testCase, testCase::suite()); \
|
||||
return runner.run(args) ? 0 : 1; \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // CppUnit_TestRunner_INCLUDED
|
@ -1,57 +0,0 @@
|
||||
//
|
||||
// TestSetup.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestSetup.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSetup_INCLUDED
|
||||
#define CppUnit_TestSetup_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
#include "CppUnit/TestDecorator.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class Test;
|
||||
class TestResult;
|
||||
|
||||
|
||||
class CppUnit_API TestSetup: public TestDecorator
|
||||
{
|
||||
REFERENCEOBJECT (TestSetup)
|
||||
|
||||
public:
|
||||
TestSetup(Test* test): TestDecorator(test)
|
||||
{
|
||||
}
|
||||
|
||||
void run(TestResult* result);
|
||||
|
||||
protected:
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline void TestSetup::run(TestResult* result)
|
||||
{
|
||||
setUp();
|
||||
TestDecorator::run(result);
|
||||
tearDown();
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TestSetup_INCLUDED
|
@ -1,98 +0,0 @@
|
||||
//
|
||||
// TestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TestSuite.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TestSuite_INCLUDED
|
||||
#define CppUnit_TestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/Guards.h"
|
||||
#include "CppUnit/Test.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class TestResult;
|
||||
|
||||
|
||||
/*
|
||||
* A TestSuite is a Composite of Tests.
|
||||
* It runs a collection of test cases. Here is an example.
|
||||
*
|
||||
* TestSuite *suite= new TestSuite();
|
||||
* suite->addTest(new TestCaller<MathTest> ("testAdd", testAdd));
|
||||
* suite->addTest(new TestCaller<MathTest> ("testDivideByZero", testDivideByZero));
|
||||
*
|
||||
* Note that TestSuites assume lifetime
|
||||
* control for any tests added to them.
|
||||
*
|
||||
* see Test and TestCaller
|
||||
*/
|
||||
class CppUnit_API TestSuite: public Test
|
||||
{
|
||||
REFERENCEOBJECT (TestSuite)
|
||||
|
||||
public:
|
||||
TestSuite(const std::string& name = "");
|
||||
~TestSuite();
|
||||
|
||||
void run(TestResult* result);
|
||||
int countTestCases();
|
||||
void addTest(Test* test);
|
||||
std::string toString();
|
||||
|
||||
virtual void deleteContents();
|
||||
|
||||
const std::vector<Test*> tests() const;
|
||||
|
||||
private:
|
||||
std::vector<Test*> _tests;
|
||||
const std::string _name;
|
||||
};
|
||||
|
||||
|
||||
// Default constructor
|
||||
inline TestSuite::TestSuite(const std::string& name): _name(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
inline TestSuite::~TestSuite()
|
||||
{
|
||||
deleteContents();
|
||||
}
|
||||
|
||||
|
||||
// Adds a test to the suite.
|
||||
inline void TestSuite::addTest(Test* test)
|
||||
{
|
||||
_tests.push_back(test);
|
||||
}
|
||||
|
||||
|
||||
// Returns a std::string representation of the test suite.
|
||||
inline std::string TestSuite::toString()
|
||||
{
|
||||
return "suite " + _name;
|
||||
}
|
||||
|
||||
|
||||
// Returns all tests
|
||||
inline const std::vector<Test*> TestSuite::tests() const
|
||||
{
|
||||
return _tests;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TestSuite_INCLUDED
|
@ -1,56 +0,0 @@
|
||||
//
|
||||
// TextTestResult.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/TextTestResult.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_TextTestResult_INCLUDED
|
||||
#define CppUnit_TextTestResult_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include "CppUnit/TestResult.h"
|
||||
#include <set>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
class CppUnit_API TextTestResult: public TestResult
|
||||
{
|
||||
public:
|
||||
TextTestResult();
|
||||
TextTestResult(std::ostream& ostr);
|
||||
|
||||
virtual void addError(Test* test, CppUnitException* e);
|
||||
virtual void addFailure(Test* test, CppUnitException* e);
|
||||
virtual void startTest(Test* test);
|
||||
virtual void print(std::ostream& stream);
|
||||
virtual void printErrors(std::ostream& stream);
|
||||
virtual void printFailures(std::ostream& stream);
|
||||
virtual void printHeader(std::ostream& stream);
|
||||
|
||||
protected:
|
||||
std::string shortName(const std::string& testName);
|
||||
void setup();
|
||||
|
||||
private:
|
||||
std::ostream& _ostr;
|
||||
std::set<std::string> _ignored;
|
||||
};
|
||||
|
||||
|
||||
/* insertion operator for easy output */
|
||||
inline std::ostream& operator<< (std::ostream& stream, TextTestResult& result)
|
||||
{
|
||||
result.print(stream);
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_TextTestResult_INCLUDED
|
@ -1,73 +0,0 @@
|
||||
//
|
||||
// estring.h
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/include/CppUnit/estring.h#1 $
|
||||
//
|
||||
|
||||
|
||||
#ifndef CppUnit_estring_INCLUDED
|
||||
#define CppUnit_estring_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/CppUnit.h"
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Create a std::string from a const char pointer
|
||||
inline std::string estring(const char *cstring)
|
||||
{
|
||||
return std::string(cstring);
|
||||
}
|
||||
|
||||
|
||||
// Create a std::string from a std::string (for uniformities' sake)
|
||||
inline std::string estring(std::string& expandedString)
|
||||
{
|
||||
return expandedString;
|
||||
}
|
||||
|
||||
|
||||
// Create a std::string from an int
|
||||
inline std::string estring(int number)
|
||||
{
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%d", number);
|
||||
return std::string (buffer);
|
||||
}
|
||||
|
||||
|
||||
// Create a string from a long
|
||||
inline std::string estring(long number)
|
||||
{
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%ld", number);
|
||||
return std::string (buffer);
|
||||
}
|
||||
|
||||
|
||||
// Create a std::string from a double
|
||||
inline std::string estring(double number)
|
||||
{
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%lf", number);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
|
||||
// Create a std::string from a double
|
||||
inline std::string estring(const void* ptr)
|
||||
{
|
||||
char buffer[50];
|
||||
sprintf(buffer, "%p", ptr);
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
||||
|
||||
|
||||
#endif // CppUnit_estring_INCLUDED
|
@ -1,18 +0,0 @@
|
||||
//
|
||||
// CppUnitException.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/CppUnitException.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/CppUnitException.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
const std::string CppUnitException::CPPUNIT_UNKNOWNFILENAME = "<unknown>";
|
||||
const int CppUnitException::CPPUNIT_UNKNOWNLINENUMBER = -1;
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,189 +0,0 @@
|
||||
//
|
||||
// TestCase.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TestCase.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include <stdexcept>
|
||||
#include <math.h>
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "CppUnit/TestResult.h"
|
||||
#include "CppUnit/estring.h"
|
||||
#include <typeinfo>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Create a default TestResult
|
||||
TestResult* TestCase::defaultResult()
|
||||
{
|
||||
return new TestResult;
|
||||
}
|
||||
|
||||
|
||||
// Check for a failed general assertion
|
||||
void TestCase::assertImplementation(bool condition, const std::string& conditionExpression, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (!condition)
|
||||
throw CppUnitException(conditionExpression, lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
void TestCase::loop1assertImplementation(bool condition, const std::string& conditionExpression, long lineNumber, long data1lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (!condition)
|
||||
throw CppUnitException(conditionExpression, lineNumber, data1lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
void TestCase::loop2assertImplementation(bool condition, const std::string& conditionExpression, long lineNumber, long data1lineNumber, long data2lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (!condition)
|
||||
throw CppUnitException(conditionExpression, lineNumber, data1lineNumber, data2lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
// Check for a failed equality assertion
|
||||
void TestCase::assertEquals(long expected, long actual, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (expected != actual)
|
||||
assertImplementation(false, notEqualsMessage(expected, actual), lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
// Check for a failed equality assertion
|
||||
void TestCase::assertEquals(double expected, double actual, double delta, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (fabs(expected - actual) > delta)
|
||||
assertImplementation(false, notEqualsMessage(expected, actual), lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
// Check for a failed equality assertion
|
||||
void TestCase::assertEquals(const void* expected, const void* actual, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (expected != actual)
|
||||
assertImplementation(false, notEqualsMessage(expected, actual), lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
// Check for a failed equality assertion
|
||||
void TestCase::assertEquals(const std::string& expected, const std::string& actual, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (expected != actual)
|
||||
assertImplementation(false, notEqualsMessage(expected, actual), lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
void TestCase::assertNotNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (pointer == NULL)
|
||||
throw CppUnitException(pointerExpression + " must not be NULL", lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
void TestCase::assertNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
if (pointer != NULL)
|
||||
throw CppUnitException(pointerExpression + " must be NULL", lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
void TestCase::fail(const std::string& message, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
throw CppUnitException(std::string("fail: ") + message, lineNumber, fileName);
|
||||
}
|
||||
|
||||
|
||||
void TestCase::warn(const std::string& message, long lineNumber, const std::string& fileName)
|
||||
{
|
||||
std::cout << "Warning [" << fileName << ':' << lineNumber << "]: " << message << std::endl;
|
||||
}
|
||||
|
||||
|
||||
// Run the test and catch any exceptions that are triggered by it
|
||||
void TestCase::run(TestResult *result)
|
||||
{
|
||||
result->startTest(this);
|
||||
|
||||
setUp();
|
||||
try
|
||||
{
|
||||
runTest();
|
||||
}
|
||||
catch (CppUnitException& e)
|
||||
{
|
||||
CppUnitException* copy = new CppUnitException(e);
|
||||
result->addFailure(this, copy);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::string msg(typeid(e).name());
|
||||
msg.append(": ");
|
||||
msg.append(e.what());
|
||||
result->addError(this, new CppUnitException(msg));
|
||||
|
||||
}
|
||||
#if !defined(_WIN32)
|
||||
catch (...)
|
||||
{
|
||||
CppUnitException *e = new CppUnitException ("unknown exception");
|
||||
result->addError (this, e);
|
||||
}
|
||||
#endif
|
||||
tearDown ();
|
||||
result->endTest(this);
|
||||
}
|
||||
|
||||
|
||||
// A default run method
|
||||
TestResult* TestCase::run()
|
||||
{
|
||||
TestResult* result = defaultResult();
|
||||
|
||||
run(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// All the work for runTest is deferred to subclasses
|
||||
void TestCase::runTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Build a message about a failed equality check
|
||||
std::string TestCase::notEqualsMessage(long expected, long actual)
|
||||
{
|
||||
return "expected: " + estring(expected) + " but was: " + estring(actual);
|
||||
}
|
||||
|
||||
|
||||
// Build a message about a failed equality check
|
||||
std::string TestCase::notEqualsMessage(double expected, double actual)
|
||||
{
|
||||
return "expected: " + estring(expected) + " but was: " + estring(actual);
|
||||
}
|
||||
|
||||
|
||||
// Build a message about a failed equality check
|
||||
std::string TestCase::notEqualsMessage(const void* expected, const void* actual)
|
||||
{
|
||||
return "expected: " + estring(expected) + " but was: " + estring(actual);
|
||||
}
|
||||
|
||||
|
||||
// Build a message about a failed equality check
|
||||
std::string TestCase::notEqualsMessage(const std::string& expected, const std::string& actual)
|
||||
{
|
||||
return "expected: \"" + expected + "\" but was: \"" + actual + "\"";
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,43 +0,0 @@
|
||||
//
|
||||
// TestDecorator.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TestDecorator.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestDecorator.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
TestDecorator::TestDecorator(Test* test)
|
||||
{
|
||||
_test = test;
|
||||
}
|
||||
|
||||
|
||||
TestDecorator::~TestDecorator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int TestDecorator::countTestCases()
|
||||
{
|
||||
return _test->countTestCases();
|
||||
}
|
||||
|
||||
|
||||
void TestDecorator::run(TestResult* result)
|
||||
{
|
||||
_test->run(result);
|
||||
}
|
||||
|
||||
|
||||
std::string TestDecorator::toString()
|
||||
{
|
||||
return _test->toString();
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,22 +0,0 @@
|
||||
//
|
||||
// TestFailure.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TestFailure.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestFailure.h"
|
||||
#include "CppUnit/Test.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Returns a short description of the failure.
|
||||
std::string TestFailure::toString()
|
||||
{
|
||||
return _failedTest->toString () + ": " + _thrownException->what();
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,29 +0,0 @@
|
||||
//
|
||||
// TestResult.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TestResult.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestResult.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Destroys a test result
|
||||
TestResult::~TestResult()
|
||||
{
|
||||
std::vector<TestFailure*>::iterator it;
|
||||
|
||||
for (it = _errors.begin(); it != _errors.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
for (it = _failures.begin(); it != _failures.end(); ++it)
|
||||
delete *it;
|
||||
|
||||
delete _syncObject;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,188 +0,0 @@
|
||||
//
|
||||
// TestRunner.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TestRunner.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "CppUnit/Test.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "CppUnit/TextTestResult.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
TestRunner::TestRunner():
|
||||
_ostr(std::cout)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestRunner::TestRunner(std::ostream& ostr):
|
||||
_ostr(ostr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TestRunner::~TestRunner()
|
||||
{
|
||||
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
|
||||
void TestRunner::printBanner()
|
||||
{
|
||||
_ostr
|
||||
<< "Usage: driver [-all] [-print] [-wait] [name] ..." << std::endl
|
||||
<< " where name is the name of a test case class" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool TestRunner::run(const std::vector<std::string>& args)
|
||||
{
|
||||
std::string testCase;
|
||||
int numberOfTests = 0;
|
||||
bool success = true;
|
||||
bool all = false;
|
||||
bool wait = false;
|
||||
bool printed = false;
|
||||
|
||||
for (int i = 1; i < args.size(); i++)
|
||||
{
|
||||
const std::string& arg = args[i];
|
||||
if (arg == "-wait")
|
||||
{
|
||||
wait = true;
|
||||
continue;
|
||||
}
|
||||
else if (arg == "-all")
|
||||
{
|
||||
all = true;
|
||||
continue;
|
||||
}
|
||||
else if (arg == "-print")
|
||||
{
|
||||
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
|
||||
{
|
||||
print(it->first, it->second, 0);
|
||||
}
|
||||
printed = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!all)
|
||||
{
|
||||
testCase = arg;
|
||||
|
||||
if (testCase == "")
|
||||
{
|
||||
printBanner();
|
||||
return false;
|
||||
}
|
||||
|
||||
Test* testToRun = 0;
|
||||
for (Mappings::iterator it = _mappings.begin(); !testToRun && it != _mappings.end(); ++it)
|
||||
{
|
||||
testToRun = find(testCase, it->second, it->first);
|
||||
}
|
||||
if (testToRun)
|
||||
{
|
||||
if (!run(testToRun)) success = false;
|
||||
}
|
||||
numberOfTests++;
|
||||
|
||||
if (!testToRun)
|
||||
{
|
||||
_ostr << "Test " << testCase << " not found." << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (all)
|
||||
{
|
||||
for (Mappings::iterator it = _mappings.begin(); it != _mappings.end(); ++it)
|
||||
{
|
||||
if (!run(it->second)) success = false;
|
||||
numberOfTests++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberOfTests == 0 && !printed)
|
||||
{
|
||||
printBanner();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (wait)
|
||||
{
|
||||
_ostr << "<RETURN> to continue" << std::endl;
|
||||
std::cin.get();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
bool TestRunner::run(Test* test)
|
||||
{
|
||||
TextTestResult result(_ostr);
|
||||
|
||||
test->run(&result);
|
||||
_ostr << result << std::endl;
|
||||
|
||||
return result.wasSuccessful();
|
||||
}
|
||||
|
||||
|
||||
void TestRunner::addTest(const std::string& name, Test* test)
|
||||
{
|
||||
_mappings.push_back(Mapping(name, test));
|
||||
}
|
||||
|
||||
|
||||
void TestRunner::print(const std::string& name, Test* pTest, int indent)
|
||||
{
|
||||
for (int i = 0; i < indent; ++i)
|
||||
_ostr << " ";
|
||||
_ostr << name << std::endl;
|
||||
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
|
||||
if (pSuite)
|
||||
{
|
||||
const std::vector<Test*>& tests = pSuite->tests();
|
||||
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
|
||||
{
|
||||
print((*it)->toString(), *it, indent + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Test* TestRunner::find(const std::string& name, Test* pTest, const std::string& testName)
|
||||
{
|
||||
if (testName.find(name) != std::string::npos)
|
||||
{
|
||||
return pTest;
|
||||
}
|
||||
else
|
||||
{
|
||||
TestSuite* pSuite = dynamic_cast<TestSuite*>(pTest);
|
||||
if (pSuite)
|
||||
{
|
||||
const std::vector<Test*>& tests = pSuite->tests();
|
||||
for (std::vector<Test*>::const_iterator it = tests.begin(); it != tests.end(); ++it)
|
||||
{
|
||||
Test* result = find(name, *it, (*it)->toString());
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,49 +0,0 @@
|
||||
//
|
||||
// TestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TestSuite.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "CppUnit/TestResult.h"
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
// Deletes all tests in the suite.
|
||||
void TestSuite::deleteContents()
|
||||
{
|
||||
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
|
||||
delete *it;
|
||||
}
|
||||
|
||||
|
||||
// Runs the tests and collects their result in a TestResult.
|
||||
void TestSuite::run(TestResult *result)
|
||||
{
|
||||
for (std::vector<Test*>::iterator it = _tests.begin(); it != _tests.end(); ++it)
|
||||
{
|
||||
if (result->shouldStop ())
|
||||
break;
|
||||
|
||||
Test *test = *it;
|
||||
test->run(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Counts the number of test cases that will be run by this test.
|
||||
int TestSuite::countTestCases()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
for (std::vector<Test*>::iterator it = _tests.begin (); it != _tests.end (); ++it)
|
||||
count += (*it)->countTestCases();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,225 +0,0 @@
|
||||
//
|
||||
// TextTestResult.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/CppUnit/src/TextTestResult.cpp#1 $
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TextTestResult.h"
|
||||
#include "CppUnit/CppUnitException.h"
|
||||
#include "CppUnit/Test.h"
|
||||
#include "CppUnit/estring.h"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
|
||||
|
||||
namespace CppUnit {
|
||||
|
||||
|
||||
TextTestResult::TextTestResult():
|
||||
_ostr(std::cout)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
|
||||
|
||||
TextTestResult::TextTestResult(std::ostream& ostr):
|
||||
_ostr(ostr)
|
||||
{
|
||||
setup();
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::setup()
|
||||
{
|
||||
#if !defined(_WIN32_WCE)
|
||||
const char* env = std::getenv("CPPUNIT_IGNORE");
|
||||
if (env)
|
||||
{
|
||||
std::string ignored = env;
|
||||
std::string::const_iterator it = ignored.begin();
|
||||
std::string::const_iterator end = ignored.end();
|
||||
while (it != end)
|
||||
{
|
||||
while (it != end && std::isspace(*it)) ++it;
|
||||
std::string test;
|
||||
while (it != end && !std::isspace(*it)) test += *it++;
|
||||
if (!test.empty()) _ignored.insert(test);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::addError(Test* test, CppUnitException* e)
|
||||
{
|
||||
if (_ignored.find(test->toString()) == _ignored.end())
|
||||
{
|
||||
TestResult::addError(test, e);
|
||||
_ostr << "ERROR" << std::flush;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr << "ERROR (ignored)" << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::addFailure(Test* test, CppUnitException* e)
|
||||
{
|
||||
if (_ignored.find(test->toString()) == _ignored.end())
|
||||
{
|
||||
TestResult::addFailure(test, e);
|
||||
_ostr << "FAILURE" << std::flush;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ostr << "FAILURE (ignored)" << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::startTest(Test* test)
|
||||
{
|
||||
TestResult::startTest(test);
|
||||
_ostr << "\n" << shortName(test->toString()) << ": ";
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::printErrors(std::ostream& stream)
|
||||
{
|
||||
if (testErrors() != 0)
|
||||
{
|
||||
stream << "\n";
|
||||
|
||||
if (testErrors() == 1)
|
||||
stream << "There was " << testErrors() << " error: " << std::endl;
|
||||
else
|
||||
stream << "There were " << testErrors() << " errors: " << std::endl;
|
||||
|
||||
int i = 1;
|
||||
for (std::vector<TestFailure*>::iterator it = errors().begin(); it != errors().end(); ++it)
|
||||
{
|
||||
TestFailure* failure = *it;
|
||||
CppUnitException* e = failure->thrownException();
|
||||
|
||||
stream << std::setw(2) << i
|
||||
<< ": "
|
||||
<< failure->failedTest()->toString() << "\n"
|
||||
<< " \"" << (e ? e->what() : "") << "\"\n"
|
||||
<< " in \""
|
||||
<< (e ? e->fileName() : std::string())
|
||||
<< "\", line ";
|
||||
if (e == 0)
|
||||
{
|
||||
stream << "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << e->lineNumber();
|
||||
if (e->data2LineNumber() != CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
|
||||
{
|
||||
stream << " data lines " << e->data1LineNumber()
|
||||
<< ", " << e->data2LineNumber();
|
||||
}
|
||||
else if (e->data1LineNumber() != CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
|
||||
{
|
||||
stream << " data line " << e->data1LineNumber();
|
||||
}
|
||||
}
|
||||
stream << "\n";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::printFailures(std::ostream& stream)
|
||||
{
|
||||
if (testFailures() != 0)
|
||||
{
|
||||
stream << "\n";
|
||||
if (testFailures() == 1)
|
||||
stream << "There was " << testFailures() << " failure: " << std::endl;
|
||||
else
|
||||
stream << "There were " << testFailures() << " failures: " << std::endl;
|
||||
|
||||
int i = 1;
|
||||
|
||||
for (std::vector<TestFailure*>::iterator it = failures().begin(); it != failures().end(); ++it)
|
||||
{
|
||||
TestFailure* failure = *it;
|
||||
CppUnitException* e = failure->thrownException();
|
||||
|
||||
stream << std::setw(2) << i
|
||||
<< ": "
|
||||
<< failure->failedTest()->toString() << "\n"
|
||||
<< " \"" << (e ? e->what() : "") << "\"\n"
|
||||
<< " in \""
|
||||
<< (e ? e->fileName() : std::string())
|
||||
<< "\", line ";
|
||||
if (e == 0)
|
||||
{
|
||||
stream << "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
stream << e->lineNumber();
|
||||
if (e->data2LineNumber() != CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
|
||||
{
|
||||
stream << " data lines "
|
||||
<< e->data1LineNumber()
|
||||
<< ", " << e->data2LineNumber();
|
||||
}
|
||||
else if (e->data1LineNumber() != CppUnitException::CPPUNIT_UNKNOWNLINENUMBER)
|
||||
{
|
||||
stream << " data line " << e->data1LineNumber();
|
||||
}
|
||||
}
|
||||
stream << "\n";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::print(std::ostream& stream)
|
||||
{
|
||||
printHeader(stream);
|
||||
printErrors(stream);
|
||||
printFailures(stream);
|
||||
}
|
||||
|
||||
|
||||
void TextTestResult::printHeader(std::ostream& stream)
|
||||
{
|
||||
stream << "\n\n";
|
||||
if (wasSuccessful())
|
||||
stream << "OK ("
|
||||
<< runTests() << " tests)"
|
||||
<< std::endl;
|
||||
else
|
||||
stream << "!!!FAILURES!!!" << std::endl
|
||||
<< "Runs: "
|
||||
<< runTests ()
|
||||
<< " Failures: "
|
||||
<< testFailures ()
|
||||
<< " Errors: "
|
||||
<< testErrors ()
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
std::string TextTestResult::shortName(const std::string& testName)
|
||||
{
|
||||
std::string::size_type pos = testName.rfind('.');
|
||||
if (pos != std::string::npos)
|
||||
return std::string(testName, pos + 1);
|
||||
else
|
||||
return testName;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CppUnit
|
@ -1,29 +0,0 @@
|
||||
set(LIBNAME "PocoCrypto")
|
||||
set(POCO_LIBNAME "${LIBNAME}")
|
||||
|
||||
# Sources
|
||||
file(GLOB SRCS_G "src/*.cpp")
|
||||
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
|
||||
|
||||
# Headers
|
||||
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
||||
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
|
||||
|
||||
#add_definitions(-D_USRDLL)
|
||||
|
||||
include_directories (BEFORE include)
|
||||
|
||||
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
|
||||
set_target_properties( "${LIBNAME}"
|
||||
PROPERTIES
|
||||
VERSION ${SHARED_LIBRARY_VERSION} SOVERSION ${SHARED_LIBRARY_VERSION}
|
||||
OUTPUT_NAME ${POCO_LIBNAME}
|
||||
DEFINE_SYMBOL Crypto_EXPORTS
|
||||
)
|
||||
|
||||
target_link_libraries( "${LIBNAME}" PocoFoundation ${OPENSSL_LIBRARIES} )
|
||||
|
||||
if (POCO_ENABLE_TESTS)
|
||||
add_subdirectory(samples)
|
||||
add_subdirectory(testsuite)
|
||||
endif ()
|
@ -1,3 +0,0 @@
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(PocoFoundation)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/PocoCryptoTargets.cmake")
|
@ -1,140 +0,0 @@
|
||||
//
|
||||
// Cipher.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/Cipher.h#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: Cipher
|
||||
//
|
||||
// Definition of the Cipher class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_Cipher_INCLUDED
|
||||
#define Crypto_Cipher_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class CryptoTransform;
|
||||
|
||||
|
||||
class Crypto_API Cipher: public Poco::RefCountedObject
|
||||
/// Represents the abstract base class from which all implementations of
|
||||
/// symmetric/assymetric encryption algorithms must inherit. Use the CipherFactory
|
||||
/// class to obtain an instance of this class:
|
||||
///
|
||||
/// CipherFactory& factory = CipherFactory::defaultFactory();
|
||||
/// // Creates a 256-bit AES cipher
|
||||
/// Cipher* pCipher = factory.createCipher(CipherKey("aes-256"));
|
||||
/// Cipher* pRSACipher = factory.createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
|
||||
///
|
||||
/// Check the different Key constructors on how to initialize/create
|
||||
/// a key. The above example auto-generates random keys.
|
||||
///
|
||||
/// Note that you won't be able to decrypt data encrypted with a random key
|
||||
/// once the Cipher is destroyed unless you persist the generated key and IV.
|
||||
/// An example usage for random keys is to encrypt data saved in a temporary
|
||||
/// file.
|
||||
///
|
||||
/// Once your key is set up, you can use the Cipher object to encrypt or
|
||||
/// decrypt strings or, in conjunction with a CryptoInputStream or a
|
||||
/// CryptoOutputStream, to encrypt streams of data.
|
||||
///
|
||||
/// Since encrypted strings will contain arbitary binary data that will cause
|
||||
/// problems in applications that are not binary-safe (eg., when sending
|
||||
/// encrypted data in e-mails), the encryptString() and decryptString() can
|
||||
/// encode (or decode, respectively) encrypted data using a "transport encoding".
|
||||
/// Supported encodings are Base64 and BinHex.
|
||||
///
|
||||
/// The following example encrypts and decrypts a string utilizing Base64
|
||||
/// encoding:
|
||||
///
|
||||
/// std::string plainText = "This is my secret information";
|
||||
/// std::string encrypted = pCipher->encryptString(plainText, Cipher::ENC_BASE64);
|
||||
/// std::string decrypted = pCipher->decryptString(encrypted, Cipher::ENC_BASE64);
|
||||
///
|
||||
/// In order to encrypt a stream of data (eg. to encrypt files), you can use
|
||||
/// a CryptoStream:
|
||||
///
|
||||
/// // Create an output stream that will encrypt all data going through it
|
||||
/// // and write pass it to the underlying file stream.
|
||||
/// Poco::FileOutputStream sink("encrypted.dat");
|
||||
/// CryptoOutputStream encryptor(sink, pCipher->createEncryptor());
|
||||
///
|
||||
/// Poco::FileInputStream source("source.txt");
|
||||
/// Poco::StreamCopier::copyStream(source, encryptor);
|
||||
///
|
||||
/// // Always close output streams to flush all internal buffers
|
||||
/// encryptor.close();
|
||||
/// sink.close();
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<Cipher> Ptr;
|
||||
typedef std::vector<unsigned char> ByteVec;
|
||||
|
||||
enum Encoding
|
||||
/// Transport encoding to use for encryptString() and decryptString().
|
||||
{
|
||||
ENC_NONE = 0x00, /// Plain binary output
|
||||
ENC_BASE64 = 0x01, /// Base64-encoded output
|
||||
ENC_BINHEX = 0x02, /// BinHex-encoded output
|
||||
ENC_BASE64_NO_LF = 0x81, /// Base64-encoded output, no linefeeds
|
||||
ENC_BINHEX_NO_LF = 0x82 /// BinHex-encoded output, no linefeeds
|
||||
|
||||
};
|
||||
|
||||
virtual ~Cipher();
|
||||
/// Destroys the Cipher.
|
||||
|
||||
virtual const std::string& name() const = 0;
|
||||
/// Returns the name of the Cipher.
|
||||
|
||||
virtual CryptoTransform* createEncryptor() = 0;
|
||||
/// Creates an encrytor object to be used with a CryptoStream.
|
||||
|
||||
virtual CryptoTransform* createDecryptor() = 0;
|
||||
/// Creates a decryptor object to be used with a CryptoStream.
|
||||
|
||||
virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE);
|
||||
/// Directly encrypt a string and encode it using the given encoding.
|
||||
|
||||
virtual std::string decryptString(const std::string& str, Encoding encoding = ENC_NONE);
|
||||
/// Directly decrypt a string that is encoded with the given encoding.
|
||||
|
||||
virtual void encrypt(std::istream& source, std::ostream& sink, Encoding encoding = ENC_NONE);
|
||||
/// Directly encrypts an input stream and encodes it using the given encoding.
|
||||
|
||||
virtual void decrypt(std::istream& source, std::ostream& sink, Encoding encoding = ENC_NONE);
|
||||
/// Directly decrypt an input stream that is encoded with the given encoding.
|
||||
|
||||
protected:
|
||||
Cipher();
|
||||
/// Creates a new Cipher object.
|
||||
|
||||
private:
|
||||
Cipher(const Cipher&);
|
||||
Cipher& operator = (const Cipher&);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_Cipher_INCLUDED
|
@ -1,77 +0,0 @@
|
||||
//
|
||||
// CipherFactory.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherFactory.h#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherFactory
|
||||
//
|
||||
// Definition of the CipherFactory class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_CipherFactory_INCLUDED
|
||||
#define Crypto_CipherFactory_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Cipher;
|
||||
class CipherKey;
|
||||
class RSAKey;
|
||||
|
||||
|
||||
class Crypto_API CipherFactory
|
||||
/// A factory for Cipher objects. See the Cipher class for examples on how to
|
||||
/// use the CipherFactory.
|
||||
{
|
||||
public:
|
||||
CipherFactory();
|
||||
/// Creates a new CipherFactory object.
|
||||
|
||||
virtual ~CipherFactory();
|
||||
/// Destroys the CipherFactory.
|
||||
|
||||
Cipher* createCipher(const CipherKey& key);
|
||||
/// Creates a Cipher object for the given Cipher name. Valid cipher
|
||||
/// names depend on the OpenSSL version the library is linked with;
|
||||
/// see the output of
|
||||
///
|
||||
/// openssl enc --help
|
||||
///
|
||||
/// for a list of supported block and stream ciphers.
|
||||
///
|
||||
/// Common examples are:
|
||||
///
|
||||
/// * AES: "aes-128", "aes-256"
|
||||
/// * DES: "des", "des3"
|
||||
/// * Blowfish: "bf"
|
||||
|
||||
Cipher* createCipher(const RSAKey& key, RSAPaddingMode paddingMode = RSA_PADDING_PKCS1);
|
||||
/// Creates a RSACipher using the given RSA key and padding mode
|
||||
/// for public key encryption/private key decryption.
|
||||
|
||||
static CipherFactory& defaultFactory();
|
||||
/// Returns the default CipherFactory.
|
||||
|
||||
private:
|
||||
CipherFactory(const CipherFactory&);
|
||||
CipherFactory& operator = (const CipherFactory&);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_CipherFactory_INCLUDED
|
@ -1,71 +0,0 @@
|
||||
//
|
||||
// CipherImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherImpl.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherImpl
|
||||
//
|
||||
// Definition of the CipherImpl class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_CipherImpl_INCLUDED
|
||||
#define Crypto_CipherImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Crypto/CipherKey.h"
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class CipherImpl: public Cipher
|
||||
/// An implementation of the Cipher class for OpenSSL's crypto library.
|
||||
{
|
||||
public:
|
||||
CipherImpl(const CipherKey& key);
|
||||
/// Creates a new CipherImpl object for the given CipherKey.
|
||||
|
||||
virtual ~CipherImpl();
|
||||
/// Destroys the CipherImpl.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name of the cipher.
|
||||
|
||||
CryptoTransform* createEncryptor();
|
||||
/// Creates an encrytor object.
|
||||
|
||||
CryptoTransform* createDecryptor();
|
||||
/// Creates a decrytor object.
|
||||
|
||||
private:
|
||||
CipherKey _key;
|
||||
OpenSSLInitializer _openSSLInitializer;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Inlines
|
||||
//
|
||||
inline const std::string& CipherImpl::name() const
|
||||
{
|
||||
return _key.name();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_CipherImpl_INCLUDED
|
@ -1,184 +0,0 @@
|
||||
//
|
||||
// CipherKey.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherKey.h#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherKey
|
||||
//
|
||||
// Definition of the CipherKey class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_CipherKey_INCLUDED
|
||||
#define Crypto_CipherKey_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/CipherKeyImpl.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API CipherKey
|
||||
/// CipherKey stores the key information for decryption/encryption of data.
|
||||
/// To create a random key, using the following code:
|
||||
///
|
||||
/// CipherKey key("aes-256");
|
||||
///
|
||||
/// Note that you won't be able to decrypt data encrypted with a random key
|
||||
/// once the Cipher is destroyed unless you persist the generated key and IV.
|
||||
/// An example usage for random keys is to encrypt data saved in a temporary
|
||||
/// file.
|
||||
///
|
||||
/// To create a key using a human-readable password
|
||||
/// string, use the following code. We create a AES Cipher and
|
||||
/// use a salt value to make the key more robust:
|
||||
///
|
||||
/// std::string password = "secret";
|
||||
/// std::string salt("asdff8723lasdf(**923412");
|
||||
/// CipherKey key("aes-256", password, salt);
|
||||
///
|
||||
{
|
||||
public:
|
||||
typedef CipherKeyImpl::Mode Mode;
|
||||
typedef CipherKeyImpl::ByteVec ByteVec;
|
||||
|
||||
enum
|
||||
{
|
||||
DEFAULT_ITERATION_COUNT = 2000
|
||||
/// Default iteration count to use with
|
||||
/// generateKey(). RSA security recommends
|
||||
/// an iteration count of at least 1000.
|
||||
};
|
||||
|
||||
CipherKey(const std::string& name,
|
||||
const std::string& passphrase,
|
||||
const std::string& salt = "",
|
||||
int iterationCount = DEFAULT_ITERATION_COUNT);
|
||||
/// Creates a new CipherKeyImpl object using the given
|
||||
/// cipher name, passphrase, salt value and iteration count.
|
||||
|
||||
CipherKey(const std::string& name,
|
||||
const ByteVec& key,
|
||||
const ByteVec& iv);
|
||||
/// Creates a new CipherKeyImpl object using the given cipher
|
||||
/// name, key and initialization vector.
|
||||
|
||||
CipherKey(const std::string& name);
|
||||
/// Creates a new CipherKeyImpl object. Autoinitializes key and
|
||||
/// initialization vector.
|
||||
|
||||
~CipherKey();
|
||||
/// Destroys the CipherKeyImpl.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name of the Cipher.
|
||||
|
||||
int keySize() const;
|
||||
/// Returns the key size of the Cipher.
|
||||
|
||||
int blockSize() const;
|
||||
/// Returns the block size of the Cipher.
|
||||
|
||||
int ivSize() const;
|
||||
/// Returns the IV size of the Cipher.
|
||||
|
||||
Mode mode() const;
|
||||
/// Returns the Cipher's mode of operation.
|
||||
|
||||
const ByteVec& getKey() const;
|
||||
/// Returns the key for the Cipher.
|
||||
|
||||
void setKey(const ByteVec& key);
|
||||
/// Sets the key for the Cipher.
|
||||
|
||||
const ByteVec& getIV() const;
|
||||
/// Returns the initialization vector (IV) for the Cipher.
|
||||
|
||||
void setIV(const ByteVec& iv);
|
||||
/// Sets the initialization vector (IV) for the Cipher.
|
||||
|
||||
CipherKeyImpl::Ptr impl();
|
||||
/// Returns the impl object
|
||||
|
||||
private:
|
||||
CipherKeyImpl::Ptr _pImpl;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& CipherKey::name() const
|
||||
{
|
||||
return _pImpl->name();
|
||||
}
|
||||
|
||||
|
||||
inline int CipherKey::keySize() const
|
||||
{
|
||||
return _pImpl->keySize();
|
||||
}
|
||||
|
||||
|
||||
inline int CipherKey::blockSize() const
|
||||
{
|
||||
return _pImpl->blockSize();
|
||||
}
|
||||
|
||||
|
||||
inline int CipherKey::ivSize() const
|
||||
{
|
||||
return _pImpl->ivSize();
|
||||
}
|
||||
|
||||
|
||||
inline CipherKey::Mode CipherKey::mode() const
|
||||
{
|
||||
return _pImpl->mode();
|
||||
}
|
||||
|
||||
|
||||
inline const CipherKey::ByteVec& CipherKey::getKey() const
|
||||
{
|
||||
return _pImpl->getKey();
|
||||
}
|
||||
|
||||
|
||||
inline void CipherKey::setKey(const CipherKey::ByteVec& key)
|
||||
{
|
||||
_pImpl->setKey(key);
|
||||
}
|
||||
|
||||
|
||||
inline const CipherKey::ByteVec& CipherKey::getIV() const
|
||||
{
|
||||
return _pImpl->getIV();
|
||||
}
|
||||
|
||||
|
||||
inline void CipherKey::setIV(const CipherKey::ByteVec& iv)
|
||||
{
|
||||
_pImpl->setIV(iv);
|
||||
}
|
||||
|
||||
|
||||
inline CipherKeyImpl::Ptr CipherKey::impl()
|
||||
{
|
||||
return _pImpl;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_CipherKey_INCLUDED
|
@ -1,172 +0,0 @@
|
||||
//
|
||||
// CipherKeyImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CipherKeyImpl.h#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherKeyImpl
|
||||
//
|
||||
// Definition of the CipherKeyImpl class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_CipherKeyImpl_INCLUDED
|
||||
#define Crypto_CipherKeyImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct evp_cipher_st;
|
||||
typedef struct evp_cipher_st EVP_CIPHER;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class CipherKeyImpl: public RefCountedObject
|
||||
/// An implementation of the CipherKey class for OpenSSL's crypto library.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<unsigned char> ByteVec;
|
||||
typedef Poco::AutoPtr<CipherKeyImpl> Ptr;
|
||||
|
||||
enum Mode
|
||||
/// Cipher mode of operation. This mode determines how multiple blocks
|
||||
/// are connected; this is essential to improve security.
|
||||
{
|
||||
MODE_STREAM_CIPHER, /// Stream cipher
|
||||
MODE_ECB, /// Electronic codebook (plain concatenation)
|
||||
MODE_CBC, /// Cipher block chaining (default)
|
||||
MODE_CFB, /// Cipher feedback
|
||||
MODE_OFB /// Output feedback
|
||||
};
|
||||
|
||||
CipherKeyImpl(const std::string& name,
|
||||
const std::string& passphrase,
|
||||
const std::string& salt,
|
||||
int iterationCount);
|
||||
/// Creates a new CipherKeyImpl object, using
|
||||
/// the given cipher name, passphrase, salt value
|
||||
/// and iteration count.
|
||||
|
||||
CipherKeyImpl(const std::string& name,
|
||||
const ByteVec& key,
|
||||
const ByteVec& iv);
|
||||
/// Creates a new CipherKeyImpl object, using the
|
||||
/// given cipher name, key and initialization vector.
|
||||
|
||||
CipherKeyImpl(const std::string& name);
|
||||
/// Creates a new CipherKeyImpl object. Autoinitializes key
|
||||
/// and initialization vector.
|
||||
|
||||
virtual ~CipherKeyImpl();
|
||||
/// Destroys the CipherKeyImpl.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name of the Cipher.
|
||||
|
||||
int keySize() const;
|
||||
/// Returns the key size of the Cipher.
|
||||
|
||||
int blockSize() const;
|
||||
/// Returns the block size of the Cipher.
|
||||
|
||||
int ivSize() const;
|
||||
/// Returns the IV size of the Cipher.
|
||||
|
||||
Mode mode() const;
|
||||
/// Returns the Cipher's mode of operation.
|
||||
|
||||
const ByteVec& getKey() const;
|
||||
/// Returns the key for the Cipher.
|
||||
|
||||
void setKey(const ByteVec& key);
|
||||
/// Sets the key for the Cipher.
|
||||
|
||||
const ByteVec& getIV() const;
|
||||
/// Returns the initialization vector (IV) for the Cipher.
|
||||
|
||||
void setIV(const ByteVec& iv);
|
||||
/// Sets the initialization vector (IV) for the Cipher.
|
||||
|
||||
const EVP_CIPHER* cipher();
|
||||
/// Returns the cipher object
|
||||
|
||||
private:
|
||||
void generateKey(const std::string& passphrase,
|
||||
const std::string& salt,
|
||||
int iterationCount);
|
||||
/// Generates key and IV from a password and optional salt string.
|
||||
|
||||
void generateKey();
|
||||
/// Generates key and IV from random data.
|
||||
|
||||
void getRandomBytes(ByteVec& vec, std::size_t count);
|
||||
/// Stores random bytes in vec.
|
||||
|
||||
private:
|
||||
const EVP_CIPHER* _pCipher;
|
||||
std::string _name;
|
||||
ByteVec _key;
|
||||
ByteVec _iv;
|
||||
OpenSSLInitializer _openSSLInitializer;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Inlines
|
||||
//
|
||||
inline const std::string& CipherKeyImpl::name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getKey() const
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
|
||||
inline void CipherKeyImpl::setKey(const ByteVec& key)
|
||||
{
|
||||
poco_assert(key.size() == static_cast<ByteVec::size_type>(keySize()));
|
||||
_key = key;
|
||||
}
|
||||
|
||||
|
||||
inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getIV() const
|
||||
{
|
||||
return _iv;
|
||||
}
|
||||
|
||||
|
||||
inline void CipherKeyImpl::setIV(const ByteVec& iv)
|
||||
{
|
||||
poco_assert(iv.size() == static_cast<ByteVec::size_type>(ivSize()));
|
||||
_iv = iv;
|
||||
}
|
||||
|
||||
|
||||
inline const EVP_CIPHER* CipherKeyImpl::cipher()
|
||||
{
|
||||
return _pCipher;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_CipherKeyImpl_INCLUDED
|
@ -1,119 +0,0 @@
|
||||
//
|
||||
// Crypto.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/Crypto.h#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: CryptoCore
|
||||
// Module: Crypto
|
||||
//
|
||||
// Basic definitions for the Poco Crypto library.
|
||||
// This file must be the first file included by every other Crypto
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_Crypto_INCLUDED
|
||||
#define Crypto_Crypto_INCLUDED
|
||||
|
||||
|
||||
#if defined(__APPLE__)
|
||||
// OS X 10.7 deprecates some OpenSSL functions
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
enum RSAPaddingMode
|
||||
/// The padding mode used for RSA public key encryption.
|
||||
{
|
||||
RSA_PADDING_PKCS1,
|
||||
/// PKCS #1 v1.5 padding. This currently is the most widely used mode.
|
||||
|
||||
RSA_PADDING_PKCS1_OAEP,
|
||||
/// EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
|
||||
/// encoding parameter. This mode is recommended for all new applications.
|
||||
|
||||
RSA_PADDING_SSLV23,
|
||||
/// PKCS #1 v1.5 padding with an SSL-specific modification that denotes
|
||||
/// that the server is SSL3 capable.
|
||||
|
||||
RSA_PADDING_NONE
|
||||
/// Raw RSA encryption. This mode should only be used to implement cryptographically
|
||||
/// sound padding modes in the application code. Encrypting user data directly with RSA
|
||||
/// is insecure.
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the Crypto_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// Crypto_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(Crypto_EXPORTS)
|
||||
#define Crypto_API __declspec(dllexport)
|
||||
#else
|
||||
#define Crypto_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(Crypto_API)
|
||||
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
|
||||
#define Crypto_API __attribute__ ((visibility ("default")))
|
||||
#else
|
||||
#define Crypto_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Crypto library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Crypto_EXPORTS)
|
||||
#pragma comment(lib, "PocoCrypto" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
void Crypto_API initializeCrypto();
|
||||
/// Initialize the Crypto library, as well as the underlying OpenSSL
|
||||
/// libraries, by calling OpenSSLInitializer::initialize().
|
||||
///
|
||||
/// Should be called before using any class from the Crypto library.
|
||||
/// The Crypto library will be initialized automatically, through
|
||||
/// OpenSSLInitializer instances held by various Crypto classes
|
||||
/// (Cipher, CipherKey, RSAKey, X509Certificate).
|
||||
/// However, it is recommended to call initializeCrypto()
|
||||
/// in any case at application startup.
|
||||
///
|
||||
/// Can be called multiple times; however, for every call to
|
||||
/// initializeCrypto(), a matching call to uninitializeCrypto()
|
||||
/// must be performed.
|
||||
|
||||
|
||||
void Crypto_API uninitializeCrypto();
|
||||
/// Uninitializes the Crypto library by calling
|
||||
/// OpenSSLInitializer::uninitialize().
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_Crypto_INCLUDED
|
@ -1,194 +0,0 @@
|
||||
//
|
||||
// CryptoStream.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CryptoStream.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CryptoStream
|
||||
//
|
||||
// Definition of the CryptoStreamBuf, CryptoInputStream and CryptoOutputStream
|
||||
// classes.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_CryptoStream_INCLUDED
|
||||
#define Crypto_CryptoStream_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/BufferedStreamBuf.h"
|
||||
#include "Poco/Buffer.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class CryptoTransform;
|
||||
class Cipher;
|
||||
|
||||
|
||||
class Crypto_API CryptoStreamBuf: public Poco::BufferedStreamBuf
|
||||
/// This stream buffer performs cryptographic transformation on the data
|
||||
/// going through it.
|
||||
{
|
||||
public:
|
||||
CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
||||
CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
||||
|
||||
virtual ~CryptoStreamBuf();
|
||||
|
||||
void close();
|
||||
/// Flushes all buffers and finishes the encryption.
|
||||
|
||||
protected:
|
||||
int readFromDevice(char* buffer, std::streamsize length);
|
||||
int writeToDevice(const char* buffer, std::streamsize length);
|
||||
|
||||
private:
|
||||
CryptoTransform* _pTransform;
|
||||
std::istream* _pIstr;
|
||||
std::ostream* _pOstr;
|
||||
bool _eof;
|
||||
|
||||
Poco::Buffer<unsigned char> _buffer;
|
||||
|
||||
CryptoStreamBuf(const CryptoStreamBuf&);
|
||||
CryptoStreamBuf& operator = (const CryptoStreamBuf&);
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API CryptoIOS: public virtual std::ios
|
||||
/// The base class for CryptoInputStream and CryptoOutputStream.
|
||||
///
|
||||
/// This class is needed to ensure correct initialization order of the
|
||||
/// stream buffer and base classes.
|
||||
{
|
||||
public:
|
||||
CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
||||
CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
||||
~CryptoIOS();
|
||||
CryptoStreamBuf* rdbuf();
|
||||
|
||||
protected:
|
||||
CryptoStreamBuf _buf;
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API CryptoInputStream: public CryptoIOS, public std::istream
|
||||
/// This stream transforms all data passing through it using the given
|
||||
/// CryptoTransform.
|
||||
///
|
||||
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
|
||||
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
|
||||
/// respectively.
|
||||
{
|
||||
public:
|
||||
CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
||||
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
|
||||
/// ownership of the given CryptoTransform object.
|
||||
|
||||
CryptoInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
|
||||
/// Create a new encrypting CryptoInputStream object using the given cipher.
|
||||
|
||||
~CryptoInputStream();
|
||||
/// Destroys the CryptoInputStream.
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API CryptoOutputStream: public CryptoIOS, public std::ostream
|
||||
/// This stream transforms all data passing through it using the given
|
||||
/// CryptoTransform.
|
||||
///
|
||||
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
|
||||
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
|
||||
/// respectively.
|
||||
///
|
||||
/// After all data has been passed through the stream, close() must be called
|
||||
/// to ensure completion of cryptographic transformation.
|
||||
{
|
||||
public:
|
||||
CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
|
||||
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
|
||||
/// ownership of the given CryptoTransform object.
|
||||
|
||||
CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
|
||||
/// Create a new decrypting CryptoOutputStream object using the given cipher.
|
||||
|
||||
~CryptoOutputStream();
|
||||
/// Destroys the CryptoOutputStream.
|
||||
|
||||
void close();
|
||||
/// Flushes all buffers and finishes the encryption.
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API DecryptingInputStream: public CryptoIOS, public std::istream
|
||||
/// This stream decrypts all data passing through it using the given
|
||||
/// Cipher.
|
||||
{
|
||||
public:
|
||||
DecryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
|
||||
/// Create a new DecryptingInputStream object using the given cipher.
|
||||
|
||||
~DecryptingInputStream();
|
||||
/// Destroys the DecryptingInputStream.
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API DecryptingOutputStream: public CryptoIOS, public std::ostream
|
||||
/// This stream decrypts all data passing through it using the given
|
||||
/// Cipher.
|
||||
{
|
||||
public:
|
||||
DecryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
|
||||
/// Create a new DecryptingOutputStream object using the given cipher.
|
||||
|
||||
~DecryptingOutputStream();
|
||||
/// Destroys the DecryptingOutputStream.
|
||||
|
||||
void close();
|
||||
/// Flushes all buffers and finishes the decryption.
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API EncryptingInputStream: public CryptoIOS, public std::istream
|
||||
/// This stream encrypts all data passing through it using the given
|
||||
/// Cipher.
|
||||
{
|
||||
public:
|
||||
EncryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
|
||||
/// Create a new EncryptingInputStream object using the given cipher.
|
||||
|
||||
~EncryptingInputStream();
|
||||
/// Destroys the EncryptingInputStream.
|
||||
};
|
||||
|
||||
|
||||
class Crypto_API EncryptingOutputStream: public CryptoIOS, public std::ostream
|
||||
/// This stream encrypts all data passing through it using the given
|
||||
/// Cipher.
|
||||
{
|
||||
public:
|
||||
EncryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
|
||||
/// Create a new EncryptingOutputStream object using the given cipher.
|
||||
|
||||
~EncryptingOutputStream();
|
||||
/// Destroys the EncryptingOutputStream.
|
||||
|
||||
void close();
|
||||
/// Flushes all buffers and finishes the encryption.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_CryptoStream_INCLUDED
|
@ -1,78 +0,0 @@
|
||||
//
|
||||
// CryptoTransform.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/CryptoTransform.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CryptoTransform
|
||||
//
|
||||
// Definition of the CryptoTransform class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_CryptoTransform_INCLUDED
|
||||
#define Crypto_CryptoTransform_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include <ios>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API CryptoTransform
|
||||
/// This interface represents the basic operations for cryptographic
|
||||
/// transformations to be used with a CryptoInputStream or a
|
||||
/// CryptoOutputStream.
|
||||
///
|
||||
/// Implementations of this class are returned by the Cipher class to
|
||||
/// perform encryption or decryption of data.
|
||||
{
|
||||
public:
|
||||
CryptoTransform();
|
||||
/// Creates a new CryptoTransform object.
|
||||
|
||||
virtual ~CryptoTransform();
|
||||
/// Destroys the CryptoTransform.
|
||||
|
||||
virtual std::size_t blockSize() const = 0;
|
||||
/// Returns the block size for this CryptoTransform.
|
||||
|
||||
virtual int setPadding(int padding);
|
||||
/// Enables or disables padding. By default encryption operations are padded using standard block
|
||||
/// padding and the padding is checked and removed when decrypting. If the padding parameter is zero then
|
||||
/// no padding is performed, the total amount of data encrypted or decrypted must then be a multiple of
|
||||
/// the block size or an error will occur.
|
||||
|
||||
virtual std::streamsize transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength) = 0;
|
||||
/// Transforms a chunk of data. The inputLength is arbitrary and does not
|
||||
/// need to be a multiple of the block size. The output buffer has a maximum
|
||||
/// capacity of the given outputLength that must be at least
|
||||
/// inputLength + blockSize() - 1
|
||||
/// Returns the number of bytes written to the output buffer.
|
||||
|
||||
virtual std::streamsize finalize(unsigned char* output, std::streamsize length) = 0;
|
||||
/// Finalizes the transformation. The output buffer must contain enough
|
||||
/// space for at least two blocks, ie.
|
||||
/// length >= 2*blockSize()
|
||||
/// must be true. Returns the number of bytes written to the output
|
||||
/// buffer.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_CryptoTransform_INCLUDED
|
@ -1,82 +0,0 @@
|
||||
//
|
||||
// DigestEngine.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/DigestEngine.h#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Digest
|
||||
// Module: DigestEngine
|
||||
//
|
||||
// Definition of the DigestEngine class.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_DigestEngine_INCLUDED
|
||||
#define Crypto_DigestEngine_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include "Poco/DigestEngine.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API DigestEngine: public Poco::DigestEngine
|
||||
/// This class implements a Poco::DigestEngine for all
|
||||
/// digest algorithms supported by OpenSSL.
|
||||
{
|
||||
public:
|
||||
DigestEngine(const std::string& name);
|
||||
/// Creates a DigestEngine using the digest with the given name
|
||||
/// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.).
|
||||
/// See the OpenSSL documentation for a list of supported digest algorithms.
|
||||
///
|
||||
/// Throws a Poco::NotFoundException if no algorithm with the given name exists.
|
||||
|
||||
~DigestEngine();
|
||||
/// Destroys the DigestEngine.
|
||||
|
||||
const std::string& algorithm() const;
|
||||
/// Returns the name of the digest algorithm.
|
||||
|
||||
int nid() const;
|
||||
/// Returns the NID (OpenSSL object identifier) of the digest algorithm.
|
||||
|
||||
// DigestEngine
|
||||
std::size_t digestLength() const;
|
||||
void reset();
|
||||
const Poco::DigestEngine::Digest& digest();
|
||||
|
||||
protected:
|
||||
void updateImpl(const void* data, std::size_t length);
|
||||
|
||||
private:
|
||||
std::string _name;
|
||||
EVP_MD_CTX* _pContext;
|
||||
Poco::DigestEngine::Digest _digest;
|
||||
OpenSSLInitializer _openSSLInitializer;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& DigestEngine::algorithm() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_DigestEngine_INCLUDED
|
@ -1,117 +0,0 @@
|
||||
//
|
||||
// OpenSSLInitializer.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/OpenSSLInitializer.h#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: CryptoCore
|
||||
// Module: OpenSSLInitializer
|
||||
//
|
||||
// Definition of the OpenSSLInitializer class.
|
||||
//
|
||||
// Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_OpenSSLInitializer_INCLUDED
|
||||
#define Crypto_OpenSSLInitializer_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/AtomicCounter.h"
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#if defined(OPENSSL_FIPS) && OPENSSL_VERSION_NUMBER < 0x010001000L
|
||||
#include <openssl/fips.h>
|
||||
#endif
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
struct CRYPTO_dynlock_value
|
||||
{
|
||||
Poco::FastMutex _mutex;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API OpenSSLInitializer
|
||||
/// Initalizes the OpenSSL library.
|
||||
///
|
||||
/// The class ensures the earliest initialization and the
|
||||
/// latest shutdown of the OpenSSL library.
|
||||
{
|
||||
public:
|
||||
OpenSSLInitializer();
|
||||
/// Automatically initialize OpenSSL on startup.
|
||||
|
||||
~OpenSSLInitializer();
|
||||
/// Automatically shut down OpenSSL on exit.
|
||||
|
||||
static void initialize();
|
||||
/// Initializes the OpenSSL machinery.
|
||||
|
||||
static void uninitialize();
|
||||
/// Shuts down the OpenSSL machinery.
|
||||
|
||||
static bool isFIPSEnabled();
|
||||
// Returns true if FIPS mode is enabled, false otherwise.
|
||||
|
||||
static void enableFIPSMode(bool enabled);
|
||||
// Enable or disable FIPS mode. If FIPS is not available, this method doesn't do anything.
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
SEEDSIZE = 256
|
||||
};
|
||||
|
||||
// OpenSSL multithreading support
|
||||
static void lock(int mode, int n, const char* file, int line);
|
||||
static unsigned long id();
|
||||
static struct CRYPTO_dynlock_value* dynlockCreate(const char* file, int line);
|
||||
static void dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line);
|
||||
static void dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line);
|
||||
|
||||
private:
|
||||
static Poco::FastMutex* _mutexes;
|
||||
static Poco::AtomicCounter _rc;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool OpenSSLInitializer::isFIPSEnabled()
|
||||
{
|
||||
#ifdef OPENSSL_FIPS
|
||||
return FIPS_mode() ? true : false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_FIPS
|
||||
inline void OpenSSLInitializer::enableFIPSMode(bool enabled)
|
||||
{
|
||||
FIPS_mode_set(enabled);
|
||||
}
|
||||
#else
|
||||
inline void OpenSSLInitializer::enableFIPSMode(bool /*enabled*/)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_OpenSSLInitializer_INCLUDED
|
@ -1,79 +0,0 @@
|
||||
//
|
||||
// RSACipherImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSACipherImpl.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSACipherImpl
|
||||
//
|
||||
// Definition of the RSACipherImpl class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_RSACipherImpl_INCLUDED
|
||||
#define Crypto_RSACipherImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Crypto/RSAKey.h"
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class RSACipherImpl: public Cipher
|
||||
/// An implementation of the Cipher class for
|
||||
/// assymetric (public-private key) encryption
|
||||
/// based on the the RSA algorithm in OpenSSL's
|
||||
/// crypto library.
|
||||
///
|
||||
/// Encryption is using the public key, decryption
|
||||
/// requires the private key.
|
||||
{
|
||||
public:
|
||||
RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode);
|
||||
/// Creates a new RSACipherImpl object for the given RSAKey
|
||||
/// and using the given padding mode.
|
||||
|
||||
virtual ~RSACipherImpl();
|
||||
/// Destroys the RSACipherImpl.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name of the Cipher.
|
||||
|
||||
CryptoTransform* createEncryptor();
|
||||
/// Creates an encrytor object.
|
||||
|
||||
CryptoTransform* createDecryptor();
|
||||
/// Creates a decrytor object.
|
||||
|
||||
private:
|
||||
RSAKey _key;
|
||||
RSAPaddingMode _paddingMode;
|
||||
OpenSSLInitializer _openSSLInitializer;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Inlines
|
||||
//
|
||||
inline const std::string& RSACipherImpl::name() const
|
||||
{
|
||||
return _key.name();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_RSACipherImpl_INCLUDED
|
@ -1,113 +0,0 @@
|
||||
//
|
||||
// RSADigestEngine.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSADigestEngine.h#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSADigestEngine
|
||||
//
|
||||
// Definition of the RSADigestEngine class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_RSADigestEngine_INCLUDED
|
||||
#define Crypto_RSADigestEngine_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/RSAKey.h"
|
||||
#include "Poco/DigestEngine.h"
|
||||
#include "Poco/Crypto/DigestEngine.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API RSADigestEngine: public Poco::DigestEngine
|
||||
/// This class implements a Poco::DigestEngine that can be
|
||||
/// used to compute a secure digital signature.
|
||||
///
|
||||
/// First another Poco::Crypto::DigestEngine is created and
|
||||
/// used to compute a cryptographic hash of the data to be
|
||||
/// signed. Then, the hash value is encrypted, using
|
||||
/// the RSA private key.
|
||||
///
|
||||
/// To verify a signature, pass it to the verify()
|
||||
/// member function. It will decrypt the signature
|
||||
/// using the RSA public key and compare the resulting
|
||||
/// hash with the actual hash of the data.
|
||||
{
|
||||
public:
|
||||
enum DigestType
|
||||
{
|
||||
DIGEST_MD5,
|
||||
DIGEST_SHA1
|
||||
};
|
||||
|
||||
//@ deprecated
|
||||
RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
|
||||
/// Creates the RSADigestEngine with the given RSA key,
|
||||
/// using the MD5 or SHA-1 hash algorithm.
|
||||
/// Kept for backward compatibility
|
||||
|
||||
RSADigestEngine(const RSAKey& key, const std::string &name);
|
||||
/// Creates the RSADigestEngine with the given RSA key,
|
||||
/// using the hash algorithm with the given name
|
||||
/// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.).
|
||||
/// See the OpenSSL documentation for a list of supported digest algorithms.
|
||||
///
|
||||
/// Throws a Poco::NotFoundException if no algorithm with the given name exists.
|
||||
|
||||
~RSADigestEngine();
|
||||
/// Destroys the RSADigestEngine.
|
||||
|
||||
std::size_t digestLength() const;
|
||||
/// Returns the length of the digest in bytes.
|
||||
|
||||
void reset();
|
||||
/// Resets the engine so that a new
|
||||
/// digest can be computed.
|
||||
|
||||
const DigestEngine::Digest& digest();
|
||||
/// Finishes the computation of the digest
|
||||
/// (the first time it's called) and
|
||||
/// returns the message digest.
|
||||
///
|
||||
/// Can be called multiple times.
|
||||
|
||||
const DigestEngine::Digest& signature();
|
||||
/// Signs the digest using the RSA algorithm
|
||||
/// and the private key (teh first time it's
|
||||
/// called) and returns the result.
|
||||
///
|
||||
/// Can be called multiple times.
|
||||
|
||||
bool verify(const DigestEngine::Digest& signature);
|
||||
/// Verifies the data against the signature.
|
||||
///
|
||||
/// Returns true if the signature can be verified, false otherwise.
|
||||
|
||||
protected:
|
||||
void updateImpl(const void* data, std::size_t length);
|
||||
|
||||
private:
|
||||
RSAKey _key;
|
||||
Poco::Crypto::DigestEngine _engine;
|
||||
Poco::DigestEngine::Digest _digest;
|
||||
Poco::DigestEngine::Digest _signature;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_RSADigestEngine_INCLUDED
|
@ -1,133 +0,0 @@
|
||||
//
|
||||
// RSAKey.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSAKey.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSAKey
|
||||
//
|
||||
// Definition of the RSAKey class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_RSAKey_INCLUDED
|
||||
#define Crypto_RSAKey_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/RSAKeyImpl.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class X509Certificate;
|
||||
|
||||
|
||||
class Crypto_API RSAKey
|
||||
/// This class stores an RSA key pair, consisting
|
||||
/// of private and public key. Storage of the private
|
||||
/// key is optional.
|
||||
///
|
||||
/// If a private key is available, the RSAKey can be
|
||||
/// used for decrypting data (encrypted with the public key)
|
||||
/// or computing secure digital signatures.
|
||||
{
|
||||
public:
|
||||
enum KeyLength
|
||||
{
|
||||
KL_512 = 512,
|
||||
KL_1024 = 1024,
|
||||
KL_2048 = 2048,
|
||||
KL_4096 = 4096
|
||||
};
|
||||
|
||||
enum Exponent
|
||||
{
|
||||
EXP_SMALL = 0,
|
||||
EXP_LARGE
|
||||
};
|
||||
|
||||
explicit RSAKey(const X509Certificate& cert);
|
||||
/// Extracts the RSA public key from the given certificate.
|
||||
|
||||
RSAKey(KeyLength keyLength, Exponent exp);
|
||||
/// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
|
||||
/// Can be used to sign data and verify signatures.
|
||||
|
||||
RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
|
||||
/// Creates the RSAKey, by reading public and private key from the given files and
|
||||
/// using the given passphrase for the private key.
|
||||
///
|
||||
/// Cannot be used for signing or decryption unless a private key is available.
|
||||
///
|
||||
/// If a private key is specified, you don't need to specify a public key file.
|
||||
/// OpenSSL will auto-create the public key from the private key.
|
||||
|
||||
RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
|
||||
/// Creates the RSAKey, by reading public and private key from the given streams and
|
||||
/// using the given passphrase for the private key.
|
||||
///
|
||||
/// Cannot be used for signing or decryption unless a private key is available.
|
||||
///
|
||||
/// If a private key is specified, you don't need to specify a public key file.
|
||||
/// OpenSSL will auto-create the public key from the private key.
|
||||
|
||||
~RSAKey();
|
||||
/// Destroys the RSAKey.
|
||||
|
||||
int size() const;
|
||||
/// Returns the RSA modulus size.
|
||||
|
||||
RSAKeyImpl::ByteVec modulus() const;
|
||||
/// Returns the RSA modulus.
|
||||
|
||||
RSAKeyImpl::ByteVec encryptionExponent() const;
|
||||
/// Returns the RSA encryption exponent.
|
||||
|
||||
RSAKeyImpl::ByteVec decryptionExponent() const;
|
||||
/// Returns the RSA decryption exponent.
|
||||
|
||||
void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
|
||||
/// Exports the public and private keys to the given files.
|
||||
///
|
||||
/// If an empty filename is specified, the corresponding key
|
||||
/// is not exported.
|
||||
|
||||
void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
|
||||
/// Exports the public and private key to the given streams.
|
||||
///
|
||||
/// If a null pointer is passed for a stream, the corresponding
|
||||
/// key is not exported.
|
||||
|
||||
RSAKeyImpl::Ptr impl() const;
|
||||
/// Returns the impl object.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns "rsa"
|
||||
|
||||
private:
|
||||
RSAKeyImpl::Ptr _pImpl;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline RSAKeyImpl::Ptr RSAKey::impl() const
|
||||
{
|
||||
return _pImpl;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_RSAKey_INCLUDED
|
@ -1,131 +0,0 @@
|
||||
//
|
||||
// RSAKeyImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/RSAKeyImpl.h#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSAKeyImpl
|
||||
//
|
||||
// Definition of the RSAKeyImpl class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_RSAKeyImplImpl_INCLUDED
|
||||
#define Crypto_RSAKeyImplImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct bignum_st;
|
||||
struct rsa_st;
|
||||
typedef struct bignum_st BIGNUM;
|
||||
typedef struct rsa_st RSA;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class X509Certificate;
|
||||
|
||||
|
||||
class RSAKeyImpl: public Poco::RefCountedObject
|
||||
/// class RSAKeyImpl
|
||||
{
|
||||
public:
|
||||
typedef Poco::AutoPtr<RSAKeyImpl> Ptr;
|
||||
typedef std::vector<unsigned char> ByteVec;
|
||||
|
||||
explicit RSAKeyImpl(const X509Certificate& cert);
|
||||
/// Extracts the RSA public key from the given certificate.
|
||||
|
||||
RSAKeyImpl(int keyLength, unsigned long exponent);
|
||||
/// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
|
||||
/// Can be used to sign data and verify signatures.
|
||||
|
||||
RSAKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase);
|
||||
/// Creates the RSAKey, by reading public and private key from the given files and
|
||||
/// using the given passphrase for the private key. Can only by used for signing if
|
||||
/// a private key is available.
|
||||
|
||||
RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase);
|
||||
/// Creates the RSAKey. Can only by used for signing if pPrivKey
|
||||
/// is not null. If a private key file is specified, you don't need to
|
||||
/// specify a public key file. OpenSSL will auto-create it from the private key.
|
||||
|
||||
~RSAKeyImpl();
|
||||
/// Destroys the RSAKeyImpl.
|
||||
|
||||
RSA* getRSA();
|
||||
/// Returns the OpenSSL RSA object.
|
||||
|
||||
const RSA* getRSA() const;
|
||||
/// Returns the OpenSSL RSA object.
|
||||
|
||||
int size() const;
|
||||
/// Returns the RSA modulus size.
|
||||
|
||||
ByteVec modulus() const;
|
||||
/// Returns the RSA modulus.
|
||||
|
||||
ByteVec encryptionExponent() const;
|
||||
/// Returns the RSA encryption exponent.
|
||||
|
||||
ByteVec decryptionExponent() const;
|
||||
/// Returns the RSA decryption exponent.
|
||||
|
||||
void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "");
|
||||
/// Exports the public and private keys to the given files.
|
||||
///
|
||||
/// If an empty filename is specified, the corresponding key
|
||||
/// is not exported.
|
||||
|
||||
void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
|
||||
/// Exports the public and private key to the given streams.
|
||||
///
|
||||
/// If a null pointer is passed for a stream, the corresponding
|
||||
/// key is not exported.
|
||||
|
||||
private:
|
||||
void freeRSA();
|
||||
|
||||
static ByteVec convertToByteVec(const BIGNUM* bn);
|
||||
|
||||
private:
|
||||
RSA* _pRSA;
|
||||
OpenSSLInitializer _openSSLInitializer;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline RSA* RSAKeyImpl::getRSA()
|
||||
{
|
||||
return _pRSA;
|
||||
}
|
||||
|
||||
|
||||
inline const RSA* RSAKeyImpl::getRSA() const
|
||||
{
|
||||
return _pRSA;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_RSAKeyImplImpl_INCLUDED
|
@ -1,193 +0,0 @@
|
||||
//
|
||||
// X509Certificate.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/include/Poco/Crypto/X509Certificate.h#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Certificate
|
||||
// Module: X509Certificate
|
||||
//
|
||||
// Definition of the X509Certificate class.
|
||||
//
|
||||
// Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Crypto_X509Certificate_INCLUDED
|
||||
#define Crypto_X509Certificate_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <set>
|
||||
#include <istream>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
class Crypto_API X509Certificate
|
||||
/// This class represents a X509 Certificate.
|
||||
{
|
||||
public:
|
||||
enum NID
|
||||
/// Name identifier for extracting information from
|
||||
/// a certificate subject's or issuer's distinguished name.
|
||||
{
|
||||
NID_COMMON_NAME = 13,
|
||||
NID_COUNTRY = 14,
|
||||
NID_LOCALITY_NAME = 15,
|
||||
NID_STATE_OR_PROVINCE = 16,
|
||||
NID_ORGANIZATION_NAME = 17,
|
||||
NID_ORGANIZATION_UNIT_NAME = 18
|
||||
};
|
||||
|
||||
explicit X509Certificate(std::istream& istr);
|
||||
/// Creates the X509Certificate object by reading
|
||||
/// a certificate in PEM format from a stream.
|
||||
|
||||
explicit X509Certificate(const std::string& path);
|
||||
/// Creates the X509Certificate object by reading
|
||||
/// a certificate in PEM format from a file.
|
||||
|
||||
explicit X509Certificate(X509* pCert);
|
||||
/// Creates the X509Certificate from an existing
|
||||
/// OpenSSL certificate. Ownership is taken of
|
||||
/// the certificate.
|
||||
|
||||
X509Certificate(X509* pCert, bool shared);
|
||||
/// Creates the X509Certificate from an existing
|
||||
/// OpenSSL certificate. Ownership is taken of
|
||||
/// the certificate. If shared is true, the
|
||||
/// certificate's reference count is incremented.
|
||||
|
||||
X509Certificate(const X509Certificate& cert);
|
||||
/// Creates the certificate by copying another one.
|
||||
|
||||
X509Certificate& operator = (const X509Certificate& cert);
|
||||
/// Assigns a certificate.
|
||||
|
||||
void swap(X509Certificate& cert);
|
||||
/// Exchanges the certificate with another one.
|
||||
|
||||
~X509Certificate();
|
||||
/// Destroys the X509Certificate.
|
||||
|
||||
const std::string& issuerName() const;
|
||||
/// Returns the certificate issuer's distinguished name.
|
||||
|
||||
std::string issuerName(NID nid) const;
|
||||
/// Extracts the information specified by the given
|
||||
/// NID (name identifier) from the certificate issuer's
|
||||
/// distinguished name.
|
||||
|
||||
const std::string& subjectName() const;
|
||||
/// Returns the certificate subject's distinguished name.
|
||||
|
||||
std::string subjectName(NID nid) const;
|
||||
/// Extracts the information specified by the given
|
||||
/// NID (name identifier) from the certificate subject's
|
||||
/// distinguished name.
|
||||
|
||||
std::string commonName() const;
|
||||
/// Returns the common name stored in the certificate
|
||||
/// subject's distinguished name.
|
||||
|
||||
void extractNames(std::string& commonName, std::set<std::string>& domainNames) const;
|
||||
/// Extracts the common name and the alias domain names from the
|
||||
/// certificate.
|
||||
|
||||
Poco::DateTime validFrom() const;
|
||||
/// Returns the date and time the certificate is valid from.
|
||||
|
||||
Poco::DateTime expiresOn() const;
|
||||
/// Returns the date and time the certificate expires.
|
||||
|
||||
void save(std::ostream& stream) const;
|
||||
/// Writes the certificate to the given stream.
|
||||
/// The certificate is written in PEM format.
|
||||
|
||||
void save(const std::string& path) const;
|
||||
/// Writes the certificate to the file given by path.
|
||||
/// The certificate is written in PEM format.
|
||||
|
||||
bool issuedBy(const X509Certificate& issuerCertificate) const;
|
||||
/// Checks whether the certificate has been issued by
|
||||
/// the issuer given by issuerCertificate. This can be
|
||||
/// used to validate a certificate chain.
|
||||
///
|
||||
/// Verifies if the certificate has been signed with the
|
||||
/// issuer's private key, using the public key from the issuer
|
||||
/// certificate.
|
||||
///
|
||||
/// Returns true if verification against the issuer certificate
|
||||
/// was successfull, false otherwise.
|
||||
|
||||
bool equals(const X509Certificate& otherCertificate) const;
|
||||
/// Checks whether the certificate is equal to
|
||||
/// the other certificate, by comparing the hashes
|
||||
/// of both certificates.
|
||||
///
|
||||
/// Returns true if both certificates are identical,
|
||||
/// otherwise false.
|
||||
|
||||
const X509* certificate() const;
|
||||
/// Returns the underlying OpenSSL certificate.
|
||||
|
||||
protected:
|
||||
void load(std::istream& stream);
|
||||
/// Loads the certificate from the given stream. The
|
||||
/// certificate must be in PEM format.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the certificate from the given file. The
|
||||
/// certificate must be in PEM format.
|
||||
|
||||
void init();
|
||||
/// Extracts issuer and subject name from the certificate.
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
NAME_BUFFER_SIZE = 256
|
||||
};
|
||||
|
||||
std::string _issuerName;
|
||||
std::string _subjectName;
|
||||
X509* _pCert;
|
||||
OpenSSLInitializer _openSSLInitializer;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& X509Certificate::issuerName() const
|
||||
{
|
||||
return _issuerName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& X509Certificate::subjectName() const
|
||||
{
|
||||
return _subjectName;
|
||||
}
|
||||
|
||||
|
||||
inline const X509* X509Certificate::certificate() const
|
||||
{
|
||||
return _pCert;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
||||
|
||||
|
||||
#endif // Crypto_X509Certificate_INCLUDED
|
@ -1 +0,0 @@
|
||||
add_subdirectory( genrsakey )
|
@ -1,7 +0,0 @@
|
||||
set(SAMPLE_NAME "genrsakey")
|
||||
|
||||
set(LOCAL_SRCS "")
|
||||
aux_source_directory(src LOCAL_SRCS)
|
||||
|
||||
add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )
|
||||
target_link_libraries( ${SAMPLE_NAME} PocoCrypto PocoUtil PocoXML PocoFoundation )
|
@ -1,198 +0,0 @@
|
||||
//
|
||||
// genrsakey.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/samples/genrsakey/src/genrsakey.cpp#1 $
|
||||
//
|
||||
// This sample demonstrates the XYZ class.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Util/Application.h"
|
||||
#include "Poco/Util/Option.h"
|
||||
#include "Poco/Util/OptionException.h"
|
||||
#include "Poco/Util/OptionSet.h"
|
||||
#include "Poco/Util/HelpFormatter.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/NumberParser.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Crypto/RSAKey.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Util::Application;
|
||||
using Poco::Util::Option;
|
||||
using Poco::Util::OptionSet;
|
||||
using Poco::Util::HelpFormatter;
|
||||
using Poco::Util::AbstractConfiguration;
|
||||
using Poco::Util::OptionCallback;
|
||||
using Poco::AutoPtr;
|
||||
using Poco::NumberParser;
|
||||
using Poco::Crypto::RSAKey;
|
||||
|
||||
|
||||
class RSAApp: public Application
|
||||
/// This sample demonstrates some of the features of the Util::Application class,
|
||||
/// such as configuration file handling and command line arguments processing.
|
||||
///
|
||||
/// Try genrsakey --help (on Unix platforms) or genrsakey /help (elsewhere) for
|
||||
/// more information.
|
||||
{
|
||||
public:
|
||||
RSAApp():
|
||||
_helpRequested(false),
|
||||
_length(RSAKey::KL_1024),
|
||||
_exp(RSAKey::EXP_LARGE),
|
||||
_name(),
|
||||
_pwd()
|
||||
{
|
||||
Poco::Crypto::initializeCrypto();
|
||||
}
|
||||
|
||||
~RSAApp()
|
||||
{
|
||||
Poco::Crypto::uninitializeCrypto();
|
||||
}
|
||||
|
||||
protected:
|
||||
void initialize(Application& self)
|
||||
{
|
||||
loadConfiguration(); // load default configuration files, if present
|
||||
Application::initialize(self);
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
Application::uninitialize();
|
||||
}
|
||||
|
||||
void reinitialize(Application& self)
|
||||
{
|
||||
Application::reinitialize(self);
|
||||
}
|
||||
|
||||
void defineOptions(OptionSet& options)
|
||||
{
|
||||
Application::defineOptions(options);
|
||||
|
||||
options.addOption(
|
||||
Option("help", "h", "display help information on command line arguments")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleHelp)));
|
||||
|
||||
options.addOption(
|
||||
Option("?", "?", "display help information on command line arguments")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleHelp)));
|
||||
|
||||
options.addOption(
|
||||
Option("key", "k", "define the key length")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("512|1024|2048|4096")
|
||||
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleKeyLength)));
|
||||
|
||||
options.addOption(
|
||||
Option("exponent", "e", "defines the exponent of the key")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("small|large")
|
||||
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleExponent)));
|
||||
|
||||
options.addOption(
|
||||
Option("file", "f", "defines the file base name. creates a file.pub and a file.priv")
|
||||
.required(true)
|
||||
.repeatable(false)
|
||||
.argument("filebasename")
|
||||
.callback(OptionCallback<RSAApp>(this, &RSAApp::handleFilePrefix)));
|
||||
|
||||
options.addOption(
|
||||
Option("password", "p", "defines the password used to encrypt the private key file. If not defined user will be asked via stdin to provide in")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("pwd")
|
||||
.callback(OptionCallback<RSAApp>(this, &RSAApp::handlePassword)));
|
||||
}
|
||||
|
||||
void handleHelp(const std::string& name, const std::string& value)
|
||||
{
|
||||
_helpRequested = true;
|
||||
displayHelp();
|
||||
stopOptionsProcessing();
|
||||
}
|
||||
|
||||
void handleKeyLength(const std::string& name, const std::string& value)
|
||||
{
|
||||
int keyLen = Poco::NumberParser::parse(value);
|
||||
if (keyLen == 512 || keyLen == 1024 || keyLen == 2048 || keyLen == 4096)
|
||||
_length = (RSAKey::KeyLength)keyLen;
|
||||
else
|
||||
throw Poco::Util::IncompatibleOptionsException("Illegal key length value");
|
||||
}
|
||||
|
||||
void handleExponent(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (Poco::icompare(value, "small") == 0)
|
||||
_exp = RSAKey::EXP_SMALL;
|
||||
else
|
||||
_exp = RSAKey::EXP_LARGE;
|
||||
}
|
||||
|
||||
void handleFilePrefix(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (value.empty())
|
||||
throw Poco::Util::IncompatibleOptionsException("Empty file prefix forbidden");
|
||||
_name = value;
|
||||
}
|
||||
|
||||
void handlePassword(const std::string& name, const std::string& value)
|
||||
{
|
||||
_pwd = value;
|
||||
}
|
||||
|
||||
void displayHelp()
|
||||
{
|
||||
HelpFormatter helpFormatter(options());
|
||||
helpFormatter.setCommand(commandName());
|
||||
helpFormatter.setUsage("OPTIONS");
|
||||
helpFormatter.setHeader("Application for generating RSA public/private key pairs.");
|
||||
helpFormatter.format(std::cout);
|
||||
}
|
||||
|
||||
int main(const std::vector<std::string>& args)
|
||||
{
|
||||
if (!_helpRequested)
|
||||
{
|
||||
logger().information("Generating key with length " + Poco::NumberFormatter::format((int)_length));
|
||||
logger().information(std::string("Exponent is ") + ((_exp == RSAKey::EXP_SMALL)?"small":"large"));
|
||||
logger().information("Generating key");
|
||||
RSAKey key(_length, _exp);
|
||||
logger().information("Generating key: DONE");
|
||||
std::string pubFile(_name + ".pub");
|
||||
std::string privFile(_name + ".priv");
|
||||
|
||||
logger().information("Saving key to " + pubFile + " and " + privFile);
|
||||
key.save(pubFile, privFile, _pwd);
|
||||
logger().information("Key saved");
|
||||
}
|
||||
return Application::EXIT_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _helpRequested;
|
||||
RSAKey::KeyLength _length;
|
||||
RSAKey::Exponent _exp;
|
||||
std::string _name;
|
||||
std::string _pwd;
|
||||
};
|
||||
|
||||
|
||||
POCO_APP_MAIN(RSAApp)
|
@ -1,142 +0,0 @@
|
||||
//
|
||||
// Cipher.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/Cipher.cpp#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: Cipher
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Crypto/CryptoStream.h"
|
||||
#include "Poco/Crypto/CryptoTransform.h"
|
||||
#include "Poco/Base64Encoder.h"
|
||||
#include "Poco/Base64Decoder.h"
|
||||
#include "Poco/HexBinaryEncoder.h"
|
||||
#include "Poco/HexBinaryDecoder.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
Cipher::Cipher()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Cipher::~Cipher()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::string Cipher::encryptString(const std::string& str, Encoding encoding)
|
||||
{
|
||||
std::istringstream source(str);
|
||||
std::ostringstream sink;
|
||||
|
||||
encrypt(source, sink, encoding);
|
||||
|
||||
return sink.str();
|
||||
}
|
||||
|
||||
|
||||
std::string Cipher::decryptString(const std::string& str, Encoding encoding)
|
||||
{
|
||||
std::istringstream source(str);
|
||||
std::ostringstream sink;
|
||||
|
||||
decrypt(source, sink, encoding);
|
||||
return sink.str();
|
||||
}
|
||||
|
||||
|
||||
void Cipher::encrypt(std::istream& source, std::ostream& sink, Encoding encoding)
|
||||
{
|
||||
CryptoInputStream encryptor(source, createEncryptor());
|
||||
|
||||
switch (encoding)
|
||||
{
|
||||
case ENC_NONE:
|
||||
StreamCopier::copyStream(encryptor, sink);
|
||||
break;
|
||||
|
||||
case ENC_BASE64:
|
||||
case ENC_BASE64_NO_LF:
|
||||
{
|
||||
Poco::Base64Encoder encoder(sink);
|
||||
if (encoding == ENC_BASE64_NO_LF)
|
||||
{
|
||||
encoder.rdbuf()->setLineLength(0);
|
||||
}
|
||||
StreamCopier::copyStream(encryptor, encoder);
|
||||
encoder.close();
|
||||
}
|
||||
break;
|
||||
|
||||
case ENC_BINHEX:
|
||||
case ENC_BINHEX_NO_LF:
|
||||
{
|
||||
Poco::HexBinaryEncoder encoder(sink);
|
||||
if (encoding == ENC_BINHEX_NO_LF)
|
||||
{
|
||||
encoder.rdbuf()->setLineLength(0);
|
||||
}
|
||||
StreamCopier::copyStream(encryptor, encoder);
|
||||
encoder.close();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Poco::InvalidArgumentException("Invalid argument", "encoding");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Cipher::decrypt(std::istream& source, std::ostream& sink, Encoding encoding)
|
||||
{
|
||||
CryptoOutputStream decryptor(sink, createDecryptor());
|
||||
|
||||
switch (encoding)
|
||||
{
|
||||
case ENC_NONE:
|
||||
StreamCopier::copyStream(source, decryptor);
|
||||
decryptor.close();
|
||||
break;
|
||||
|
||||
case ENC_BASE64:
|
||||
case ENC_BASE64_NO_LF:
|
||||
{
|
||||
Poco::Base64Decoder decoder(source);
|
||||
StreamCopier::copyStream(decoder, decryptor);
|
||||
decryptor.close();
|
||||
}
|
||||
break;
|
||||
|
||||
case ENC_BINHEX:
|
||||
case ENC_BINHEX_NO_LF:
|
||||
{
|
||||
Poco::HexBinaryDecoder decoder(source);
|
||||
StreamCopier::copyStream(decoder, decryptor);
|
||||
decryptor.close();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Poco::InvalidArgumentException("Invalid argument", "encoding");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,67 +0,0 @@
|
||||
//
|
||||
// CipherFactory.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CipherFactory.cpp#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherFactory
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/CipherFactory.h"
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Crypto/CipherKey.h"
|
||||
#include "Poco/Crypto/RSAKey.h"
|
||||
#include "Poco/Crypto/CipherImpl.h"
|
||||
#include "Poco/Crypto/RSACipherImpl.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/SingletonHolder.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
CipherFactory::CipherFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CipherFactory::~CipherFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static Poco::SingletonHolder<CipherFactory> holder;
|
||||
}
|
||||
|
||||
|
||||
CipherFactory& CipherFactory::defaultFactory()
|
||||
{
|
||||
return *holder.get();
|
||||
}
|
||||
|
||||
|
||||
Cipher* CipherFactory::createCipher(const CipherKey& key)
|
||||
{
|
||||
return new CipherImpl(key);
|
||||
}
|
||||
|
||||
|
||||
Cipher* CipherFactory::createCipher(const RSAKey& key, RSAPaddingMode paddingMode)
|
||||
{
|
||||
return new RSACipherImpl(key, paddingMode);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,229 +0,0 @@
|
||||
//
|
||||
// CipherImpl.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CipherImpl.cpp#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherImpl
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/CipherImpl.h"
|
||||
#include "Poco/Crypto/CryptoTransform.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void throwError()
|
||||
{
|
||||
unsigned long err;
|
||||
std::string msg;
|
||||
|
||||
while ((err = ERR_get_error()))
|
||||
{
|
||||
if (!msg.empty())
|
||||
msg.append("; ");
|
||||
msg.append(ERR_error_string(err, 0));
|
||||
}
|
||||
|
||||
throw Poco::IOException(msg);
|
||||
}
|
||||
|
||||
|
||||
class CryptoTransformImpl: public CryptoTransform
|
||||
{
|
||||
public:
|
||||
typedef Cipher::ByteVec ByteVec;
|
||||
|
||||
enum Direction
|
||||
{
|
||||
DIR_ENCRYPT,
|
||||
DIR_DECRYPT
|
||||
};
|
||||
|
||||
CryptoTransformImpl(
|
||||
const EVP_CIPHER* pCipher,
|
||||
const ByteVec& key,
|
||||
const ByteVec& iv,
|
||||
Direction dir);
|
||||
|
||||
~CryptoTransformImpl();
|
||||
|
||||
std::size_t blockSize() const;
|
||||
|
||||
int setPadding(int padding);
|
||||
|
||||
std::streamsize transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength);
|
||||
|
||||
std::streamsize finalize(
|
||||
unsigned char* output,
|
||||
std::streamsize length);
|
||||
|
||||
private:
|
||||
const EVP_CIPHER* _pCipher;
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
EVP_CIPHER_CTX* _pContext;
|
||||
#else
|
||||
EVP_CIPHER_CTX _context;
|
||||
#endif
|
||||
ByteVec _key;
|
||||
ByteVec _iv;
|
||||
};
|
||||
|
||||
|
||||
CryptoTransformImpl::CryptoTransformImpl(
|
||||
const EVP_CIPHER* pCipher,
|
||||
const ByteVec& key,
|
||||
const ByteVec& iv,
|
||||
Direction dir):
|
||||
_pCipher(pCipher),
|
||||
_key(key),
|
||||
_iv(iv)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
_pContext = EVP_CIPHER_CTX_new();
|
||||
EVP_CipherInit(
|
||||
_pContext,
|
||||
_pCipher,
|
||||
&_key[0],
|
||||
_iv.empty() ? 0 : &_iv[0],
|
||||
(dir == DIR_ENCRYPT) ? 1 : 0);
|
||||
#else
|
||||
EVP_CipherInit(
|
||||
&_context,
|
||||
_pCipher,
|
||||
&_key[0],
|
||||
_iv.empty() ? 0 : &_iv[0],
|
||||
(dir == DIR_ENCRYPT) ? 1 : 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
CryptoTransformImpl::~CryptoTransformImpl()
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
EVP_CIPHER_CTX_cleanup(_pContext);
|
||||
#else
|
||||
EVP_CIPHER_CTX_cleanup(&_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::size_t CryptoTransformImpl::blockSize() const
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
return EVP_CIPHER_CTX_block_size(_pContext);
|
||||
#else
|
||||
return EVP_CIPHER_CTX_block_size(&_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int CryptoTransformImpl::setPadding(int padding)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
return EVP_CIPHER_CTX_block_size(_pContext);
|
||||
#else
|
||||
return EVP_CIPHER_CTX_set_padding(&_context, padding);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::streamsize CryptoTransformImpl::transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength)
|
||||
{
|
||||
poco_assert (outputLength >= (inputLength + blockSize() - 1));
|
||||
|
||||
int outLen = static_cast<int>(outputLength);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
int rc = EVP_CipherUpdate(
|
||||
_pContext,
|
||||
output,
|
||||
&outLen,
|
||||
input,
|
||||
static_cast<int>(inputLength));
|
||||
#else
|
||||
int rc = EVP_CipherUpdate(
|
||||
&_context,
|
||||
output,
|
||||
&outLen,
|
||||
input,
|
||||
static_cast<int>(inputLength));
|
||||
#endif
|
||||
if (rc == 0)
|
||||
throwError();
|
||||
|
||||
return static_cast<std::streamsize>(outLen);
|
||||
}
|
||||
|
||||
|
||||
std::streamsize CryptoTransformImpl::finalize(
|
||||
unsigned char* output,
|
||||
std::streamsize length)
|
||||
{
|
||||
poco_assert (length >= blockSize());
|
||||
|
||||
int len = static_cast<int>(length);
|
||||
|
||||
// Use the '_ex' version that does not perform implicit cleanup since we
|
||||
// will call EVP_CIPHER_CTX_cleanup() from the dtor as there is no
|
||||
// guarantee that finalize() will be called if an error occurred.
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
int rc = EVP_CipherFinal_ex(_pContext, output, &len);
|
||||
#else
|
||||
int rc = EVP_CipherFinal_ex(&_context, output, &len);
|
||||
#endif
|
||||
|
||||
if (rc == 0)
|
||||
throwError();
|
||||
|
||||
return static_cast<std::streamsize>(len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CipherImpl::CipherImpl(const CipherKey& key):
|
||||
_key(key)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CipherImpl::~CipherImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoTransform* CipherImpl::createEncryptor()
|
||||
{
|
||||
CipherKeyImpl::Ptr p = _key.impl();
|
||||
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_ENCRYPT);
|
||||
}
|
||||
|
||||
|
||||
CryptoTransform* CipherImpl::createDecryptor()
|
||||
{
|
||||
CipherKeyImpl::Ptr p = _key.impl();
|
||||
return new CryptoTransformImpl(p->cipher(), p->getKey(), p->getIV(), CryptoTransformImpl::DIR_DECRYPT);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,47 +0,0 @@
|
||||
//
|
||||
// CipherKey.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CipherKey.cpp#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherKey
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/CipherKey.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
CipherKey::CipherKey(const std::string& name, const std::string& passphrase, const std::string& salt, int iterationCount):
|
||||
_pImpl(new CipherKeyImpl(name, passphrase, salt, iterationCount))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CipherKey::CipherKey(const std::string& name, const ByteVec& key, const ByteVec& iv):
|
||||
_pImpl(new CipherKeyImpl(name, key, iv))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CipherKey::CipherKey(const std::string& name):
|
||||
_pImpl(new CipherKeyImpl(name))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CipherKey::~CipherKey()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,198 +0,0 @@
|
||||
//
|
||||
// CipherKeyImpl.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CipherKeyImpl.cpp#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CipherKeyImpl
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/CipherKeyImpl.h"
|
||||
#include "Poco/Crypto/CryptoTransform.h"
|
||||
#include "Poco/Crypto/CipherFactory.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/RandomStream.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
CipherKeyImpl::CipherKeyImpl(const std::string& name,
|
||||
const std::string& passphrase,
|
||||
const std::string& salt,
|
||||
int iterationCount):
|
||||
_pCipher(0),
|
||||
_name(name),
|
||||
_key(),
|
||||
_iv()
|
||||
{
|
||||
// dummy access to Cipherfactory so that the EVP lib is initilaized
|
||||
CipherFactory::defaultFactory();
|
||||
_pCipher = EVP_get_cipherbyname(name.c_str());
|
||||
|
||||
if (!_pCipher)
|
||||
throw Poco::NotFoundException("Cipher " + name + " was not found");
|
||||
_key = ByteVec(keySize());
|
||||
_iv = ByteVec(ivSize());
|
||||
generateKey(passphrase, salt, iterationCount);
|
||||
}
|
||||
|
||||
|
||||
CipherKeyImpl::CipherKeyImpl(const std::string& name,
|
||||
const ByteVec& key,
|
||||
const ByteVec& iv):
|
||||
_pCipher(0),
|
||||
_name(name),
|
||||
_key(key),
|
||||
_iv(iv)
|
||||
{
|
||||
// dummy access to Cipherfactory so that the EVP lib is initilaized
|
||||
CipherFactory::defaultFactory();
|
||||
_pCipher = EVP_get_cipherbyname(name.c_str());
|
||||
|
||||
if (!_pCipher)
|
||||
throw Poco::NotFoundException("Cipher " + name + " was not found");
|
||||
}
|
||||
|
||||
|
||||
CipherKeyImpl::CipherKeyImpl(const std::string& name):
|
||||
_pCipher(0),
|
||||
_name(name),
|
||||
_key(),
|
||||
_iv()
|
||||
{
|
||||
// dummy access to Cipherfactory so that the EVP lib is initilaized
|
||||
CipherFactory::defaultFactory();
|
||||
_pCipher = EVP_get_cipherbyname(name.c_str());
|
||||
|
||||
if (!_pCipher)
|
||||
throw Poco::NotFoundException("Cipher " + name + " was not found");
|
||||
_key = ByteVec(keySize());
|
||||
_iv = ByteVec(ivSize());
|
||||
generateKey();
|
||||
}
|
||||
|
||||
|
||||
CipherKeyImpl::~CipherKeyImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CipherKeyImpl::Mode CipherKeyImpl::mode() const
|
||||
{
|
||||
switch (EVP_CIPHER_mode(_pCipher))
|
||||
{
|
||||
case EVP_CIPH_STREAM_CIPHER:
|
||||
return MODE_STREAM_CIPHER;
|
||||
|
||||
case EVP_CIPH_ECB_MODE:
|
||||
return MODE_ECB;
|
||||
|
||||
case EVP_CIPH_CBC_MODE:
|
||||
return MODE_CBC;
|
||||
|
||||
case EVP_CIPH_CFB_MODE:
|
||||
return MODE_CFB;
|
||||
|
||||
case EVP_CIPH_OFB_MODE:
|
||||
return MODE_OFB;
|
||||
}
|
||||
throw Poco::IllegalStateException("Unexpected value of EVP_CIPHER_mode()");
|
||||
}
|
||||
|
||||
|
||||
void CipherKeyImpl::generateKey()
|
||||
{
|
||||
ByteVec vec;
|
||||
|
||||
getRandomBytes(vec, keySize());
|
||||
setKey(vec);
|
||||
|
||||
getRandomBytes(vec, ivSize());
|
||||
setIV(vec);
|
||||
}
|
||||
|
||||
|
||||
void CipherKeyImpl::getRandomBytes(ByteVec& vec, std::size_t count)
|
||||
{
|
||||
Poco::RandomInputStream random;
|
||||
|
||||
vec.clear();
|
||||
vec.reserve(count);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
vec.push_back(static_cast<unsigned char>(random.get()));
|
||||
}
|
||||
|
||||
|
||||
void CipherKeyImpl::generateKey(
|
||||
const std::string& password,
|
||||
const std::string& salt,
|
||||
int iterationCount)
|
||||
{
|
||||
unsigned char keyBytes[EVP_MAX_KEY_LENGTH];
|
||||
unsigned char ivBytes[EVP_MAX_IV_LENGTH];
|
||||
|
||||
// OpenSSL documentation specifies that the salt must be an 8-byte array.
|
||||
unsigned char saltBytes[8];
|
||||
|
||||
if (!salt.empty())
|
||||
{
|
||||
int len = static_cast<int>(salt.size());
|
||||
// Create the salt array from the salt string
|
||||
for (int i = 0; i < 8; ++i)
|
||||
saltBytes[i] = salt.at(i % len);
|
||||
for (int i = 8; i < len; ++i)
|
||||
saltBytes[i % 8] ^= salt.at(i);
|
||||
}
|
||||
|
||||
// Now create the key and IV, using the MD5 digest algorithm.
|
||||
int keySize = EVP_BytesToKey(
|
||||
_pCipher,
|
||||
EVP_md5(),
|
||||
(salt.empty() ? 0 : saltBytes),
|
||||
reinterpret_cast<const unsigned char*>(password.data()),
|
||||
static_cast<int>(password.size()),
|
||||
iterationCount,
|
||||
keyBytes,
|
||||
ivBytes);
|
||||
|
||||
// Copy the buffers to our member byte vectors.
|
||||
_key.assign(keyBytes, keyBytes + keySize);
|
||||
|
||||
if (ivSize() == 0)
|
||||
_iv.clear();
|
||||
else
|
||||
_iv.assign(ivBytes, ivBytes + ivSize());
|
||||
}
|
||||
|
||||
|
||||
int CipherKeyImpl::keySize() const
|
||||
{
|
||||
return EVP_CIPHER_key_length(_pCipher);
|
||||
}
|
||||
|
||||
|
||||
int CipherKeyImpl::blockSize() const
|
||||
{
|
||||
return EVP_CIPHER_block_size(_pCipher);
|
||||
}
|
||||
|
||||
|
||||
int CipherKeyImpl::ivSize() const
|
||||
{
|
||||
return EVP_CIPHER_iv_length(_pCipher);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,357 +0,0 @@
|
||||
//
|
||||
// CryptoStream.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CryptoStream.cpp#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CryptoStream
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/CryptoStream.h"
|
||||
#include "Poco/Crypto/CryptoTransform.h"
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
//
|
||||
// CryptoStreamBuf
|
||||
//
|
||||
|
||||
|
||||
CryptoStreamBuf::CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
||||
Poco::BufferedStreamBuf(bufferSize, std::ios::in),
|
||||
_pTransform(pTransform),
|
||||
_pIstr(&istr),
|
||||
_pOstr(0),
|
||||
_eof(false),
|
||||
_buffer(static_cast<std::size_t>(bufferSize))
|
||||
{
|
||||
poco_check_ptr (pTransform);
|
||||
poco_assert (bufferSize > 2 * pTransform->blockSize());
|
||||
}
|
||||
|
||||
|
||||
CryptoStreamBuf::CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
||||
Poco::BufferedStreamBuf(bufferSize, std::ios::out),
|
||||
_pTransform(pTransform),
|
||||
_pIstr(0),
|
||||
_pOstr(&ostr),
|
||||
_eof(false),
|
||||
_buffer(static_cast<std::size_t>(bufferSize))
|
||||
{
|
||||
poco_check_ptr (pTransform);
|
||||
poco_assert (bufferSize > 2 * pTransform->blockSize());
|
||||
}
|
||||
|
||||
|
||||
CryptoStreamBuf::~CryptoStreamBuf()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
delete _pTransform;
|
||||
}
|
||||
|
||||
|
||||
void CryptoStreamBuf::close()
|
||||
{
|
||||
sync();
|
||||
|
||||
if (_pIstr)
|
||||
{
|
||||
_pIstr = 0;
|
||||
}
|
||||
else if (_pOstr)
|
||||
{
|
||||
// Close can be called multiple times. By zeroing the pointer we make
|
||||
// sure that we call finalize() only once, even if an exception is
|
||||
// thrown.
|
||||
std::ostream* pOstr = _pOstr;
|
||||
_pOstr = 0;
|
||||
|
||||
// Finalize transformation.
|
||||
std::streamsize n = _pTransform->finalize(_buffer.begin(), static_cast<std::streamsize>(_buffer.size()));
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
pOstr->write(reinterpret_cast<char*>(_buffer.begin()), n);
|
||||
if (!pOstr->good())
|
||||
throw Poco::IOException("Output stream failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int CryptoStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_pIstr)
|
||||
return 0;
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (!_eof)
|
||||
{
|
||||
int m = (static_cast<int>(length) - count)/2 - static_cast<int>(_pTransform->blockSize());
|
||||
|
||||
// Make sure we can read at least one more block. Explicitely check
|
||||
// for m < 0 since blockSize() returns an unsigned int and the
|
||||
// comparison might give false results for m < 0.
|
||||
if (m <= 0)
|
||||
break;
|
||||
|
||||
int n = 0;
|
||||
|
||||
if (_pIstr->good())
|
||||
{
|
||||
_pIstr->read(reinterpret_cast<char*>(_buffer.begin()), m);
|
||||
n = static_cast<int>(_pIstr->gcount());
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
{
|
||||
_eof = true;
|
||||
|
||||
// No more data, finalize transformation
|
||||
count += static_cast<int>(_pTransform->finalize(
|
||||
reinterpret_cast<unsigned char*>(buffer + count),
|
||||
static_cast<int>(length) - count));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Transform next chunk of data
|
||||
count += static_cast<int>(_pTransform->transform(
|
||||
_buffer.begin(),
|
||||
n,
|
||||
reinterpret_cast<unsigned char*>(buffer + count),
|
||||
static_cast<int>(length) - count));
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
int CryptoStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
||||
{
|
||||
if (!_pOstr)
|
||||
return 0;
|
||||
|
||||
std::size_t maxChunkSize = _buffer.size()/2;
|
||||
std::size_t count = 0;
|
||||
|
||||
while (count < length)
|
||||
{
|
||||
// Truncate chunk size so that the maximum output fits into _buffer.
|
||||
std::size_t n = static_cast<std::size_t>(length) - count;
|
||||
if (n > maxChunkSize)
|
||||
n = maxChunkSize;
|
||||
|
||||
// Transform next chunk of data
|
||||
std::streamsize k = _pTransform->transform(
|
||||
reinterpret_cast<const unsigned char*>(buffer + count),
|
||||
static_cast<std::streamsize>(n),
|
||||
_buffer.begin(),
|
||||
static_cast<std::streamsize>(_buffer.size()));
|
||||
|
||||
// Attention: (n != k) might be true. In count, we have to track how
|
||||
// many bytes from buffer have been consumed, not how many bytes have
|
||||
// been written to _pOstr!
|
||||
count += n;
|
||||
|
||||
if (k > 0)
|
||||
{
|
||||
_pOstr->write(reinterpret_cast<const char*>(_buffer.begin()), k);
|
||||
if (!_pOstr->good())
|
||||
throw Poco::IOException("Output stream failure");
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<int>(count);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CryptoIOS
|
||||
//
|
||||
|
||||
|
||||
CryptoIOS::CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
||||
_buf(istr, pTransform, bufferSize)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
CryptoIOS::CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
||||
_buf(ostr, pTransform, bufferSize)
|
||||
{
|
||||
poco_ios_init(&_buf);
|
||||
}
|
||||
|
||||
|
||||
CryptoIOS::~CryptoIOS()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoStreamBuf* CryptoIOS::rdbuf()
|
||||
{
|
||||
return &_buf;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CryptoInputStream
|
||||
//
|
||||
|
||||
|
||||
CryptoInputStream::CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
||||
CryptoIOS(istr, pTransform, bufferSize),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoInputStream::CryptoInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize):
|
||||
CryptoIOS(istr, cipher.createEncryptor(), bufferSize),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoInputStream::~CryptoInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CryptoOutputStream
|
||||
//
|
||||
|
||||
|
||||
CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize):
|
||||
CryptoIOS(ostr, pTransform, bufferSize),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoOutputStream::CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize):
|
||||
CryptoIOS(ostr, cipher.createDecryptor(), bufferSize),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoOutputStream::~CryptoOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CryptoOutputStream::close()
|
||||
{
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// EncryptingInputStream
|
||||
//
|
||||
|
||||
|
||||
EncryptingInputStream::EncryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize):
|
||||
CryptoIOS(istr, cipher.createEncryptor(), bufferSize),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EncryptingInputStream::~EncryptingInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// EncryptingOuputStream
|
||||
//
|
||||
|
||||
|
||||
EncryptingOutputStream::EncryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize):
|
||||
CryptoIOS(ostr, cipher.createEncryptor(), bufferSize),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
EncryptingOutputStream::~EncryptingOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void EncryptingOutputStream::close()
|
||||
{
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// DecryptingInputStream
|
||||
//
|
||||
|
||||
|
||||
DecryptingInputStream::DecryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize):
|
||||
CryptoIOS(istr, cipher.createDecryptor(), bufferSize),
|
||||
std::istream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DecryptingInputStream::~DecryptingInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// DecryptingOuputStream
|
||||
//
|
||||
|
||||
|
||||
DecryptingOutputStream::DecryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize):
|
||||
CryptoIOS(ostr, cipher.createDecryptor(), bufferSize),
|
||||
std::ostream(&_buf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DecryptingOutputStream::~DecryptingOutputStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DecryptingOutputStream::close()
|
||||
{
|
||||
_buf.close();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,40 +0,0 @@
|
||||
//
|
||||
// CryptoTransform.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/CryptoTransform.cpp#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Cipher
|
||||
// Module: CryptoTransform
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/CryptoTransform.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
CryptoTransform::CryptoTransform()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoTransform::~CryptoTransform()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int CryptoTransform::setPadding(int padding)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,82 +0,0 @@
|
||||
//
|
||||
// DigestEngine.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/DigestEngine.cpp#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Digest
|
||||
// Module: DigestEngine
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/DigestEngine.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
DigestEngine::DigestEngine(const std::string& name):
|
||||
_name(name),
|
||||
_pContext(EVP_MD_CTX_create())
|
||||
{
|
||||
const EVP_MD* md = EVP_get_digestbyname(_name.c_str());
|
||||
if (!md) throw Poco::NotFoundException(_name);
|
||||
EVP_DigestInit_ex(_pContext, md, NULL);
|
||||
}
|
||||
|
||||
|
||||
DigestEngine::~DigestEngine()
|
||||
{
|
||||
EVP_MD_CTX_destroy(_pContext);
|
||||
}
|
||||
|
||||
int DigestEngine::nid() const
|
||||
{
|
||||
return EVP_MD_nid(EVP_MD_CTX_md(_pContext));
|
||||
}
|
||||
|
||||
std::size_t DigestEngine::digestLength() const
|
||||
{
|
||||
return EVP_MD_CTX_size(_pContext);
|
||||
}
|
||||
|
||||
|
||||
void DigestEngine::reset()
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
EVP_MD_CTX_free(_pContext);
|
||||
_pContext = EVP_MD_CTX_create();
|
||||
#else
|
||||
EVP_MD_CTX_cleanup(_pContext);
|
||||
#endif
|
||||
const EVP_MD* md = EVP_get_digestbyname(_name.c_str());
|
||||
if (!md) throw Poco::NotFoundException(_name);
|
||||
EVP_DigestInit_ex(_pContext, md, NULL);
|
||||
}
|
||||
|
||||
|
||||
const Poco::DigestEngine::Digest& DigestEngine::digest()
|
||||
{
|
||||
_digest.clear();
|
||||
unsigned len = EVP_MD_CTX_size(_pContext);
|
||||
_digest.resize(len);
|
||||
EVP_DigestFinal_ex(_pContext, &_digest[0], &len);
|
||||
reset();
|
||||
return _digest;
|
||||
}
|
||||
|
||||
|
||||
void DigestEngine::updateImpl(const void* data, std::size_t length)
|
||||
{
|
||||
EVP_DigestUpdate(_pContext, data, length);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,166 +0,0 @@
|
||||
//
|
||||
// OpenSSLInitializer.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/OpenSSLInitializer.cpp#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: CryptoCore
|
||||
// Module: OpenSSLInitializer
|
||||
//
|
||||
// Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/OpenSSLInitializer.h"
|
||||
#include "Poco/RandomStream.h"
|
||||
#include "Poco/Thread.h"
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/err.h>
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
|
||||
#include <openssl/conf.h>
|
||||
#endif
|
||||
|
||||
|
||||
using Poco::RandomInputStream;
|
||||
using Poco::Thread;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
Poco::FastMutex* OpenSSLInitializer::_mutexes(0);
|
||||
Poco::AtomicCounter OpenSSLInitializer::_rc;
|
||||
|
||||
|
||||
OpenSSLInitializer::OpenSSLInitializer()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
|
||||
OpenSSLInitializer::~OpenSSLInitializer()
|
||||
{
|
||||
try
|
||||
{
|
||||
uninitialize();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::initialize()
|
||||
{
|
||||
if (++_rc == 1)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
|
||||
OPENSSL_config(NULL);
|
||||
#endif
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
OpenSSL_add_all_algorithms();
|
||||
|
||||
char seed[SEEDSIZE];
|
||||
RandomInputStream rnd;
|
||||
rnd.read(seed, sizeof(seed));
|
||||
RAND_seed(seed, SEEDSIZE);
|
||||
|
||||
int nMutexes = CRYPTO_num_locks();
|
||||
_mutexes = new Poco::FastMutex[nMutexes];
|
||||
CRYPTO_set_locking_callback(&OpenSSLInitializer::lock);
|
||||
#ifndef POCO_OS_FAMILY_WINDOWS
|
||||
// Not needed on Windows (see SF #110: random unhandled exceptions when linking with ssl).
|
||||
// https://sourceforge.net/p/poco/bugs/110/
|
||||
//
|
||||
// From http://www.openssl.org/docs/crypto/threads.html :
|
||||
// "If the application does not register such a callback using CRYPTO_THREADID_set_callback(),
|
||||
// then a default implementation is used - on Windows and BeOS this uses the system's
|
||||
// default thread identifying APIs"
|
||||
CRYPTO_set_id_callback(&OpenSSLInitializer::id);
|
||||
#endif
|
||||
CRYPTO_set_dynlock_create_callback(&OpenSSLInitializer::dynlockCreate);
|
||||
CRYPTO_set_dynlock_lock_callback(&OpenSSLInitializer::dynlock);
|
||||
CRYPTO_set_dynlock_destroy_callback(&OpenSSLInitializer::dynlockDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::uninitialize()
|
||||
{
|
||||
if (--_rc == 0)
|
||||
{
|
||||
EVP_cleanup();
|
||||
ERR_free_strings();
|
||||
CRYPTO_set_locking_callback(0);
|
||||
#ifndef POCO_OS_FAMILY_WINDOWS
|
||||
CRYPTO_set_id_callback(0);
|
||||
#endif
|
||||
delete [] _mutexes;
|
||||
|
||||
CONF_modules_free();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::lock(int mode, int n, const char* file, int line)
|
||||
{
|
||||
if (mode & CRYPTO_LOCK)
|
||||
_mutexes[n].lock();
|
||||
else
|
||||
_mutexes[n].unlock();
|
||||
}
|
||||
|
||||
|
||||
unsigned long OpenSSLInitializer::id()
|
||||
{
|
||||
// Note: we use an old-style C cast here because
|
||||
// neither static_cast<> nor reinterpret_cast<>
|
||||
// work uniformly across all platforms.
|
||||
return (unsigned long) Poco::Thread::currentTid();
|
||||
}
|
||||
|
||||
|
||||
struct CRYPTO_dynlock_value* OpenSSLInitializer::dynlockCreate(const char* file, int line)
|
||||
{
|
||||
return new CRYPTO_dynlock_value;
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line)
|
||||
{
|
||||
poco_check_ptr (lock);
|
||||
|
||||
if (mode & CRYPTO_LOCK)
|
||||
lock->_mutex.lock();
|
||||
else
|
||||
lock->_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void OpenSSLInitializer::dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line)
|
||||
{
|
||||
delete lock;
|
||||
}
|
||||
|
||||
|
||||
void initializeCrypto()
|
||||
{
|
||||
OpenSSLInitializer::initialize();
|
||||
}
|
||||
|
||||
|
||||
void uninitializeCrypto()
|
||||
{
|
||||
OpenSSLInitializer::uninitialize();
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,320 +0,0 @@
|
||||
//
|
||||
// RSACipherImpl.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/RSACipherImpl.cpp#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSACipherImpl
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/RSACipherImpl.h"
|
||||
#include "Poco/Crypto/CryptoTransform.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
void throwError()
|
||||
{
|
||||
unsigned long err;
|
||||
std::string msg;
|
||||
|
||||
while ((err = ERR_get_error()))
|
||||
{
|
||||
if (!msg.empty())
|
||||
msg.append("; ");
|
||||
msg.append(ERR_error_string(err, 0));
|
||||
}
|
||||
|
||||
throw Poco::IOException(msg);
|
||||
}
|
||||
|
||||
|
||||
int mapPaddingMode(RSAPaddingMode paddingMode)
|
||||
{
|
||||
switch (paddingMode)
|
||||
{
|
||||
case RSA_PADDING_PKCS1:
|
||||
return RSA_PKCS1_PADDING;
|
||||
case RSA_PADDING_PKCS1_OAEP:
|
||||
return RSA_PKCS1_OAEP_PADDING;
|
||||
case RSA_PADDING_SSLV23:
|
||||
return RSA_SSLV23_PADDING;
|
||||
case RSA_PADDING_NONE:
|
||||
return RSA_NO_PADDING;
|
||||
default:
|
||||
poco_bugcheck();
|
||||
return RSA_NO_PADDING;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class RSAEncryptImpl: public CryptoTransform
|
||||
{
|
||||
public:
|
||||
RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
|
||||
~RSAEncryptImpl();
|
||||
|
||||
std::size_t blockSize() const;
|
||||
std::size_t maxDataSize() const;
|
||||
|
||||
std::streamsize transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength);
|
||||
|
||||
std::streamsize finalize(unsigned char* output, std::streamsize length);
|
||||
|
||||
private:
|
||||
const RSA* _pRSA;
|
||||
RSAPaddingMode _paddingMode;
|
||||
std::streamsize _pos;
|
||||
unsigned char* _pBuf;
|
||||
};
|
||||
|
||||
|
||||
RSAEncryptImpl::RSAEncryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode):
|
||||
_pRSA(pRSA),
|
||||
_paddingMode(paddingMode),
|
||||
_pos(0),
|
||||
_pBuf(0)
|
||||
{
|
||||
_pBuf = new unsigned char[blockSize()];
|
||||
}
|
||||
|
||||
|
||||
RSAEncryptImpl::~RSAEncryptImpl()
|
||||
{
|
||||
delete [] _pBuf;
|
||||
}
|
||||
|
||||
|
||||
std::size_t RSAEncryptImpl::blockSize() const
|
||||
{
|
||||
return RSA_size(_pRSA);
|
||||
}
|
||||
|
||||
|
||||
std::size_t RSAEncryptImpl::maxDataSize() const
|
||||
{
|
||||
std::size_t size = blockSize();
|
||||
switch (_paddingMode)
|
||||
{
|
||||
case RSA_PADDING_PKCS1:
|
||||
case RSA_PADDING_SSLV23:
|
||||
size -= 11;
|
||||
break;
|
||||
case RSA_PADDING_PKCS1_OAEP:
|
||||
size -= 41;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
std::streamsize RSAEncryptImpl::transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength)
|
||||
{
|
||||
// always fill up the buffer before writing!
|
||||
std::streamsize maxSize = static_cast<std::streamsize>(maxDataSize());
|
||||
std::streamsize rsaSize = static_cast<std::streamsize>(blockSize());
|
||||
poco_assert_dbg(_pos <= maxSize);
|
||||
poco_assert (outputLength >= rsaSize);
|
||||
int rc = 0;
|
||||
while (inputLength > 0)
|
||||
{
|
||||
// check how many data bytes we are missing to get the buffer full
|
||||
poco_assert_dbg (maxSize >= _pos);
|
||||
std::streamsize missing = maxSize - _pos;
|
||||
if (missing == 0)
|
||||
{
|
||||
poco_assert (outputLength >= rsaSize);
|
||||
int n = RSA_public_encrypt(static_cast<int>(maxSize), _pBuf, output, const_cast<RSA*>(_pRSA), mapPaddingMode(_paddingMode));
|
||||
if (n == -1)
|
||||
throwError();
|
||||
rc += n;
|
||||
output += n;
|
||||
outputLength -= n;
|
||||
_pos = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (missing > inputLength)
|
||||
missing = inputLength;
|
||||
|
||||
std::memcpy(_pBuf + _pos, input, static_cast<std::size_t>(missing));
|
||||
input += missing;
|
||||
_pos += missing;
|
||||
inputLength -= missing;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
std::streamsize RSAEncryptImpl::finalize(unsigned char* output, std::streamsize length)
|
||||
{
|
||||
poco_assert (length >= blockSize());
|
||||
poco_assert (_pos <= maxDataSize());
|
||||
int rc = 0;
|
||||
if (_pos > 0)
|
||||
{
|
||||
rc = RSA_public_encrypt(static_cast<int>(_pos), _pBuf, output, const_cast<RSA*>(_pRSA), mapPaddingMode(_paddingMode));
|
||||
if (rc == -1) throwError();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
class RSADecryptImpl: public CryptoTransform
|
||||
{
|
||||
public:
|
||||
RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode);
|
||||
~RSADecryptImpl();
|
||||
|
||||
std::size_t blockSize() const;
|
||||
|
||||
std::streamsize transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength);
|
||||
|
||||
std::streamsize finalize(
|
||||
unsigned char* output,
|
||||
std::streamsize length);
|
||||
|
||||
private:
|
||||
const RSA* _pRSA;
|
||||
RSAPaddingMode _paddingMode;
|
||||
std::streamsize _pos;
|
||||
unsigned char* _pBuf;
|
||||
};
|
||||
|
||||
|
||||
RSADecryptImpl::RSADecryptImpl(const RSA* pRSA, RSAPaddingMode paddingMode):
|
||||
_pRSA(pRSA),
|
||||
_paddingMode(paddingMode),
|
||||
_pos(0),
|
||||
_pBuf(0)
|
||||
{
|
||||
_pBuf = new unsigned char[blockSize()];
|
||||
}
|
||||
|
||||
|
||||
RSADecryptImpl::~RSADecryptImpl()
|
||||
{
|
||||
delete [] _pBuf;
|
||||
}
|
||||
|
||||
|
||||
std::size_t RSADecryptImpl::blockSize() const
|
||||
{
|
||||
return RSA_size(_pRSA);
|
||||
}
|
||||
|
||||
|
||||
std::streamsize RSADecryptImpl::transform(
|
||||
const unsigned char* input,
|
||||
std::streamsize inputLength,
|
||||
unsigned char* output,
|
||||
std::streamsize outputLength)
|
||||
{
|
||||
|
||||
// always fill up the buffer before decrypting!
|
||||
std::streamsize rsaSize = static_cast<std::streamsize>(blockSize());
|
||||
poco_assert_dbg(_pos <= rsaSize);
|
||||
poco_assert (outputLength >= rsaSize);
|
||||
int rc = 0;
|
||||
while (inputLength > 0)
|
||||
{
|
||||
// check how many data bytes we are missing to get the buffer full
|
||||
poco_assert_dbg (rsaSize >= _pos);
|
||||
std::streamsize missing = rsaSize - _pos;
|
||||
if (missing == 0)
|
||||
{
|
||||
int tmp = RSA_private_decrypt(static_cast<int>(rsaSize), _pBuf, output, const_cast<RSA*>(_pRSA), mapPaddingMode(_paddingMode));
|
||||
if (tmp == -1)
|
||||
throwError();
|
||||
rc += tmp;
|
||||
output += tmp;
|
||||
outputLength -= tmp;
|
||||
_pos = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (missing > inputLength)
|
||||
missing = inputLength;
|
||||
|
||||
std::memcpy(_pBuf + _pos, input, static_cast<std::size_t>(missing));
|
||||
input += missing;
|
||||
_pos += missing;
|
||||
inputLength -= missing;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
std::streamsize RSADecryptImpl::finalize(unsigned char* output, std::streamsize length)
|
||||
{
|
||||
poco_assert (length >= blockSize());
|
||||
int rc = 0;
|
||||
if (_pos > 0)
|
||||
{
|
||||
rc = RSA_private_decrypt(static_cast<int>(_pos), _pBuf, output, const_cast<RSA*>(_pRSA), mapPaddingMode(_paddingMode));
|
||||
if (rc == -1)
|
||||
throwError();
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RSACipherImpl::RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode):
|
||||
_key(key),
|
||||
_paddingMode(paddingMode)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RSACipherImpl::~RSACipherImpl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoTransform* RSACipherImpl::createEncryptor()
|
||||
{
|
||||
return new RSAEncryptImpl(_key.impl()->getRSA(), _paddingMode);
|
||||
}
|
||||
|
||||
|
||||
CryptoTransform* RSACipherImpl::createDecryptor()
|
||||
{
|
||||
return new RSADecryptImpl(_key.impl()->getRSA(), _paddingMode);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,98 +0,0 @@
|
||||
//
|
||||
// RSADigestEngine.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/RSADigestEngine.cpp#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSADigestEngine
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/RSADigestEngine.h"
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
RSADigestEngine::RSADigestEngine(const RSAKey& key, DigestType digestType):
|
||||
_key(key),
|
||||
_engine(digestType == DIGEST_MD5 ? "MD5" : "SHA1")
|
||||
{
|
||||
}
|
||||
|
||||
RSADigestEngine::RSADigestEngine(const RSAKey& key, const std::string &name):
|
||||
_key(key),
|
||||
_engine(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RSADigestEngine::~RSADigestEngine()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
std::size_t RSADigestEngine::digestLength() const
|
||||
{
|
||||
return _engine.digestLength();
|
||||
}
|
||||
|
||||
|
||||
void RSADigestEngine::reset()
|
||||
{
|
||||
_engine.reset();
|
||||
_digest.clear();
|
||||
_signature.clear();
|
||||
}
|
||||
|
||||
|
||||
const DigestEngine::Digest& RSADigestEngine::digest()
|
||||
{
|
||||
if (_digest.empty())
|
||||
{
|
||||
_digest = _engine.digest();
|
||||
}
|
||||
return _digest;
|
||||
}
|
||||
|
||||
|
||||
const DigestEngine::Digest& RSADigestEngine::signature()
|
||||
{
|
||||
if (_signature.empty())
|
||||
{
|
||||
digest();
|
||||
_signature.resize(_key.size());
|
||||
unsigned sigLen = static_cast<unsigned>(_signature.size());
|
||||
RSA_sign(_engine.nid(), &_digest[0], static_cast<unsigned>(_digest.size()), &_signature[0], &sigLen, _key.impl()->getRSA());
|
||||
// truncate _sig to sigLen
|
||||
if (sigLen < _signature.size())
|
||||
_signature.resize(sigLen);
|
||||
}
|
||||
return _signature;
|
||||
}
|
||||
|
||||
|
||||
bool RSADigestEngine::verify(const DigestEngine::Digest& sig)
|
||||
{
|
||||
digest();
|
||||
DigestEngine::Digest sigCpy = sig; // copy becausse RSA_verify can modify sigCpy
|
||||
int ret = RSA_verify(_engine.nid(), &_digest[0], static_cast<unsigned>(_digest.size()), &sigCpy[0], static_cast<unsigned>(sigCpy.size()), _key.impl()->getRSA());
|
||||
return ret != 0;
|
||||
}
|
||||
|
||||
|
||||
void RSADigestEngine::updateImpl(const void* data, std::size_t length)
|
||||
{
|
||||
_engine.update(data, length);
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,107 +0,0 @@
|
||||
//
|
||||
// RSAKey.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/RSAKey.cpp#2 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSAKey
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/RSAKey.h"
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
RSAKey::RSAKey(const X509Certificate& cert):
|
||||
_pImpl(new RSAKeyImpl(cert))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
|
||||
_pImpl(0)
|
||||
{
|
||||
int keyLen = keyLength;
|
||||
unsigned long expVal = RSA_3;
|
||||
if (exp == EXP_LARGE)
|
||||
expVal = RSA_F4;
|
||||
_pImpl = new RSAKeyImpl(keyLen, expVal);
|
||||
}
|
||||
|
||||
|
||||
RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
|
||||
_pImpl(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
|
||||
_pImpl(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RSAKey::~RSAKey()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int RSAKey::size() const
|
||||
{
|
||||
return _pImpl->size();
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKey::modulus() const
|
||||
{
|
||||
return _pImpl->modulus();
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const
|
||||
{
|
||||
return _pImpl->encryptionExponent();
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const
|
||||
{
|
||||
return _pImpl->decryptionExponent();
|
||||
}
|
||||
|
||||
|
||||
void RSAKey::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
|
||||
{
|
||||
_pImpl->save(publicKeyFile, privateKeyFile, privateKeyPassphrase);
|
||||
}
|
||||
|
||||
|
||||
void RSAKey::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase)
|
||||
{
|
||||
_pImpl->save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
static const std::string RSA("rsa");
|
||||
}
|
||||
|
||||
|
||||
const std::string& RSAKey::name() const
|
||||
{
|
||||
return RSA;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,360 +0,0 @@
|
||||
//
|
||||
// RSAKeyImpl.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/RSAKeyImpl.cpp#3 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: RSA
|
||||
// Module: RSAKeyImpl
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/RSAKeyImpl.h"
|
||||
#include "Poco/Crypto/X509Certificate.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include <sstream>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/evp.h>
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
|
||||
#include <openssl/bn.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
RSAKeyImpl::RSAKeyImpl(const X509Certificate& cert):
|
||||
_pRSA(0)
|
||||
{
|
||||
const X509* pCert = cert.certificate();
|
||||
EVP_PKEY* pKey = X509_get_pubkey(const_cast<X509*>(pCert));
|
||||
_pRSA = EVP_PKEY_get1_RSA(pKey);
|
||||
EVP_PKEY_free(pKey);
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent):
|
||||
_pRSA(0)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
|
||||
_pRSA = RSA_new();
|
||||
int ret = 0;
|
||||
BIGNUM* bn = 0;
|
||||
try
|
||||
{
|
||||
bn = BN_new();
|
||||
BN_set_word(bn, exponent);
|
||||
ret = RSA_generate_key_ex(_pRSA, keyLength, bn, 0);
|
||||
BN_free(bn);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BN_free(bn);
|
||||
throw;
|
||||
}
|
||||
if (!ret) throw Poco::InvalidArgumentException("Failed to create RSA context");
|
||||
#else
|
||||
_pRSA = RSA_generate_key(keyLength, exponent, 0, 0);
|
||||
if (!_pRSA) throw Poco::InvalidArgumentException("Failed to create RSA context");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::RSAKeyImpl(
|
||||
const std::string& publicKeyFile,
|
||||
const std::string& privateKeyFile,
|
||||
const std::string& privateKeyPassphrase):
|
||||
_pRSA(0)
|
||||
{
|
||||
poco_assert_dbg(_pRSA == 0);
|
||||
|
||||
_pRSA = RSA_new();
|
||||
if (!publicKeyFile.empty())
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_file());
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for reading public key", publicKeyFile);
|
||||
int rc = BIO_read_filename(bio, publicKeyFile.c_str());
|
||||
if (rc)
|
||||
{
|
||||
RSA* pubKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
|
||||
if (!pubKey)
|
||||
{
|
||||
int rc = BIO_reset(bio);
|
||||
// BIO_reset() normally returns 1 for success and 0 or -1 for failure.
|
||||
// File BIOs are an exception, they return 0 for success and -1 for failure.
|
||||
if (rc != 0) throw Poco::FileException("Failed to load public key", publicKeyFile);
|
||||
pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
|
||||
}
|
||||
BIO_free(bio);
|
||||
if (!pubKey)
|
||||
{
|
||||
freeRSA();
|
||||
throw Poco::FileException("Failed to load public key", publicKeyFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
freeRSA();
|
||||
throw Poco::FileNotFoundException("Public key file", publicKeyFile);
|
||||
}
|
||||
}
|
||||
|
||||
if (!privateKeyFile.empty())
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_file());
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for reading private key", privateKeyFile);
|
||||
int rc = BIO_read_filename(bio, privateKeyFile.c_str());
|
||||
if (rc)
|
||||
{
|
||||
RSA* privKey = 0;
|
||||
if (privateKeyPassphrase.empty())
|
||||
privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, 0);
|
||||
else
|
||||
privKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, const_cast<char*>(privateKeyPassphrase.c_str()));
|
||||
BIO_free(bio);
|
||||
if (!privKey)
|
||||
{
|
||||
freeRSA();
|
||||
throw Poco::FileException("Failed to load private key", privateKeyFile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
freeRSA();
|
||||
throw Poco::FileNotFoundException("Private key file", privateKeyFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
|
||||
_pRSA(0)
|
||||
{
|
||||
poco_assert_dbg(_pRSA == 0);
|
||||
|
||||
_pRSA = RSA_new();
|
||||
if (pPublicKeyStream)
|
||||
{
|
||||
std::string publicKeyData;
|
||||
Poco::StreamCopier::copyToString(*pPublicKeyStream, publicKeyData);
|
||||
BIO* bio = BIO_new_mem_buf(const_cast<char*>(publicKeyData.data()), static_cast<int>(publicKeyData.size()));
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for reading public key");
|
||||
RSA* publicKey = PEM_read_bio_RSAPublicKey(bio, &_pRSA, 0, 0);
|
||||
if (!publicKey)
|
||||
{
|
||||
int rc = BIO_reset(bio);
|
||||
// BIO_reset() normally returns 1 for success and 0 or -1 for failure.
|
||||
// File BIOs are an exception, they return 0 for success and -1 for failure.
|
||||
if (rc != 1) throw Poco::FileException("Failed to load public key");
|
||||
publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
|
||||
}
|
||||
BIO_free(bio);
|
||||
if (!publicKey)
|
||||
{
|
||||
freeRSA();
|
||||
throw Poco::FileException("Failed to load public key");
|
||||
}
|
||||
}
|
||||
|
||||
if (pPrivateKeyStream)
|
||||
{
|
||||
std::string privateKeyData;
|
||||
Poco::StreamCopier::copyToString(*pPrivateKeyStream, privateKeyData);
|
||||
BIO* bio = BIO_new_mem_buf(const_cast<char*>(privateKeyData.data()), static_cast<int>(privateKeyData.size()));
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for reading private key");
|
||||
RSA* privateKey = 0;
|
||||
if (privateKeyPassphrase.empty())
|
||||
privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, 0);
|
||||
else
|
||||
privateKey = PEM_read_bio_RSAPrivateKey(bio, &_pRSA, 0, const_cast<char*>(privateKeyPassphrase.c_str()));
|
||||
BIO_free(bio);
|
||||
if (!privateKey)
|
||||
{
|
||||
freeRSA();
|
||||
throw Poco::FileException("Failed to load private key");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::~RSAKeyImpl()
|
||||
{
|
||||
freeRSA();
|
||||
}
|
||||
|
||||
|
||||
void RSAKeyImpl::freeRSA()
|
||||
{
|
||||
if (_pRSA)
|
||||
RSA_free(_pRSA);
|
||||
_pRSA = 0;
|
||||
}
|
||||
|
||||
|
||||
int RSAKeyImpl::size() const
|
||||
{
|
||||
return RSA_size(_pRSA);
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKeyImpl::modulus() const
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
const BIGNUM* n = 0;
|
||||
const BIGNUM* e = 0;
|
||||
const BIGNUM* d = 0;
|
||||
RSA_get0_key(_pRSA, &n, &e, &d);
|
||||
return convertToByteVec(n);
|
||||
#else
|
||||
return convertToByteVec(_pRSA->n);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKeyImpl::encryptionExponent() const
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
const BIGNUM* n = 0;
|
||||
const BIGNUM* e = 0;
|
||||
const BIGNUM* d = 0;
|
||||
RSA_get0_key(_pRSA, &n, &e, &d);
|
||||
return convertToByteVec(e);
|
||||
#else
|
||||
return convertToByteVec(_pRSA->e);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKeyImpl::decryptionExponent() const
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
const BIGNUM* n = 0;
|
||||
const BIGNUM* e = 0;
|
||||
const BIGNUM* d = 0;
|
||||
RSA_get0_key(_pRSA, &n, &e, &d);
|
||||
return convertToByteVec(d);
|
||||
#else
|
||||
return convertToByteVec(_pRSA->d);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void RSAKeyImpl::save(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase)
|
||||
{
|
||||
if (!publicKeyFile.empty())
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_file());
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for writing public key file", publicKeyFile);
|
||||
try
|
||||
{
|
||||
if (BIO_write_filename(bio, const_cast<char*>(publicKeyFile.c_str())))
|
||||
{
|
||||
if (!PEM_write_bio_RSAPublicKey(bio, _pRSA))
|
||||
throw Poco::WriteFileException("Failed to write public key to file", publicKeyFile);
|
||||
}
|
||||
else throw Poco::CreateFileException("Cannot create public key file");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BIO_free(bio);
|
||||
throw;
|
||||
}
|
||||
BIO_free(bio);
|
||||
}
|
||||
|
||||
if (!privateKeyFile.empty())
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_file());
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for writing private key file", privateKeyFile);
|
||||
try
|
||||
{
|
||||
if (BIO_write_filename(bio, const_cast<char*>(privateKeyFile.c_str())))
|
||||
{
|
||||
int rc = 0;
|
||||
if (privateKeyPassphrase.empty())
|
||||
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0);
|
||||
else
|
||||
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(),
|
||||
reinterpret_cast<unsigned char*>(const_cast<char*>(privateKeyPassphrase.c_str())),
|
||||
static_cast<int>(privateKeyPassphrase.length()), 0, 0);
|
||||
if (!rc) throw Poco::FileException("Failed to write private key to file", privateKeyFile);
|
||||
}
|
||||
else throw Poco::CreateFileException("Cannot create private key file", privateKeyFile);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BIO_free(bio);
|
||||
throw;
|
||||
}
|
||||
BIO_free(bio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RSAKeyImpl::save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream, const std::string& privateKeyPassphrase)
|
||||
{
|
||||
if (pPublicKeyStream)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for writing public key");
|
||||
if (!PEM_write_bio_RSAPublicKey(bio, _pRSA))
|
||||
{
|
||||
BIO_free(bio);
|
||||
throw Poco::WriteFileException("Failed to write public key to stream");
|
||||
}
|
||||
char* pData;
|
||||
long size = BIO_get_mem_data(bio, &pData);
|
||||
pPublicKeyStream->write(pData, static_cast<std::streamsize>(size));
|
||||
BIO_free(bio);
|
||||
}
|
||||
|
||||
if (pPrivateKeyStream)
|
||||
{
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
if (!bio) throw Poco::IOException("Cannot create BIO for writing public key");
|
||||
int rc = 0;
|
||||
if (privateKeyPassphrase.empty())
|
||||
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0);
|
||||
else
|
||||
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(),
|
||||
reinterpret_cast<unsigned char*>(const_cast<char*>(privateKeyPassphrase.c_str())),
|
||||
static_cast<int>(privateKeyPassphrase.length()), 0, 0);
|
||||
if (!rc)
|
||||
{
|
||||
BIO_free(bio);
|
||||
throw Poco::FileException("Failed to write private key to stream");
|
||||
}
|
||||
char* pData;
|
||||
long size = BIO_get_mem_data(bio, &pData);
|
||||
pPrivateKeyStream->write(pData, static_cast<std::streamsize>(size));
|
||||
BIO_free(bio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RSAKeyImpl::ByteVec RSAKeyImpl::convertToByteVec(const BIGNUM* bn)
|
||||
{
|
||||
int numBytes = BN_num_bytes(bn);
|
||||
ByteVec byteVector(numBytes);
|
||||
|
||||
ByteVec::value_type* buffer = new ByteVec::value_type[numBytes];
|
||||
BN_bn2bin(bn, buffer);
|
||||
|
||||
for (int i = 0; i < numBytes; ++i)
|
||||
byteVector[i] = buffer[i];
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
return byteVector;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,295 +0,0 @@
|
||||
//
|
||||
// X509Certificate.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/src/X509Certificate.cpp#1 $
|
||||
//
|
||||
// Library: Crypto
|
||||
// Package: Certificate
|
||||
// Module: X509Certificate
|
||||
//
|
||||
// Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Crypto/X509Certificate.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include <sstream>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/x509v3.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/evp.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
X509Certificate::X509Certificate(std::istream& istr):
|
||||
_pCert(0)
|
||||
{
|
||||
load(istr);
|
||||
}
|
||||
|
||||
|
||||
X509Certificate::X509Certificate(const std::string& path):
|
||||
_pCert(0)
|
||||
{
|
||||
load(path);
|
||||
}
|
||||
|
||||
|
||||
X509Certificate::X509Certificate(X509* pCert):
|
||||
_pCert(pCert)
|
||||
{
|
||||
poco_check_ptr(_pCert);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
X509Certificate::X509Certificate(X509* pCert, bool shared):
|
||||
_pCert(pCert)
|
||||
{
|
||||
poco_check_ptr(_pCert);
|
||||
|
||||
if (shared)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
X509_up_ref(_pCert);
|
||||
#else
|
||||
_pCert->references++;
|
||||
#endif
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
X509Certificate::X509Certificate(const X509Certificate& cert):
|
||||
_issuerName(cert._issuerName),
|
||||
_subjectName(cert._subjectName),
|
||||
_pCert(cert._pCert)
|
||||
{
|
||||
_pCert = X509_dup(_pCert);
|
||||
}
|
||||
|
||||
|
||||
X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
|
||||
{
|
||||
X509Certificate tmp(cert);
|
||||
swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::swap(X509Certificate& cert)
|
||||
{
|
||||
using std::swap;
|
||||
swap(cert._issuerName, _issuerName);
|
||||
swap(cert._subjectName, _subjectName);
|
||||
swap(cert._pCert, _pCert);
|
||||
}
|
||||
|
||||
|
||||
X509Certificate::~X509Certificate()
|
||||
{
|
||||
X509_free(_pCert);
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::load(std::istream& istr)
|
||||
{
|
||||
poco_assert (!_pCert);
|
||||
|
||||
std::stringstream certStream;
|
||||
Poco::StreamCopier::copyStream(istr, certStream);
|
||||
std::string cert = certStream.str();
|
||||
|
||||
BIO *pBIO = BIO_new_mem_buf(const_cast<char*>(cert.data()), static_cast<int>(cert.size()));
|
||||
if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate");
|
||||
_pCert = PEM_read_bio_X509(pBIO, 0, 0, 0);
|
||||
BIO_free(pBIO);
|
||||
|
||||
if (!_pCert) throw Poco::IOException("Faild to load certificate from stream");
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::load(const std::string& path)
|
||||
{
|
||||
poco_assert (!_pCert);
|
||||
|
||||
BIO *pBIO = BIO_new(BIO_s_file());
|
||||
if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate file", path);
|
||||
if (!BIO_read_filename(pBIO, path.c_str()))
|
||||
{
|
||||
BIO_free(pBIO);
|
||||
throw Poco::OpenFileException("Cannot open certificate file for reading", path);
|
||||
}
|
||||
|
||||
_pCert = PEM_read_bio_X509(pBIO, 0, 0, 0);
|
||||
BIO_free(pBIO);
|
||||
|
||||
if (!_pCert) throw Poco::ReadFileException("Faild to load certificate from", path);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::save(std::ostream& stream) const
|
||||
{
|
||||
BIO *pBIO = BIO_new(BIO_s_mem());
|
||||
if (!pBIO) throw Poco::IOException("Cannot create BIO for writing certificate");
|
||||
try
|
||||
{
|
||||
if (!PEM_write_bio_X509(pBIO, _pCert))
|
||||
throw Poco::IOException("Failed to write certificate to stream");
|
||||
|
||||
char *pData;
|
||||
long size;
|
||||
size = BIO_get_mem_data(pBIO, &pData);
|
||||
stream.write(pData, size);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BIO_free(pBIO);
|
||||
throw;
|
||||
}
|
||||
BIO_free(pBIO);
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::save(const std::string& path) const
|
||||
{
|
||||
BIO *pBIO = BIO_new(BIO_s_file());
|
||||
if (!pBIO) throw Poco::IOException("Cannot create BIO for reading certificate file", path);
|
||||
if (!BIO_write_filename(pBIO, const_cast<char*>(path.c_str())))
|
||||
{
|
||||
BIO_free(pBIO);
|
||||
throw Poco::CreateFileException("Cannot create certificate file", path);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!PEM_write_bio_X509(pBIO, _pCert))
|
||||
throw Poco::WriteFileException("Failed to write certificate to file", path);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
BIO_free(pBIO);
|
||||
throw;
|
||||
}
|
||||
BIO_free(pBIO);
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::init()
|
||||
{
|
||||
char buffer[NAME_BUFFER_SIZE];
|
||||
X509_NAME_oneline(X509_get_issuer_name(_pCert), buffer, sizeof(buffer));
|
||||
_issuerName = buffer;
|
||||
X509_NAME_oneline(X509_get_subject_name(_pCert), buffer, sizeof(buffer));
|
||||
_subjectName = buffer;
|
||||
}
|
||||
|
||||
|
||||
std::string X509Certificate::commonName() const
|
||||
{
|
||||
return subjectName(NID_COMMON_NAME);
|
||||
}
|
||||
|
||||
|
||||
std::string X509Certificate::issuerName(NID nid) const
|
||||
{
|
||||
if (X509_NAME* issuer = X509_get_issuer_name(_pCert))
|
||||
{
|
||||
char buffer[NAME_BUFFER_SIZE];
|
||||
if (X509_NAME_get_text_by_NID(issuer, nid, buffer, sizeof(buffer)) >= 0)
|
||||
return std::string(buffer);
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
std::string X509Certificate::subjectName(NID nid) const
|
||||
{
|
||||
if (X509_NAME* subj = X509_get_subject_name(_pCert))
|
||||
{
|
||||
char buffer[NAME_BUFFER_SIZE];
|
||||
if (X509_NAME_get_text_by_NID(subj, nid, buffer, sizeof(buffer)) >= 0)
|
||||
return std::string(buffer);
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
|
||||
void X509Certificate::extractNames(std::string& cmnName, std::set<std::string>& domainNames) const
|
||||
{
|
||||
domainNames.clear();
|
||||
if (STACK_OF(GENERAL_NAME)* names = static_cast<STACK_OF(GENERAL_NAME)*>(X509_get_ext_d2i(_pCert, NID_subject_alt_name, 0, 0)))
|
||||
{
|
||||
for (int i = 0; i < sk_GENERAL_NAME_num(names); ++i)
|
||||
{
|
||||
const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i);
|
||||
if (name->type == GEN_DNS)
|
||||
{
|
||||
const char* data = reinterpret_cast<char*>(ASN1_STRING_data(name->d.ia5));
|
||||
std::size_t len = ASN1_STRING_length(name->d.ia5);
|
||||
domainNames.insert(std::string(data, len));
|
||||
}
|
||||
}
|
||||
GENERAL_NAMES_free(names);
|
||||
}
|
||||
|
||||
cmnName = commonName();
|
||||
if (!cmnName.empty() && domainNames.empty())
|
||||
{
|
||||
domainNames.insert(cmnName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Poco::DateTime X509Certificate::validFrom() const
|
||||
{
|
||||
ASN1_TIME* certTime = X509_get_notBefore(_pCert);
|
||||
std::string dateTime(reinterpret_cast<char*>(certTime->data));
|
||||
int tzd;
|
||||
return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
|
||||
}
|
||||
|
||||
|
||||
Poco::DateTime X509Certificate::expiresOn() const
|
||||
{
|
||||
ASN1_TIME* certTime = X509_get_notAfter(_pCert);
|
||||
std::string dateTime(reinterpret_cast<char*>(certTime->data));
|
||||
int tzd;
|
||||
return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
|
||||
}
|
||||
|
||||
|
||||
bool X509Certificate::issuedBy(const X509Certificate& issuerCertificate) const
|
||||
{
|
||||
X509* pCert = const_cast<X509*>(_pCert);
|
||||
X509* pIssuerCert = const_cast<X509*>(issuerCertificate.certificate());
|
||||
EVP_PKEY* pIssuerPublicKey = X509_get_pubkey(pIssuerCert);
|
||||
if (!pIssuerPublicKey) throw Poco::InvalidArgumentException("Issuer certificate has no public key");
|
||||
int rc = X509_verify(pCert, pIssuerPublicKey);
|
||||
EVP_PKEY_free(pIssuerPublicKey);
|
||||
return rc == 1;
|
||||
}
|
||||
|
||||
|
||||
bool X509Certificate::equals(const X509Certificate& otherCertificate) const
|
||||
{
|
||||
X509* pCert = const_cast<X509*>(_pCert);
|
||||
X509* pOtherCert = const_cast<X509*>(otherCertificate.certificate());
|
||||
return X509_cmp(pCert, pOtherCert) == 0;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Crypto
|
@ -1,24 +0,0 @@
|
||||
set(TESTUNIT "${LIBNAME}-testrunner")
|
||||
|
||||
# Sources
|
||||
file(GLOB SRCS_G "src/*.cpp")
|
||||
POCO_SOURCES_AUTO( TEST_SRCS ${SRCS_G})
|
||||
|
||||
# Headers
|
||||
file(GLOB_RECURSE HDRS_G "src/*.h" )
|
||||
POCO_HEADERS_AUTO( TEST_SRCS ${HDRS_G})
|
||||
|
||||
POCO_SOURCES_AUTO_PLAT( TEST_SRCS OFF
|
||||
src/WinDriver.cpp
|
||||
)
|
||||
|
||||
POCO_SOURCES_AUTO_PLAT( TEST_SRCS WINCE
|
||||
src/WinCEDriver.cpp
|
||||
)
|
||||
|
||||
add_executable( ${TESTUNIT} ${TEST_SRCS} )
|
||||
add_test(NAME ${LIBNAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${TESTUNIT} -all)
|
||||
target_link_libraries( ${TESTUNIT} PocoCrypto PocoNetSSL PocoXML PocoUtil PocoFoundation CppUnit )
|
||||
if(UNIX)
|
||||
target_link_libraries( ${TESTUNIT} pthread)
|
||||
endif(UNIX)
|
@ -1,281 +0,0 @@
|
||||
//
|
||||
// CryptoTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/CryptoTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CryptoTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Crypto/CipherFactory.h"
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Crypto/CipherKey.h"
|
||||
#include "Poco/Crypto/X509Certificate.h"
|
||||
#include "Poco/Crypto/CryptoStream.h"
|
||||
#include "Poco/StreamCopier.h"
|
||||
#include "Poco/Base64Encoder.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using namespace Poco::Crypto;
|
||||
|
||||
|
||||
static const std::string APPINF_PEM(
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
"MIIESzCCAzOgAwIBAgIBATALBgkqhkiG9w0BAQUwgdMxEzARBgNVBAMMCmFwcGlu\n"
|
||||
"Zi5jb20xNjA0BgNVBAoMLUFwcGxpZWQgSW5mb3JtYXRpY3MgU29mdHdhcmUgRW5n\n"
|
||||
"aW5lZXJpbmcgR21iSDEUMBIGA1UECwwLRGV2ZWxvcG1lbnQxEjAQBgNVBAgMCUNh\n"
|
||||
"cmludGhpYTELMAkGA1UEBhMCQVQxHjAcBgNVBAcMFVN0LiBKYWtvYiBpbSBSb3Nl\n"
|
||||
"bnRhbDEtMCsGCSqGSIb3DQEJARYeZ3VlbnRlci5vYmlsdHNjaG5pZ0BhcHBpbmYu\n"
|
||||
"Y29tMB4XDTA5MDUwNzE0NTY1NloXDTI5MDUwMjE0NTY1NlowgdMxEzARBgNVBAMM\n"
|
||||
"CmFwcGluZi5jb20xNjA0BgNVBAoMLUFwcGxpZWQgSW5mb3JtYXRpY3MgU29mdHdh\n"
|
||||
"cmUgRW5naW5lZXJpbmcgR21iSDEUMBIGA1UECwwLRGV2ZWxvcG1lbnQxEjAQBgNV\n"
|
||||
"BAgMCUNhcmludGhpYTELMAkGA1UEBhMCQVQxHjAcBgNVBAcMFVN0LiBKYWtvYiBp\n"
|
||||
"bSBSb3NlbnRhbDEtMCsGCSqGSIb3DQEJARYeZ3VlbnRlci5vYmlsdHNjaG5pZ0Bh\n"
|
||||
"cHBpbmYuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA89GolWCR\n"
|
||||
"KtLQclJ2M2QtpFqzNC54hUQdR6n8+DAeruH9WFwLSdWW2fEi+jrtd/WEWCdt4PxX\n"
|
||||
"F2/eBYeURus7Hg2ZtJGDd3je0+Ygsv7+we4cMN/knaBY7rATqhmnZWk+yBpkf5F2\n"
|
||||
"IHp9gBxUaJWmt/bq3XrvTtzrDXpCd4zg4zPXZ8IC8ket5o3K2vnkAOsIsgN+Ffqd\n"
|
||||
"4GjF4dsblG6u6E3VarGRLwGtgB8BAZOA/33mV4FHSMkc4OXpAChaK3tM8YhrLw+m\n"
|
||||
"XtsfqDiv1825S6OWFCKGj/iX8X2QAkrdB63vXCSpb3de/ByIUfp31PpMlMh6dKo1\n"
|
||||
"vf7yj0nb2w0utQIDAQABoyowKDAOBgNVHQ8BAf8EBAMCB4AwFgYDVR0lAQH/BAww\n"
|
||||
"CgYIKwYBBQUHAwMwDQYJKoZIhvcNAQEFBQADggEBAM0cpfb4BgiU/rkYe121P581\n"
|
||||
"ftg5Ck1PYYda1Fy/FgzbgJh2AwVo/6sn6GF79/QkEcWEgtCMNNO3LMTTddUUApuP\n"
|
||||
"jnEimyfmUhIThyud/vryzTMNa/eZMwaAqUQWqLf+AwgqjUsBSMenbSHavzJOpsvR\n"
|
||||
"LI0PQ1VvqB+3UGz0JUnBJiKvHs83Fdm4ewPAf3M5fGcIa+Fl2nU5Plzwzskj84f6\n"
|
||||
"73ZlEEi3aW9JieNy7RWsMM+1E8Sj2CGRZC4BM9V1Fgnsh4+VHX8Eu7eHucvfeIYx\n"
|
||||
"3mmLMoK4sCayL/FGhrUDw5AkWb8tKNpRXY+W60Et281yxQSeWLPIbatVzIWI0/M=\n"
|
||||
"-----END CERTIFICATE-----\n"
|
||||
);
|
||||
|
||||
|
||||
CryptoTest::CryptoTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CryptoTest::~CryptoTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testEncryptDecrypt()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_NONE);
|
||||
std::string result = pCipher->decryptString(out, Cipher::ENC_NONE);
|
||||
assert (in == result);
|
||||
}
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
|
||||
std::string result = pCipher->decryptString(out, Cipher::ENC_BASE64);
|
||||
assert (in == result);
|
||||
}
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_BINHEX);
|
||||
std::string result = pCipher->decryptString(out, Cipher::ENC_BINHEX);
|
||||
assert (in == result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testEncryptDecryptWithSalt()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
|
||||
Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "simplepwd", "Too much salt"));
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_NONE);
|
||||
std::string result = pCipher2->decryptString(out, Cipher::ENC_NONE);
|
||||
assert (in == result);
|
||||
}
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
|
||||
std::string result = pCipher2->decryptString(out, Cipher::ENC_BASE64);
|
||||
assert (in == result);
|
||||
}
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_BINHEX);
|
||||
std::string result = pCipher2->decryptString(out, Cipher::ENC_BINHEX);
|
||||
assert (in == result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testEncryptDecryptDESECB()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("des-ecb", "password"));
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_NONE);
|
||||
std::string result = pCipher->decryptString(out, Cipher::ENC_NONE);
|
||||
assert (in == result);
|
||||
}
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_BASE64);
|
||||
std::string result = pCipher->decryptString(out, Cipher::ENC_BASE64);
|
||||
assert (in == result);
|
||||
}
|
||||
|
||||
for (std::size_t n = 1; n < MAX_DATA_SIZE; n++)
|
||||
{
|
||||
std::string in(n, 'x');
|
||||
std::string out = pCipher->encryptString(in, Cipher::ENC_BINHEX);
|
||||
std::string result = pCipher->decryptString(out, Cipher::ENC_BINHEX);
|
||||
assert (in == result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testPassword()
|
||||
{
|
||||
CipherKey key("aes256", "password", "salt");
|
||||
|
||||
std::ostringstream keyStream;
|
||||
Poco::Base64Encoder base64KeyEnc(keyStream);
|
||||
base64KeyEnc.write(reinterpret_cast<const char*>(&key.getKey()[0]), key.keySize());
|
||||
base64KeyEnc.close();
|
||||
std::string base64Key = keyStream.str();
|
||||
assert (base64Key == "hIzxBt58GDd7/6mRp88bewKk42lM4QwaF78ek0FkVoA=");
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testEncryptInterop()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "password", "salt"));
|
||||
|
||||
const std::string plainText = "This is a secret message.";
|
||||
const std::string expectedCipherText = "9HITTPaU3A/LaZzldbdnRZ109DKlshouKren/n8BsHc=";
|
||||
std::string cipherText = pCipher->encryptString(plainText, Cipher::ENC_BASE64);
|
||||
assert (cipherText == expectedCipherText);
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testDecryptInterop()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256", "password", "salt"));
|
||||
|
||||
const std::string expectedPlainText = "This is a secret message.";
|
||||
const std::string cipherText = "9HITTPaU3A/LaZzldbdnRZ109DKlshouKren/n8BsHc=";
|
||||
std::string plainText = pCipher->decryptString(cipherText, Cipher::ENC_BASE64);
|
||||
assert (plainText == expectedPlainText);
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testStreams()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(CipherKey("aes256"));
|
||||
|
||||
static const std::string SECRET_MESSAGE = "This is a secret message. Don't tell anyone.";
|
||||
|
||||
std::stringstream sstr;
|
||||
EncryptingOutputStream encryptor(sstr, *pCipher);
|
||||
encryptor << SECRET_MESSAGE;
|
||||
encryptor.close();
|
||||
|
||||
DecryptingInputStream decryptor(sstr, *pCipher);
|
||||
std::string result;
|
||||
Poco::StreamCopier::copyToString(decryptor, result);
|
||||
|
||||
assert (result == SECRET_MESSAGE);
|
||||
assert (decryptor.eof());
|
||||
assert (!decryptor.bad());
|
||||
|
||||
|
||||
std::istringstream emptyStream;
|
||||
DecryptingInputStream badDecryptor(emptyStream, *pCipher);
|
||||
Poco::StreamCopier::copyToString(badDecryptor, result);
|
||||
|
||||
assert (badDecryptor.fail());
|
||||
assert (badDecryptor.bad());
|
||||
assert (!badDecryptor.eof());
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::testCertificate()
|
||||
{
|
||||
std::istringstream certStream(APPINF_PEM);
|
||||
X509Certificate cert(certStream);
|
||||
|
||||
std::string subjectName(cert.subjectName());
|
||||
std::string issuerName(cert.issuerName());
|
||||
std::string commonName(cert.commonName());
|
||||
std::string country(cert.subjectName(X509Certificate::NID_COUNTRY));
|
||||
std::string localityName(cert.subjectName(X509Certificate::NID_LOCALITY_NAME));
|
||||
std::string stateOrProvince(cert.subjectName(X509Certificate::NID_STATE_OR_PROVINCE));
|
||||
std::string organizationName(cert.subjectName(X509Certificate::NID_ORGANIZATION_NAME));
|
||||
std::string organizationUnitName(cert.subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME));
|
||||
|
||||
assert (subjectName == "/CN=appinf.com/O=Applied Informatics Software Engineering GmbH/OU=Development/ST=Carinthia/C=AT/L=St. Jakob im Rosental/emailAddress=guenter.obiltschnig@appinf.com");
|
||||
assert (issuerName == subjectName);
|
||||
assert (commonName == "appinf.com");
|
||||
assert (country == "AT");
|
||||
assert (localityName == "St. Jakob im Rosental");
|
||||
assert (stateOrProvince == "Carinthia");
|
||||
assert (organizationName == "Applied Informatics Software Engineering GmbH");
|
||||
assert (organizationUnitName == "Development");
|
||||
|
||||
// fails with recent OpenSSL versions:
|
||||
// assert (cert.issuedBy(cert));
|
||||
|
||||
std::istringstream otherCertStream(APPINF_PEM);
|
||||
X509Certificate otherCert(otherCertStream);
|
||||
|
||||
assert (cert.equals(otherCert));
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CryptoTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* CryptoTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptoTest");
|
||||
|
||||
CppUnit_addTest(pSuite, CryptoTest, testEncryptDecrypt);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testEncryptDecryptWithSalt);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testEncryptDecryptDESECB);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testPassword);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testEncryptInterop);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testDecryptInterop);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testStreams);
|
||||
CppUnit_addTest(pSuite, CryptoTest, testCertificate);
|
||||
|
||||
return pSuite;
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
//
|
||||
// CryptoTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/CryptoTest.h#2 $
|
||||
//
|
||||
// Definition of the CryptoTest class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef CryptoTest_INCLUDED
|
||||
#define CryptoTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class CryptoTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
MAX_DATA_SIZE = 10000
|
||||
};
|
||||
|
||||
CryptoTest(const std::string& name);
|
||||
~CryptoTest();
|
||||
|
||||
void testEncryptDecrypt();
|
||||
void testEncryptDecryptWithSalt();
|
||||
void testEncryptDecryptDESECB();
|
||||
void testStreams();
|
||||
void testPassword();
|
||||
void testEncryptInterop();
|
||||
void testDecryptInterop();
|
||||
void testCertificate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // CryptoTest_INCLUDED
|
@ -1,28 +0,0 @@
|
||||
//
|
||||
// CryptoTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/CryptoTestSuite.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CryptoTestSuite.h"
|
||||
#include "CryptoTest.h"
|
||||
#include "RSATest.h"
|
||||
#include "DigestEngineTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* CryptoTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("CryptoTestSuite");
|
||||
|
||||
pSuite->addTest(CryptoTest::suite());
|
||||
pSuite->addTest(RSATest::suite());
|
||||
pSuite->addTest(DigestEngineTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//
|
||||
// CryptoTestSuite.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/CryptoTestSuite.h#1 $
|
||||
//
|
||||
// Definition of the CryptoTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef CryptoTestSuite_INCLUDED
|
||||
#define CryptoTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class CryptoTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // CryptoTestSuite_INCLUDED
|
@ -1,96 +0,0 @@
|
||||
//
|
||||
// DigestEngineTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/DigestEngineTest.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "DigestEngineTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Crypto/DigestEngine.h"
|
||||
|
||||
|
||||
using Poco::Crypto::DigestEngine;
|
||||
|
||||
|
||||
DigestEngineTest::DigestEngineTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DigestEngineTest::~DigestEngineTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DigestEngineTest::testMD5()
|
||||
{
|
||||
DigestEngine engine("MD5");
|
||||
|
||||
// test vectors from RFC 1321
|
||||
|
||||
engine.update("");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "d41d8cd98f00b204e9800998ecf8427e");
|
||||
|
||||
engine.update("a");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "0cc175b9c0f1b6a831c399e269772661");
|
||||
|
||||
engine.update("abc");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "900150983cd24fb0d6963f7d28e17f72");
|
||||
|
||||
engine.update("message digest");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "f96b697d7cb7938d525a2f31aaf161d0");
|
||||
|
||||
engine.update("abcdefghijklmnopqrstuvwxyz");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "c3fcd3d76192e4007dfb496cca67e13b");
|
||||
|
||||
engine.update("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
engine.update("abcdefghijklmnopqrstuvwxyz0123456789");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "d174ab98d277d9f5a5611c2c9f419d9f");
|
||||
|
||||
engine.update("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "57edf4a22be3c955ac49da2e2107b67a");
|
||||
}
|
||||
|
||||
void DigestEngineTest::testSHA1()
|
||||
{
|
||||
DigestEngine engine("SHA1");
|
||||
|
||||
// test vectors from FIPS 180-1
|
||||
|
||||
engine.update("abc");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "a9993e364706816aba3e25717850c26c9cd0d89d");
|
||||
|
||||
engine.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
|
||||
|
||||
for (int i = 0; i < 1000000; ++i)
|
||||
engine.update('a');
|
||||
assert (DigestEngine::digestToHex(engine.digest()) == "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
|
||||
}
|
||||
|
||||
void DigestEngineTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DigestEngineTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* DigestEngineTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("DigestEngineTest");
|
||||
|
||||
CppUnit_addTest(pSuite, DigestEngineTest, testMD5);
|
||||
CppUnit_addTest(pSuite, DigestEngineTest, testSHA1);
|
||||
|
||||
return pSuite;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
//
|
||||
// DigestEngineTest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/DigestEngineTest.h#1 $
|
||||
//
|
||||
// Definition of the DigestEngineTest class.
|
||||
//
|
||||
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef DigestEngineTest_INCLUDED
|
||||
#define DigestEngineTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class DigestEngineTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DigestEngineTest(const std::string& name);
|
||||
~DigestEngineTest();
|
||||
|
||||
void testMD5();
|
||||
void testSHA1();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // DigestEngineTest_INCLUDED
|
@ -1,45 +0,0 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/Driver.cpp#1 $
|
||||
//
|
||||
// Console-based test driver for Poco Crypto.
|
||||
//
|
||||
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "CryptoTestSuite.h"
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
|
||||
|
||||
class CryptoInitializer
|
||||
{
|
||||
public:
|
||||
CryptoInitializer()
|
||||
{
|
||||
Poco::Crypto::initializeCrypto();
|
||||
}
|
||||
|
||||
~CryptoInitializer()
|
||||
{
|
||||
Poco::Crypto::uninitializeCrypto();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
CryptoInitializer ci;
|
||||
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < ac; ++i)
|
||||
args.push_back(std::string(av[i]));
|
||||
CppUnit::TestRunner runner;
|
||||
runner.addTest("CryptoTestSuite", CryptoTestSuite::suite());
|
||||
return runner.run(args) ? 0 : 1;
|
||||
}
|
@ -1,279 +0,0 @@
|
||||
//
|
||||
// RSATest.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/RSATest.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "RSATest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Crypto/RSADigestEngine.h"
|
||||
#include "Poco/Crypto/CipherFactory.h"
|
||||
#include "Poco/Crypto/Cipher.h"
|
||||
#include "Poco/Crypto/X509Certificate.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using namespace Poco::Crypto;
|
||||
|
||||
|
||||
static const std::string anyPem(
|
||||
"-----BEGIN CERTIFICATE-----\r\n"
|
||||
"MIICaDCCAdECCQCzfxSsk7yaLjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB\r\n"
|
||||
"VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV\r\n"
|
||||
"BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA\r\n"
|
||||
"aW5mLmNvbTAeFw0wNjAzMDExMzA3MzFaFw0wNjAzMzExMzA3MzFaMH4xCzAJBgNV\r\n"
|
||||
"BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExETAPBgNVBAcTCFN0IEpha29iMRww\r\n"
|
||||
"GgYDVQQKExNBcHBsaWVkIEluZm9ybWF0aWNzMQowCAYDVQQDFAEqMR4wHAYJKoZI\r\n"
|
||||
"hvcNAQkBFg9pbmZvQGFwcGluZi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ\r\n"
|
||||
"AoGBAJHGyXDHyCYoWz+65ltNwwZbhwOGnxr9P1WMATuFJh0bPBZxKbZRdbTm9KhZ\r\n"
|
||||
"OlvsEIsfgiYdsxURYIqXfEgISYLZcZY0pQwGEOmB+0NeC/+ENSfOlNSthx6zSVlc\r\n"
|
||||
"zhJ7+dJOGwepHAiLr1fRuc5jogYLraE+lKTnqAAFfzwvti77AgMBAAEwDQYJKoZI\r\n"
|
||||
"hvcNAQEFBQADgYEAY/ZoeY1ukkEJX7259NeoVM0oahlulWV0rlCqyaeosOiDORPT\r\n"
|
||||
"m6X1w/5MTCf9VyaD1zukoSZ4QqNVjHFXcXidbB7Tgt3yRuZ5PC5LIFCDPv9mgPne\r\n"
|
||||
"mUA70yfctNfza2z3ZiQ6NDkW3mZX+1tmxYIrJQIrkVeYeqf1Gh2nyZrUMcE=\r\n"
|
||||
"-----END CERTIFICATE-----\r\n"
|
||||
"-----BEGIN RSA PRIVATE KEY-----\r\n"
|
||||
"Proc-Type: 4,ENCRYPTED\r\n"
|
||||
"DEK-Info: DES-EDE3-CBC,E7AE93C9E49184EA\r\n"
|
||||
"\r\n"
|
||||
"A2IqzNcWs+I5vzV+i+woDk56+yr58eU0Onw8eEvXkLjnSc58JU4327IF7yUbKWdW\r\n"
|
||||
"Q7BYGGOkVFiZ7ANOwviDg5SUhxRDWCcW8dS6/p1vfdQ1C3qj2OwJjkpg0aDBIzJn\r\n"
|
||||
"FzgguT3MF3ama77vxv0S3kOfmCj62MLqPGpj5pQ0/1hefRFbL8oAX8bXUN7/rmGM\r\n"
|
||||
"Zc0QyzFZv2iQ04dY/6TNclwKPB4H0On4K+8BMs3PRkWA0clCaQaFO2+iwnk3XZfe\r\n"
|
||||
"+MsKUEbLCpAQeYspYv1cw38dCdWq1KTP5aJk+oXgwjfX5cAaPTz74NTqTIsCcaTD\r\n"
|
||||
"3vy7ukJYFlDR9Kyo7z8rMazYrKJslhnuRH0BhK9st9McwL957j5tZmrKyraCcmCx\r\n"
|
||||
"dMAGcsis1va3ayYZpIpFqA4EhYrTM+6N8ZRfUap20+b5IQwHfTQDejUhL6rBwy7j\r\n"
|
||||
"Ti5yD83/itoOMyXq2sV/XWfVD5zk/P5iv22O1EAQMhhnPB9K/I/JhuSGQJfn3cNh\r\n"
|
||||
"ykOUYT0+vDeSeEVa+FVEP1W35G0alTbKbNs5Tb8KxJ3iDJUxokM//SvPXZy9hOVX\r\n"
|
||||
"Y05imB04J15DaGbAHlNzunhuJi7121WV/JRXZRW9diE6hwpD8rwqi3FMuRUmy7U9\r\n"
|
||||
"aFA5poKRAYlo9YtZ3YpFyjGKB6MfCQcB2opuSnQ/gbugV41m67uQ4CDwWLaNRkTb\r\n"
|
||||
"GlsMBNcHnidg15Bsat5HaB7l250ukrI13Uw1MYdDUzaS3gPfw9aC4F2w0p3U+DPH\r\n"
|
||||
"80/zePxtroR7T4/+rI136Rl+aMXDMOEGCX1TVP8rjuZzuRyUSUKC8Q==\r\n"
|
||||
"-----END RSA PRIVATE KEY-----\r\n"
|
||||
"-----BEGIN CERTIFICATE-----\r\n"
|
||||
"MIICXTCCAcYCCQC1Vk/N8qR4AjANBgkqhkiG9w0BAQUFADBzMQswCQYDVQQGEwJB\r\n"
|
||||
"VDESMBAGA1UECBMJQ2FyaW50aGlhMRIwEAYDVQQHEwlTdC4gSmFrb2IxDzANBgNV\r\n"
|
||||
"BAoTBkFwcEluZjEPMA0GA1UEAxMGQXBwSW5mMRowGAYJKoZIhvcNAQkBFgthcHBA\r\n"
|
||||
"aW5mLmNvbTAeFw0wNjAyMjcxMzI3MThaFw0wNjAzMjkxMzI3MThaMHMxCzAJBgNV\r\n"
|
||||
"BAYTAkFUMRIwEAYDVQQIEwlDYXJpbnRoaWExEjAQBgNVBAcTCVN0LiBKYWtvYjEP\r\n"
|
||||
"MA0GA1UEChMGQXBwSW5mMQ8wDQYDVQQDEwZBcHBJbmYxGjAYBgkqhkiG9w0BCQEW\r\n"
|
||||
"C2FwcEBpbmYuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCsFXiPuicN\r\n"
|
||||
"Im4oJwF8NuaFN+lgYwcZ6dAO3ILIR3kLA2PxF8HSQLfF8J8a4odZhLhctIMAKTxm\r\n"
|
||||
"k0w8TW5qhL8QLdGzY9vzvkgdKOkan2t3sMeXJAfrM1AphTsmgntAQazGZjOj5p4W\r\n"
|
||||
"jDnxQ+VXAylqwjHh49eSBxM3wgoscF4iLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GB\r\n"
|
||||
"AIpfLdXiKchPvFMhQS8xTtXvrw5dVL3yImUMYs4GQi8RrjGmfGB3yMAR7B/b8v4a\r\n"
|
||||
"+ztfusgWAWiUKuSGTk4S8YB0fsFlmOv0WDr+PyZ4Lui/a8opbyzGE7rqpnF/s0GO\r\n"
|
||||
"M7uLCNNwIN7WhmxcWV0KZU1wTppoSWPJda1yTbBzF9XP\r\n"
|
||||
"-----END CERTIFICATE-----\r\n"
|
||||
);
|
||||
|
||||
|
||||
RSATest::RSATest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RSATest::~RSATest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testNewKeys()
|
||||
{
|
||||
RSAKey key(RSAKey::KL_1024, RSAKey::EXP_SMALL);
|
||||
std::ostringstream strPub;
|
||||
std::ostringstream strPriv;
|
||||
key.save(&strPub, &strPriv, "testpwd");
|
||||
std::string pubKey = strPub.str();
|
||||
std::string privKey = strPriv.str();
|
||||
|
||||
// now do the round trip
|
||||
std::istringstream iPub(pubKey);
|
||||
std::istringstream iPriv(privKey);
|
||||
RSAKey key2(&iPub, &iPriv, "testpwd");
|
||||
|
||||
std::istringstream iPriv2(privKey);
|
||||
RSAKey key3(0, &iPriv2, "testpwd");
|
||||
std::ostringstream strPub3;
|
||||
key3.save(&strPub3);
|
||||
std::string pubFromPrivate = strPub3.str();
|
||||
assert (pubFromPrivate == pubKey);
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testNewKeysNoPassphrase()
|
||||
{
|
||||
RSAKey key(RSAKey::KL_1024, RSAKey::EXP_SMALL);
|
||||
std::ostringstream strPub;
|
||||
std::ostringstream strPriv;
|
||||
key.save(&strPub, &strPriv);
|
||||
std::string pubKey = strPub.str();
|
||||
std::string privKey = strPriv.str();
|
||||
|
||||
// now do the round trip
|
||||
std::istringstream iPub(pubKey);
|
||||
std::istringstream iPriv(privKey);
|
||||
RSAKey key2(&iPub, &iPriv);
|
||||
|
||||
std::istringstream iPriv2(privKey);
|
||||
RSAKey key3(0, &iPriv2);
|
||||
std::ostringstream strPub3;
|
||||
key3.save(&strPub3);
|
||||
std::string pubFromPrivate = strPub3.str();
|
||||
assert (pubFromPrivate == pubKey);
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testSign()
|
||||
{
|
||||
std::string msg("Test this sign message");
|
||||
RSAKey key(RSAKey::KL_2048, RSAKey::EXP_LARGE);
|
||||
RSADigestEngine eng(key);
|
||||
eng.update(msg.c_str(), static_cast<unsigned>(msg.length()));
|
||||
const Poco::DigestEngine::Digest& sig = eng.signature();
|
||||
std::string hexDig = Poco::DigestEngine::digestToHex(sig);
|
||||
|
||||
// verify
|
||||
std::ostringstream strPub;
|
||||
key.save(&strPub);
|
||||
std::string pubKey = strPub.str();
|
||||
std::istringstream iPub(pubKey);
|
||||
RSAKey keyPub(&iPub);
|
||||
RSADigestEngine eng2(keyPub);
|
||||
eng2.update(msg.c_str(), static_cast<unsigned>(msg.length()));
|
||||
assert (eng2.verify(sig));
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testSignSha256()
|
||||
{
|
||||
std::string msg("Test this sign message");
|
||||
RSAKey key(RSAKey::KL_2048, RSAKey::EXP_LARGE);
|
||||
RSADigestEngine eng(key, "SHA256");
|
||||
eng.update(msg.c_str(), static_cast<unsigned>(msg.length()));
|
||||
const Poco::DigestEngine::Digest& sig = eng.signature();
|
||||
std::string hexDig = Poco::DigestEngine::digestToHex(sig);
|
||||
|
||||
// verify
|
||||
std::ostringstream strPub;
|
||||
key.save(&strPub);
|
||||
std::string pubKey = strPub.str();
|
||||
std::istringstream iPub(pubKey);
|
||||
RSAKey keyPub(&iPub);
|
||||
RSADigestEngine eng2(keyPub, "SHA256");
|
||||
eng2.update(msg.c_str(), static_cast<unsigned>(msg.length()));
|
||||
assert (eng2.verify(sig));
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testSignManipulated()
|
||||
{
|
||||
std::string msg("Test this sign message");
|
||||
std::string msgManip("Test that sign message");
|
||||
RSAKey key(RSAKey::KL_2048, RSAKey::EXP_LARGE);
|
||||
RSADigestEngine eng(key);
|
||||
eng.update(msg.c_str(), static_cast<unsigned>(msg.length()));
|
||||
const Poco::DigestEngine::Digest& sig = eng.signature();
|
||||
std::string hexDig = Poco::DigestEngine::digestToHex(sig);
|
||||
|
||||
// verify
|
||||
std::ostringstream strPub;
|
||||
key.save(&strPub);
|
||||
std::string pubKey = strPub.str();
|
||||
std::istringstream iPub(pubKey);
|
||||
RSAKey keyPub(&iPub);
|
||||
RSADigestEngine eng2(keyPub);
|
||||
eng2.update(msgManip.c_str(), static_cast<unsigned>(msgManip.length()));
|
||||
assert (!eng2.verify(sig));
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testRSACipher()
|
||||
{
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
|
||||
for (std::size_t n = 1; n <= 1200; n++)
|
||||
{
|
||||
std::string val(n, 'x');
|
||||
std::string enc = pCipher->encryptString(val);
|
||||
std::string dec = pCipher->decryptString(enc);
|
||||
assert (dec == val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testRSACipherLarge()
|
||||
{
|
||||
std::vector<std::size_t> sizes;
|
||||
sizes.push_back (2047);
|
||||
sizes.push_back (2048);
|
||||
sizes.push_back (2049);
|
||||
sizes.push_back (4095);
|
||||
sizes.push_back (4096);
|
||||
sizes.push_back (4097);
|
||||
sizes.push_back (8191);
|
||||
sizes.push_back (8192);
|
||||
sizes.push_back (8193);
|
||||
sizes.push_back (16383);
|
||||
sizes.push_back (16384);
|
||||
sizes.push_back (16385);
|
||||
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(RSAKey(RSAKey::KL_1024, RSAKey::EXP_SMALL));
|
||||
for (std::vector<std::size_t>::const_iterator it = sizes.begin(); it != sizes.end(); ++it)
|
||||
{
|
||||
std::string val(*it, 'x');
|
||||
std::string enc = pCipher->encryptString(val);
|
||||
std::string dec = pCipher->decryptString(enc);
|
||||
assert (dec == val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RSATest::testCertificate()
|
||||
{
|
||||
std::istringstream str(anyPem);
|
||||
X509Certificate cert(str);
|
||||
RSAKey publicKey(cert);
|
||||
std::istringstream str2(anyPem);
|
||||
RSAKey privateKey(0, &str2, "test");
|
||||
Cipher::Ptr pCipher = CipherFactory::defaultFactory().createCipher(publicKey);
|
||||
Cipher::Ptr pCipher2 = CipherFactory::defaultFactory().createCipher(privateKey);
|
||||
std::string val("lets do some encryption");
|
||||
|
||||
std::string enc = pCipher->encryptString(val);
|
||||
std::string dec = pCipher2->decryptString(enc);
|
||||
assert (dec == val);
|
||||
}
|
||||
|
||||
|
||||
void RSATest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void RSATest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* RSATest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("RSATest");
|
||||
|
||||
CppUnit_addTest(pSuite, RSATest, testNewKeys);
|
||||
CppUnit_addTest(pSuite, RSATest, testNewKeysNoPassphrase);
|
||||
CppUnit_addTest(pSuite, RSATest, testSign);
|
||||
CppUnit_addTest(pSuite, RSATest, testSignSha256);
|
||||
CppUnit_addTest(pSuite, RSATest, testSignManipulated);
|
||||
CppUnit_addTest(pSuite, RSATest, testRSACipher);
|
||||
CppUnit_addTest(pSuite, RSATest, testRSACipherLarge);
|
||||
CppUnit_addTest(pSuite, RSATest, testCertificate);
|
||||
|
||||
return pSuite;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
//
|
||||
// RSATest.h
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/RSATest.h#1 $
|
||||
//
|
||||
// Definition of the RSATest class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef RSATest_INCLUDED
|
||||
#define RSATest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class RSATest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
RSATest(const std::string& name);
|
||||
~RSATest();
|
||||
|
||||
void testNewKeys();
|
||||
void testNewKeysNoPassphrase();
|
||||
void testSign();
|
||||
void testSignSha256();
|
||||
void testSignManipulated();
|
||||
void testRSACipher();
|
||||
void testRSACipherLarge();
|
||||
void testCertificate();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // RSATest_INCLUDED
|
@ -1,50 +0,0 @@
|
||||
//
|
||||
// WinCEDriver.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/WinCEDriver.cpp#1 $
|
||||
//
|
||||
// Console-based test driver for Windows CE.
|
||||
//
|
||||
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "CryptoTestSuite.h"
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
class CryptoInitializer
|
||||
{
|
||||
public:
|
||||
CryptoInitializer()
|
||||
{
|
||||
Poco::Crypto::initializeCrypto();
|
||||
}
|
||||
|
||||
~CryptoInitializer()
|
||||
{
|
||||
Poco::Crypto::uninitializeCrypto();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int _tmain(int argc, wchar_t* argv[])
|
||||
{
|
||||
CryptoInitializer ci;
|
||||
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
char buffer[1024];
|
||||
std::wcstombs(buffer, argv[i], sizeof(buffer));
|
||||
args.push_back(std::string(buffer));
|
||||
}
|
||||
CppUnit::TestRunner runner;
|
||||
runner.addTest("CryptoTestSuite", CryptoTestSuite::suite());
|
||||
return runner.run(args) ? 0 : 1;
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/Crypto/testsuite/src/WinDriver.cpp#1 $
|
||||
//
|
||||
// Windows test driver for Poco Crypto.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "CryptoTestSuite.h"
|
||||
#include "Poco/Crypto/Crypto.h"
|
||||
|
||||
|
||||
class CryptoInitializer
|
||||
{
|
||||
public:
|
||||
CryptoInitializer()
|
||||
{
|
||||
Poco::Crypto::initializeCrypto();
|
||||
}
|
||||
|
||||
~CryptoInitializer()
|
||||
{
|
||||
Poco::Crypto::uninitializeCrypto();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
CryptoInitializer ci;
|
||||
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(CryptoTestSuite::suite());
|
||||
runner.run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TestDriver theDriver;
|
@ -1,40 +0,0 @@
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#error This file is not editable by Visual C++.
|
||||
#endif //APSTUDIO_INVOKED
|
||||
|
||||
#include "winres.h"
|
||||
|
||||
#define POCO_VERSION 1,6,1,0
|
||||
#define POCO_VERSION_STR "1.6.1"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION POCO_VERSION
|
||||
PRODUCTVERSION POCO_VERSION
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000004b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Applied Informatics Software Engineering GmbH"
|
||||
VALUE "FileDescription", "This file is part of the POCO C++ Libraries."
|
||||
VALUE "FileVersion", POCO_VERSION_STR
|
||||
VALUE "InternalName", "POCO"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2004-2015, Applied Informatics Software Engineering GmbH and Contributors."
|
||||
VALUE "ProductName", "POCO C++ Libraries - http://pocoproject.org"
|
||||
VALUE "ProductVersion", POCO_VERSION_STR
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0, 1200
|
||||
END
|
||||
END
|
@ -1,64 +0,0 @@
|
||||
set(LIBNAME "PocoData")
|
||||
set(POCO_LIBNAME "${LIBNAME}")
|
||||
|
||||
# Sources
|
||||
file(GLOB SRCS_G "src/*.cpp")
|
||||
POCO_SOURCES_AUTO( SRCS ${SRCS_G})
|
||||
|
||||
# Headers
|
||||
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
||||
POCO_HEADERS_AUTO( SRCS ${HDRS_G})
|
||||
|
||||
if (NOT POCO_STATIC)
|
||||
add_definitions(-DTHREADSAFE)
|
||||
endif (NOT POCO_STATIC)
|
||||
|
||||
if(MSVC AND NOT(MSVC_VERSION LESS 1400))
|
||||
set_source_files_properties(src/StatementImpl.cpp
|
||||
PROPERTIES COMPILE_FLAGS "/bigobj")
|
||||
endif()
|
||||
|
||||
include_directories (BEFORE include)
|
||||
|
||||
add_library( "${LIBNAME}" ${LIB_MODE} ${SRCS} )
|
||||
set_target_properties( "${LIBNAME}"
|
||||
PROPERTIES
|
||||
VERSION ${SHARED_LIBRARY_VERSION} SOVERSION ${SHARED_LIBRARY_VERSION}
|
||||
OUTPUT_NAME ${POCO_LIBNAME}
|
||||
DEFINE_SYMBOL Data_EXPORTS
|
||||
)
|
||||
|
||||
target_link_libraries( "${LIBNAME}" PocoFoundation)
|
||||
|
||||
if(POCO_ENABLE_DATA_MYSQL)
|
||||
find_package(MySQL)
|
||||
if(MYSQL_FOUND)
|
||||
include_directories("${MYSQL_INCLUDE_DIR}")
|
||||
message(STATUS "MySQL Support Enabled")
|
||||
add_subdirectory( MySQL )
|
||||
else()
|
||||
message(STATUS "MySQL Support Disabled - no MySQL library")
|
||||
endif(MYSQL_FOUND)
|
||||
endif(POCO_ENABLE_DATA_MYSQL)
|
||||
|
||||
if(POCO_ENABLE_DATA_ODBC)
|
||||
find_package(ODBC)
|
||||
if(WIN32 AND NOT WINCE)
|
||||
set(ODBC_LIBRARIES "odbc32" "odbccp32")
|
||||
message(STATUS "Windows native ODBC Support Enabled")
|
||||
add_subdirectory( ODBC )
|
||||
else(WIN32 AND NOT WINCE)
|
||||
if(ODBC_FOUND)
|
||||
include_directories("${ODBC_INCLUDE_DIRECTORIES}")
|
||||
message(STATUS "ODBC Support Enabled")
|
||||
add_subdirectory( ODBC )
|
||||
else()
|
||||
message(STATUS "ODBC Support Disabled - no ODBC runtime")
|
||||
endif()
|
||||
endif(WIN32 AND NOT WINCE)
|
||||
endif(POCO_ENABLE_DATA_ODBC)
|
||||
|
||||
if (POCO_ENABLE_TESTS)
|
||||
add_subdirectory(samples)
|
||||
add_subdirectory(testsuite)
|
||||
endif ()
|
@ -1,26 +0,0 @@
|
||||
set(LIBNAME "Poco_DataMySQL")
|
||||
set(POCO_LIBNAME "${LIBNAME}")
|
||||
|
||||
# Sources
|
||||
file(GLOB SRCS_G "src/*.cpp")
|
||||
POCO_SOURCES_AUTO( MYSQL_SRCS ${SRCS_G})
|
||||
|
||||
# Headers
|
||||
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
||||
POCO_HEADERS_AUTO( MYSQL_SRCS ${HDRS_G})
|
||||
|
||||
add_definitions(-DTHREADSAFE -DNO_TCL)
|
||||
|
||||
add_library( "${LIBNAME}" ${LIB_MODE} ${MYSQL_SRCS} )
|
||||
set_target_properties( "${LIBNAME}"
|
||||
PROPERTIES
|
||||
VERSION ${SHARED_LIBRARY_VERSION} SOVERSION ${SHARED_LIBRARY_VERSION}
|
||||
OUTPUT_NAME ${POCO_LIBNAME}
|
||||
DEFINE_SYMBOL MySQL_EXPORTS
|
||||
)
|
||||
|
||||
target_link_libraries( "${LIBNAME}" PocoFoundation PocoData ${MYSQL_LIB})
|
||||
|
||||
if (POCO_ENABLE_TESTS)
|
||||
add_subdirectory(testsuite)
|
||||
endif ()
|
@ -1,4 +0,0 @@
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(PocoFoundation)
|
||||
find_dependency(PocoData)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/PocoDataMySQLTargets.cmake")
|
@ -1,260 +0,0 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/Binder.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: Binder
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_Binder_INCLUDED
|
||||
#define Data_MySQL_Binder_INCLUDED
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
#include "Poco/Data/MySQL/MySQLException.h"
|
||||
#include <mysql.h>
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API Binder: public Poco::Data::AbstractBinder
|
||||
/// Binds placeholders in the sql query to the provided values. Performs data types mapping.
|
||||
{
|
||||
public:
|
||||
typedef SharedPtr<Binder> Ptr;
|
||||
|
||||
Binder();
|
||||
/// Creates the Binder.
|
||||
|
||||
virtual ~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int8& val, Direction dir);
|
||||
/// Binds an Int8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt8& val, Direction dir);
|
||||
/// Binds an UInt8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int16& val, Direction dir);
|
||||
/// Binds an Int16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt16& val, Direction dir);
|
||||
/// Binds an UInt16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int32& val, Direction dir);
|
||||
/// Binds an Int32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt32& val, Direction dir);
|
||||
/// Binds an UInt32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int64& val, Direction dir);
|
||||
/// Binds an Int64.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt64& val, Direction dir);
|
||||
/// Binds an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
|
||||
virtual void bind(std::size_t pos, const long& val, Direction dir = PD_IN);
|
||||
/// Binds a long.
|
||||
|
||||
virtual void bind(std::size_t pos, const unsigned long& val, Direction dir = PD_IN);
|
||||
/// Binds an unsigned long.
|
||||
|
||||
#endif // POCO_LONG_IS_64_BIT
|
||||
|
||||
virtual void bind(std::size_t pos, const bool& val, Direction dir);
|
||||
/// Binds a boolean.
|
||||
|
||||
virtual void bind(std::size_t pos, const float& val, Direction dir);
|
||||
/// Binds a float.
|
||||
|
||||
virtual void bind(std::size_t pos, const double& val, Direction dir);
|
||||
/// Binds a double.
|
||||
|
||||
virtual void bind(std::size_t pos, const char& val, Direction dir);
|
||||
/// Binds a single character.
|
||||
|
||||
virtual void bind(std::size_t pos, const std::string& val, Direction dir);
|
||||
/// Binds a string.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir);
|
||||
/// Binds a BLOB.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir);
|
||||
/// Binds a CLOB.
|
||||
|
||||
virtual void bind(std::size_t pos, const DateTime& val, Direction dir);
|
||||
/// Binds a DateTime.
|
||||
|
||||
virtual void bind(std::size_t pos, const Date& val, Direction dir);
|
||||
/// Binds a Date.
|
||||
|
||||
virtual void bind(std::size_t pos, const Time& val, Direction dir);
|
||||
/// Binds a Time.
|
||||
|
||||
virtual void bind(std::size_t pos, const NullData& val, Direction dir);
|
||||
/// Binds a null.
|
||||
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::Int8>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::Int8>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::Int8>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::UInt8>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::UInt8>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::UInt8>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::Int16>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::Int16>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::Int16>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::UInt16>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::UInt16>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::UInt16>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::Int32>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::Int32>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::Int32>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::UInt32>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::UInt32>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::UInt32>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::Int64>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::Int64>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::Int64>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Poco::UInt64>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Poco::UInt64>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Poco::UInt64>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<bool>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<bool>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<bool>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<float>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<float>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<float>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<double>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<double>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<double>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<char>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<char>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<char>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<BLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<BLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<BLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<CLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<CLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<CLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<DateTime>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<DateTime>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<DateTime>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Date>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Date>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Date>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<Time>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<Time>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<Time>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<NullData>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<NullData>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<NullData>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::vector<std::string>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::deque<std::string>& val, Direction dir = PD_IN);
|
||||
|
||||
virtual void bind(std::size_t pos, const std::list<std::string>& val, Direction dir = PD_IN);
|
||||
|
||||
std::size_t size() const;
|
||||
/// Return count of binded parameters
|
||||
|
||||
MYSQL_BIND* getBindArray() const;
|
||||
/// Return array
|
||||
|
||||
//void updateDates();
|
||||
/// Update linked times
|
||||
|
||||
private:
|
||||
Binder(const Binder&);
|
||||
/// Don't copy the binder
|
||||
|
||||
virtual void bind(std::size_t, const char* const&, Direction)
|
||||
/// Binds a const char ptr.
|
||||
/// This is a private no-op in this implementation
|
||||
/// due to security risk.
|
||||
{
|
||||
}
|
||||
|
||||
void realBind(std::size_t pos, enum_field_types type, const void* buffer, int length, bool isUnsigned = false);
|
||||
/// Common bind implementation
|
||||
|
||||
private:
|
||||
|
||||
std::vector<MYSQL_BIND> _bindArray;
|
||||
std::vector<MYSQL_TIME*> _dates;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_Binder_INCLUDED
|
@ -1,127 +0,0 @@
|
||||
//
|
||||
// Connector.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/Connector.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: Connector
|
||||
//
|
||||
// Definition of the Connector class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_Connector_INCLUDED
|
||||
#define Data_MySQL_Connector_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/Connector.h"
|
||||
|
||||
|
||||
// Note: to avoid static (de)initialization problems,
|
||||
// during connector automatic (un)registration, it is
|
||||
// best to have this as a macro.
|
||||
#define POCO_DATA_MYSQL_CONNECTOR_NAME "mysql"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API Connector: public Poco::Data::Connector
|
||||
/// Connector instantiates MySQL SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
|
||||
static std::string KEY;
|
||||
|
||||
Connector();
|
||||
/// Creates the Connector.
|
||||
|
||||
virtual ~Connector();
|
||||
/// Destroys the Connector.
|
||||
|
||||
virtual const std::string& name() const;
|
||||
/// Returns the name associated with this connector.
|
||||
|
||||
virtual Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString,
|
||||
std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates a MySQL SessionImpl object and initializes it with the given connectionString.
|
||||
|
||||
static void registerConnector();
|
||||
/// Registers the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
|
||||
|
||||
static void unregisterConnector();
|
||||
/// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
//
|
||||
// Automatic Connector registration
|
||||
//
|
||||
|
||||
struct MySQL_API MySQLConnectorRegistrator
|
||||
/// Connector registering class.
|
||||
/// A global instance of this class is instantiated
|
||||
/// with sole purpose to automatically register the
|
||||
/// MySQL connector with central Poco Data registry.
|
||||
{
|
||||
MySQLConnectorRegistrator()
|
||||
/// Calls Poco::Data::MySQL::registerConnector();
|
||||
{
|
||||
Poco::Data::MySQL::Connector::registerConnector();
|
||||
}
|
||||
|
||||
~MySQLConnectorRegistrator()
|
||||
/// Calls Poco::Data::MySQL::unregisterConnector();
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::Data::MySQL::Connector::unregisterConnector();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(__GNUC__)
|
||||
extern "C" const struct MySQL_API MySQLConnectorRegistrator pocoMySQLConnectorRegistrator;
|
||||
#if defined(MySQL_EXPORTS)
|
||||
#if defined(_WIN64)
|
||||
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
|
||||
#endif
|
||||
#else // !MySQL_EXPORTS
|
||||
#if defined(_WIN64)
|
||||
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
|
||||
#endif
|
||||
#endif // MySQL_EXPORTS
|
||||
#else // !POCO_OS_FAMILY_WINDOWS
|
||||
#define POCO_DATA_MYSQL_FORCE_SYMBOL(s) extern "C" const struct MySQLConnectorRegistrator s;
|
||||
#endif // POCO_OS_FAMILY_WINDOWS
|
||||
POCO_DATA_MYSQL_FORCE_SYMBOL(pocoMySQLConnectorRegistrator)
|
||||
#endif // POCO_NO_AUTOMATIC_LIB_INIT
|
||||
|
||||
//
|
||||
// End automatic Connector registration
|
||||
//
|
||||
|
||||
|
||||
#endif // Data_MySQL_Connector_INCLUDED
|
@ -1,338 +0,0 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/Extractor.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: Extractor
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_Extractor_INCLUDED
|
||||
#define Data_MySQL_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/MySQL/StatementExecutor.h"
|
||||
#include "Poco/Data/MySQL/ResultMetadata.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
namespace Dynamic {
|
||||
class Var;
|
||||
}
|
||||
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API Extractor: public Poco::Data::AbstractExtractor
|
||||
/// Extracts and converts data values from the result row returned by MySQL.
|
||||
/// If NULL is received, the incoming val value is not changed and false is returned
|
||||
{
|
||||
public:
|
||||
typedef SharedPtr<Extractor> Ptr;
|
||||
|
||||
Extractor(StatementExecutor& st, ResultMetadata& md);
|
||||
/// Creates the Extractor.
|
||||
|
||||
virtual ~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
virtual bool extract(std::size_t pos, long& val);
|
||||
/// Extracts a long. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, unsigned long& val);
|
||||
/// Extracts an unsigned long. Returns false if null was received.
|
||||
#endif
|
||||
|
||||
virtual bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
virtual bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
virtual bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
virtual bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Data::BLOB& val);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Data::CLOB& val);
|
||||
/// Extracts a CLOB.
|
||||
|
||||
virtual bool extract(std::size_t pos, DateTime& val);
|
||||
/// Extracts a DateTime. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Date& val);
|
||||
/// Extracts a Date. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Time& val);
|
||||
/// Extracts a Time. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Any& val);
|
||||
/// Extracts an Any. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Dynamic::Var& val);
|
||||
/// Extracts a Dynamic::Var. Returns false if null was received.
|
||||
|
||||
virtual bool isNull(std::size_t col, std::size_t row);
|
||||
/// Returns true if the value at [col,row] position is null.
|
||||
|
||||
virtual void reset();
|
||||
/// Resets any information internally cached by the extractor.
|
||||
|
||||
////////////
|
||||
// Not implemented extract functions
|
||||
////////////
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::Int8>& val);
|
||||
/// Extracts an Int8 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::Int8>& val);
|
||||
/// Extracts an Int8 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int8>& val);
|
||||
/// Extracts an Int8 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::UInt8>& val);
|
||||
/// Extracts an UInt8 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::UInt8>& val);
|
||||
/// Extracts an UInt8 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt8>& val);
|
||||
/// Extracts an UInt8 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::Int16>& val);
|
||||
/// Extracts an Int16 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::Int16>& val);
|
||||
/// Extracts an Int16 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int16>& val);
|
||||
/// Extracts an Int16 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::UInt16>& val);
|
||||
/// Extracts an UInt16 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::UInt16>& val);
|
||||
/// Extracts an UInt16 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt16>& val);
|
||||
/// Extracts an UInt16 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::Int32>& val);
|
||||
/// Extracts an Int32 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::Int32>& val);
|
||||
/// Extracts an Int32 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int32>& val);
|
||||
/// Extracts an Int32 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::UInt32>& val);
|
||||
/// Extracts an UInt32 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::UInt32>& val);
|
||||
/// Extracts an UInt32 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt32>& val);
|
||||
/// Extracts an UInt32 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::Int64>& val);
|
||||
/// Extracts an Int64 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::Int64>& val);
|
||||
/// Extracts an Int64 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int64>& val);
|
||||
/// Extracts an Int64 list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Poco::UInt64>& val);
|
||||
/// Extracts an UInt64 vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Poco::UInt64>& val);
|
||||
/// Extracts an UInt64 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt64>& val);
|
||||
/// Extracts an UInt64 list.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
virtual bool extract(std::size_t pos, std::vector<long>& val);
|
||||
/// Extracts a long vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<long>& val);
|
||||
/// Extracts a long deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<long>& val);
|
||||
/// Extracts a long list.
|
||||
#endif
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<bool>& val);
|
||||
/// Extracts a boolean vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<bool>& val);
|
||||
/// Extracts a boolean deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<bool>& val);
|
||||
/// Extracts a boolean list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<float>& val);
|
||||
/// Extracts a float vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<float>& val);
|
||||
/// Extracts a float deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<float>& val);
|
||||
/// Extracts a float list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<double>& val);
|
||||
/// Extracts a double vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<double>& val);
|
||||
/// Extracts a double deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<double>& val);
|
||||
/// Extracts a double list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<char>& val);
|
||||
/// Extracts a character vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<char>& val);
|
||||
/// Extracts a character deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<char>& val);
|
||||
/// Extracts a character list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<std::string>& val);
|
||||
/// Extracts a string vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<std::string>& val);
|
||||
/// Extracts a string deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<std::string>& val);
|
||||
/// Extracts a string list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<BLOB>& val);
|
||||
/// Extracts a BLOB vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<BLOB>& val);
|
||||
/// Extracts a BLOB deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<BLOB>& val);
|
||||
/// Extracts a BLOB list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<CLOB>& val);
|
||||
/// Extracts a CLOB vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<CLOB>& val);
|
||||
/// Extracts a CLOB deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<CLOB>& val);
|
||||
/// Extracts a CLOB list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<DateTime>& val);
|
||||
/// Extracts a DateTime vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<DateTime>& val);
|
||||
/// Extracts a DateTime deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<DateTime>& val);
|
||||
/// Extracts a DateTime list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Date>& val);
|
||||
/// Extracts a Date vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Date>& val);
|
||||
/// Extracts a Date deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Date>& val);
|
||||
/// Extracts a Date list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Time>& val);
|
||||
/// Extracts a Time vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Time>& val);
|
||||
/// Extracts a Time deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Time>& val);
|
||||
/// Extracts a Time list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Any>& val);
|
||||
/// Extracts an Any vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Any>& val);
|
||||
/// Extracts an Any deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Any>& val);
|
||||
/// Extracts an Any list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<Dynamic::Var>& val);
|
||||
/// Extracts a Dynamic::Var vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<Dynamic::Var>& val);
|
||||
/// Extracts a Dynamic::Var deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Dynamic::Var>& val);
|
||||
/// Extracts a Dynamic::Var list.
|
||||
|
||||
private:
|
||||
|
||||
bool realExtractFixed(std::size_t pos, enum_field_types type, void* buffer, bool isUnsigned = false);
|
||||
|
||||
// Prevent VC8 warning "operator= could not be generated"
|
||||
Extractor& operator=(const Extractor&);
|
||||
|
||||
private:
|
||||
|
||||
StatementExecutor& _stmt;
|
||||
ResultMetadata& _metadata;
|
||||
};
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_Extractor_INCLUDED
|
@ -1,62 +0,0 @@
|
||||
//
|
||||
// MySQL.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/MySQL.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: MySQL
|
||||
//
|
||||
// Basic definitions for the MySQL library.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef MySQL_MySQL_INCLUDED
|
||||
#define MySQL_MySQL_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the ODBC_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// ODBC_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(MySQL_EXPORTS)
|
||||
#define MySQL_API __declspec(dllexport)
|
||||
#else
|
||||
#define MySQL_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(MySQL_API)
|
||||
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
|
||||
#define MySQL_API __attribute__ ((visibility ("default")))
|
||||
#else
|
||||
#define MySQL_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Data library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(MySQL_EXPORTS)
|
||||
#pragma comment(lib, "PocoDataMySQL" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // MySQL_MySQL_INCLUDED
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user