diff --git a/lib/EAPBase/build/EAPBase.vcxproj b/lib/EAPBase/build/EAPBase.vcxproj index c1356db..06c807e 100644 --- a/lib/EAPBase/build/EAPBase.vcxproj +++ b/lib/EAPBase/build/EAPBase.vcxproj @@ -82,7 +82,6 @@ - diff --git a/lib/EAPBase/build/EAPBase.vcxproj.filters b/lib/EAPBase/build/EAPBase.vcxproj.filters index 520ae1d..7940a33 100644 --- a/lib/EAPBase/build/EAPBase.vcxproj.filters +++ b/lib/EAPBase/build/EAPBase.vcxproj.filters @@ -17,9 +17,6 @@ Header Files - - Header Files - Header Files diff --git a/lib/EAPBase/include/Config.h b/lib/EAPBase/include/Config.h index 46a6a66..85360ad 100644 --- a/lib/EAPBase/include/Config.h +++ b/lib/EAPBase/include/Config.h @@ -18,6 +18,8 @@ along with GÉANTLink. If not, see . */ +#include "EAP.h" + #include namespace eap @@ -74,7 +76,6 @@ namespace eapserial #pragma once #include "Module.h" -#include "EAPSerial.h" #include "EAPXML.h" #include "../../../include/Version.h" diff --git a/lib/EAPBase/include/Credentials.h b/lib/EAPBase/include/Credentials.h index 16bd42d..91f88ed 100644 --- a/lib/EAPBase/include/Credentials.h +++ b/lib/EAPBase/include/Credentials.h @@ -37,7 +37,6 @@ namespace eap #include "Config.h" #include "Module.h" -#include "EAPSerial.h" #include "../../../include/Version.h" diff --git a/lib/EAPBase/include/EAP.h b/lib/EAPBase/include/EAP.h index fe9b52f..454508f 100644 --- a/lib/EAPBase/include/EAP.h +++ b/lib/EAPBase/include/EAP.h @@ -27,8 +27,15 @@ #if !defined(RC_INVOKED) && !defined(MIDL_PASS) +#include + #include +#include +#include +#include +#include + namespace eap { /// @@ -41,6 +48,260 @@ namespace eap namespace eapserial { + /// + /// Packs a boolean + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val Variable with data to pack + /// + inline void pack(_Inout_ unsigned char *&cursor, _In_ const bool &val); + + /// + /// Returns packed size of a boolean + /// + /// \param[in] val Data to pack + /// + /// \returns Size of data when packed (in bytes) + /// + inline size_t get_pk_size(_In_ const bool &val); + + /// + /// Unpacks a boolean + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val Variable to receive unpacked value + /// + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ bool &val); + + /// + /// Packs a byte + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val Variable with data to pack + /// + inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned char &val); + + /// + /// Returns packed size of a byte + /// + /// \param[in] val Data to pack + /// + /// \returns Size of data when packed (in bytes) + /// + inline size_t get_pk_size(_In_ const unsigned char &val); + + /// + /// Unpacks a byte + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val Variable to receive unpacked value + /// + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned char &val); + + /// + /// Packs an unsigned int + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val Variable with data to pack + /// + inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned int &val); + + /// + /// Returns packed size of an unsigned int + /// + /// \param[in] val Data to pack + /// + /// \returns Size of data when packed (in bytes) + /// + inline size_t get_pk_size(_In_ const unsigned int &val); + + /// + /// Unpacks an unsigned int + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val Variable to receive unpacked value + /// + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned int &val); + +#ifdef _WIN64 + /// + /// Packs a size_t + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val Variable with data to pack + /// + inline void pack(_Inout_ unsigned char *&cursor, _In_ const size_t &val); + + /// + /// Returns packed size of a size_t + /// + /// \param[in] val Data to pack + /// + /// \returns Size of data when packed (in bytes) + /// + inline size_t get_pk_size(_In_ const size_t &val); + + /// + /// Unpacks a size_t + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val Variable to receive unpacked value + /// + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ size_t &val); +#endif + + /// + /// Packs a string + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val String to pack + /// + template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string<_Elem, _Traits, _Ax> &val); + + /// + /// Returns packed size of a string + /// + /// \param[in] val String to pack + /// + /// \returns Size of data when packed (in bytes) + /// + template inline size_t get_pk_size(const std::basic_string<_Elem, _Traits, _Ax> &val); + + /// + /// Unpacks a string + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val String to unpack to + /// + template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string<_Elem, _Traits, _Ax> &val); + + /// + /// Packs a wide string + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val String to pack + /// + template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string &val); + + /// + /// Returns packed size of a wide string + /// + /// \param[in] val String to pack + /// + /// \returns Size of data when packed (in bytes) + /// + template inline size_t get_pk_size(const std::basic_string &val); + + /// + /// Unpacks a wide string + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val String to unpack to + /// + template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string &val); + + /// + /// Packs a vector + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val Vector to pack + /// + template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::vector<_Ty, _Ax> &val); + + /// + /// Returns packed size of a vector + /// + /// \param[in] val Vector to pack + /// + /// \returns Size of data when packed (in bytes) + /// + template inline size_t get_pk_size(const std::vector<_Ty, _Ax> &val); + + /// + /// Unpacks a vector + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val Vector to unpack to + /// + template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::vector<_Ty, _Ax> &val); + + /// + /// Packs a list + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val List to pack + /// + template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::list<_Ty, _Ax> &val); + + /// + /// Returns packed size of a list + /// + /// \param[in] val List to pack + /// + /// \returns Size of data when packed (in bytes) + /// + template inline size_t get_pk_size(const std::list<_Ty, _Ax> &val); + + /// + /// Unpacks a list + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val List to unpack to + /// + template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::list<_Ty, _Ax> &val); + + /// + /// Packs a std::unique_ptr + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val std::unique_ptr to pack + /// + template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::unique_ptr<_Ty, _Dx> &val); + + /// + /// Returns packed size of a std::unique_ptr + /// + /// \param[in] val std::unique_ptr to pack + /// + /// \returns Size of data when packed (in bytes) + /// + template inline size_t get_pk_size(const std::unique_ptr<_Ty, _Dx> &val); + + ///// + ///// Unpacks a std::unique_ptr + ///// + ///// \note Not generally unpackable, since we do not know, how to create a new instance of unique_ptr. + ///// + ///// \param[inout] cursor Memory cursor + ///// \param[out] val std::unique_ptr to unpack to + ///// + //template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::unique_ptr<_Ty, _Dx> &val); + + /// + /// Packs a certificate context + /// + /// \param[inout] cursor Memory cursor + /// \param[in] val Certificate context to pack + /// + inline void pack(_Inout_ unsigned char *&cursor, _In_ const winstd::cert_context &val); + + /// + /// Returns packed size of a certificate context + /// + /// \param[in] val Certificate context to pack + /// + /// \returns Size of data when packed (in bytes) + /// + inline size_t get_pk_size(const winstd::cert_context &val); + + /// + /// Unpacks a certificate context + /// + /// \param[inout] cursor Memory cursor + /// \param[out] val Certificate context to unpack to + /// + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ winstd::cert_context &val); + /// /// Packs an EAP method type /// @@ -67,11 +328,8 @@ namespace eapserial inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ eap::type_t &val); } - #pragma once -#include "EAPSerial.h" - namespace eap { @@ -88,6 +346,295 @@ namespace eap namespace eapserial { + inline void pack(_Inout_ unsigned char *&cursor, _In_ const bool &val) + { + *cursor = val ? 1 : 0; + cursor++; + } + + + inline size_t get_pk_size(_In_ const bool &val) + { + UNREFERENCED_PARAMETER(val); + return sizeof(unsigned char); + } + + + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ bool &val) + { + val = *cursor ? true : false; + cursor++; + } + + + inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned char &val) + { + *cursor = val; + cursor++; + } + + + inline size_t get_pk_size(_In_ const unsigned char &val) + { + UNREFERENCED_PARAMETER(val); + return sizeof(unsigned char); + } + + + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned char &val) + { + val = *cursor; + cursor++; + } + + + inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned int &val) + { + *(unsigned int*)cursor = val; + cursor += sizeof(unsigned int); + } + + + inline size_t get_pk_size(_In_ const unsigned int &val) + { + UNREFERENCED_PARAMETER(val); + return sizeof(unsigned int); + } + + + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned int &val) + { + val = *(unsigned int*)cursor; + cursor += sizeof(unsigned int); + } + + +#ifdef _WIN64 + inline void pack(_Inout_ unsigned char *&cursor, _In_ const size_t &val) + { + *(size_t*)cursor = val; + cursor += sizeof(size_t); + } + + + inline size_t get_pk_size(_In_ const size_t &val) + { + UNREFERENCED_PARAMETER(val); + return sizeof(size_t); + } + + + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ size_t &val) + { + val = *(size_t*)cursor; + cursor += sizeof(size_t); + } +#endif + + + template + inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string<_Elem, _Traits, _Ax> &val) + { + std::basic_string<_Elem, _Traits, _Ax>::size_type count = val.length(); + assert(strlen(val.c_str()) == count); // String should not contain null characters + size_t nSize = sizeof(_Elem)*(count + 1); + memcpy(cursor, (const _Elem*)val.c_str(), nSize); + cursor += nSize; + } + + + template + inline size_t get_pk_size(const std::basic_string<_Elem, _Traits, _Ax> &val) + { + return sizeof(_Elem)*(val.length() + 1); + } + + + template + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string<_Elem, _Traits, _Ax> &val) + { + std::basic_string<_Elem, _Traits, _Ax>::size_type count = strlen((const _Elem*&)cursor); + val.assign((const _Elem*&)cursor, count); + cursor += sizeof(_Elem)*(count + 1); + } + + + template + inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string &val) + { + std::string val_utf8; + WideCharToMultiByte(CP_UTF8, 0, val.c_str(), (int)val.length(), val_utf8, NULL, NULL); + pack(cursor, val_utf8); + } + + + template + inline size_t get_pk_size(const std::basic_string &val) + { + return sizeof(std::string::size_type) + WideCharToMultiByte(CP_UTF8, 0, val.c_str(), (int)val.length(), NULL, 0, NULL, NULL); + } + + + template + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string &val) + { + std::string val_utf8; + unpack(cursor, val_utf8); + MultiByteToWideChar(CP_UTF8, 0, val_utf8.c_str(), (int)val_utf8.length(), val); + } + + + template + inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::vector<_Ty, _Ax> &val) + { + std::vector<_Ty, _Ax>::size_type count = val.size(); + pack(cursor, count); + + // Since we do not know wheter vector elements are primitives or objects, iterate instead of memcpy. + // For performance critical vectors of flat opaque data types write specialized template instantiation. + for (std::vector<_Ty, _Ax>::size_type i = 0; i < count; i++) + pack(cursor, val[i]); + } + + + template + inline size_t get_pk_size(const std::vector<_Ty, _Ax> &val) + { + // Since we do not know wheter vector elements are primitives or objects, iterate instead of sizeof(). + // For performance critical vectors of flat opaque data types write specialized template instantiation. + std::vector<_Ty, _Ax>::size_type count = val.size(); + size_t size = get_pk_size(count); + for (std::vector<_Ty, _Ax>::size_type i = 0; i < count; i++) + size += get_pk_size(val[i]); + return size; + } + + + template + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::vector<_Ty, _Ax> &val) + { + std::vector<_Ty, _Ax>::size_type count; + unpack(cursor, count); + + // Since we do not know wheter vector elements are primitives or objects, iterate instead of assign(). + // For performance critical vectors of flat opaque data types write specialized template instantiation. + val.clear(); + val.reserve(count); + for (std::vector<_Ty, _Ax>::size_type i = 0; i < count; i++) { + _Ty el; + unpack(cursor, el); + val.push_back(el); + } + } + + + template + inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::list<_Ty, _Ax> &val) + { + std::list<_Ty, _Ax>::size_type count = val.size(); + pack(cursor, count); + + // Since we do not know wheter list elements are primitives or objects, iterate instead of memcpy. + // For performance critical vectors of flat opaque data types write specialized template instantiation. + for (std::list<_Ty, _Ax>::const_iterator i = val.cbegin(), i_end = val.cend(); i != i_end; ++i) + pack(cursor, *i); + } + + + template + inline size_t get_pk_size(const std::list<_Ty, _Ax> &val) + { + // Since we do not know wheter list elements are primitives or objects, iterate instead of sizeof(). + // For performance critical vectors of flat opaque data types write specialized template instantiation. + std::list<_Ty, _Ax>::size_type count = val.size(); + size_t size = get_pk_size(count); + for (std::list<_Ty, _Ax>::const_iterator i = val.cbegin(), i_end = val.cend(); i != i_end; ++i) + size += get_pk_size(*i); + return size; + } + + + template + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::list<_Ty, _Ax> &val) + { + std::list<_Ty, _Ax>::size_type count; + unpack(cursor, count); + + // Since we do not know wheter list elements are primitives or objects, iterate instead of assign(). + // For performance critical vectors of flat opaque data types write specialized template instantiation. + val.clear(); + for (std::list<_Ty, _Ax>::size_type i = 0; i < count; i++) { + _Ty el; + unpack(cursor, el); + val.push_back(el); + } + } + + + template + inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::unique_ptr<_Ty, _Dx> &val) + { + if (val) { + pack(cursor, true); + pack(cursor, *val); + } else + pack(cursor, false); + } + + + template + inline size_t get_pk_size(const std::unique_ptr<_Ty, _Dx> &val) + { + return + val ? + get_pk_size(true) + + get_pk_size(*val) : + get_pk_size(false); + } + + + inline void pack(_Inout_ unsigned char *&cursor, _In_ const winstd::cert_context &val) + { + if (val) { + pack(cursor, (unsigned int)val->dwCertEncodingType); + pack(cursor, (unsigned int)val->cbCertEncoded ); + memcpy(cursor, val->pbCertEncoded, val->cbCertEncoded); + cursor += val->cbCertEncoded; + } else { + pack(cursor, (unsigned int)0); + pack(cursor, (unsigned int)0); + } + } + + + inline size_t get_pk_size(const winstd::cert_context &val) + { + return + val ? + get_pk_size((unsigned int)val->dwCertEncodingType) + + get_pk_size((unsigned int)val->cbCertEncoded ) + + val->cbCertEncoded : + get_pk_size((unsigned int)0) + + get_pk_size((unsigned int)0); + } + + + inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ winstd::cert_context &val) + { + DWORD dwCertEncodingType; + unpack(cursor, (unsigned int&)dwCertEncodingType); + + DWORD dwCertEncodedSize; + unpack(cursor, (unsigned int&)dwCertEncodedSize); + + if (dwCertEncodedSize) { + val.create(dwCertEncodingType, (BYTE*)cursor, dwCertEncodedSize); + cursor += dwCertEncodedSize; + } else + val.free(); + } + + inline void pack(_Inout_ unsigned char *&cursor, _In_ const eap::type_t &val) { pack(cursor, (unsigned char)val); diff --git a/lib/EAPBase/include/EAPSerial.h b/lib/EAPBase/include/EAPSerial.h deleted file mode 100644 index 7b180b6..0000000 --- a/lib/EAPBase/include/EAPSerial.h +++ /dev/null @@ -1,579 +0,0 @@ -/* - Copyright 2015-2016 Amebis - Copyright 2016 GÉANT - - This file is part of GÉANTLink. - - GÉANTLink is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - GÉANTLink is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GÉANTLink. If not, see . -*/ - -#include - -#include - -#include -#include -#include -#include - -namespace eapserial -{ - /// - /// Packs a boolean - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val Variable with data to pack - /// - inline void pack(_Inout_ unsigned char *&cursor, _In_ const bool &val); - - /// - /// Returns packed size of a boolean - /// - /// \param[in] val Data to pack - /// - /// \returns Size of data when packed (in bytes) - /// - inline size_t get_pk_size(_In_ const bool &val); - - /// - /// Unpacks a boolean - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val Variable to receive unpacked value - /// - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ bool &val); - - /// - /// Packs a byte - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val Variable with data to pack - /// - inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned char &val); - - /// - /// Returns packed size of a byte - /// - /// \param[in] val Data to pack - /// - /// \returns Size of data when packed (in bytes) - /// - inline size_t get_pk_size(_In_ const unsigned char &val); - - /// - /// Unpacks a byte - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val Variable to receive unpacked value - /// - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned char &val); - - /// - /// Packs an unsigned int - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val Variable with data to pack - /// - inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned int &val); - - /// - /// Returns packed size of an unsigned int - /// - /// \param[in] val Data to pack - /// - /// \returns Size of data when packed (in bytes) - /// - inline size_t get_pk_size(_In_ const unsigned int &val); - - /// - /// Unpacks an unsigned int - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val Variable to receive unpacked value - /// - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned int &val); - -#ifdef _WIN64 - /// - /// Packs a size_t - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val Variable with data to pack - /// - inline void pack(_Inout_ unsigned char *&cursor, _In_ const size_t &val); - - /// - /// Returns packed size of a size_t - /// - /// \param[in] val Data to pack - /// - /// \returns Size of data when packed (in bytes) - /// - inline size_t get_pk_size(_In_ const size_t &val); - - /// - /// Unpacks a size_t - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val Variable to receive unpacked value - /// - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ size_t &val); -#endif - - /// - /// Packs a string - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val String to pack - /// - template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string<_Elem, _Traits, _Ax> &val); - - /// - /// Returns packed size of a string - /// - /// \param[in] val String to pack - /// - /// \returns Size of data when packed (in bytes) - /// - template inline size_t get_pk_size(const std::basic_string<_Elem, _Traits, _Ax> &val); - - /// - /// Unpacks a string - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val String to unpack to - /// - template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string<_Elem, _Traits, _Ax> &val); - - /// - /// Packs a wide string - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val String to pack - /// - template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string &val); - - /// - /// Returns packed size of a wide string - /// - /// \param[in] val String to pack - /// - /// \returns Size of data when packed (in bytes) - /// - template inline size_t get_pk_size(const std::basic_string &val); - - /// - /// Unpacks a wide string - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val String to unpack to - /// - template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string &val); - - /// - /// Packs a vector - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val Vector to pack - /// - template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::vector<_Ty, _Ax> &val); - - /// - /// Returns packed size of a vector - /// - /// \param[in] val Vector to pack - /// - /// \returns Size of data when packed (in bytes) - /// - template inline size_t get_pk_size(const std::vector<_Ty, _Ax> &val); - - /// - /// Unpacks a vector - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val Vector to unpack to - /// - template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::vector<_Ty, _Ax> &val); - - /// - /// Packs a list - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val List to pack - /// - template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::list<_Ty, _Ax> &val); - - /// - /// Returns packed size of a list - /// - /// \param[in] val List to pack - /// - /// \returns Size of data when packed (in bytes) - /// - template inline size_t get_pk_size(const std::list<_Ty, _Ax> &val); - - /// - /// Unpacks a list - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val List to unpack to - /// - template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::list<_Ty, _Ax> &val); - - /// - /// Packs a std::unique_ptr - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val std::unique_ptr to pack - /// - template inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::unique_ptr<_Ty, _Dx> &val); - - /// - /// Returns packed size of a std::unique_ptr - /// - /// \param[in] val std::unique_ptr to pack - /// - /// \returns Size of data when packed (in bytes) - /// - template inline size_t get_pk_size(const std::unique_ptr<_Ty, _Dx> &val); - - ///// - ///// Unpacks a std::unique_ptr - ///// - ///// \note Not generally unpackable, since we do not know, how to create a new instance of unique_ptr. - ///// - ///// \param[inout] cursor Memory cursor - ///// \param[out] val std::unique_ptr to unpack to - ///// - //template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::unique_ptr<_Ty, _Dx> &val); - - /// - /// Packs a certificate context - /// - /// \param[inout] cursor Memory cursor - /// \param[in] val Certificate context to pack - /// - inline void pack(_Inout_ unsigned char *&cursor, _In_ const winstd::cert_context &val); - - /// - /// Returns packed size of a certificate context - /// - /// \param[in] val Certificate context to pack - /// - /// \returns Size of data when packed (in bytes) - /// - inline size_t get_pk_size(const winstd::cert_context &val); - - /// - /// Unpacks a certificate context - /// - /// \param[inout] cursor Memory cursor - /// \param[out] val Certificate context to unpack to - /// - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ winstd::cert_context &val); -} - -#pragma once - - -namespace eapserial -{ - inline void pack(_Inout_ unsigned char *&cursor, _In_ const bool &val) - { - *cursor = val ? 1 : 0; - cursor++; - } - - - inline size_t get_pk_size(_In_ const bool &val) - { - UNREFERENCED_PARAMETER(val); - return sizeof(unsigned char); - } - - - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ bool &val) - { - val = *cursor ? true : false; - cursor++; - } - - - inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned char &val) - { - *cursor = val; - cursor++; - } - - - inline size_t get_pk_size(_In_ const unsigned char &val) - { - UNREFERENCED_PARAMETER(val); - return sizeof(unsigned char); - } - - - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned char &val) - { - val = *cursor; - cursor++; - } - - - inline void pack(_Inout_ unsigned char *&cursor, _In_ const unsigned int &val) - { - *(unsigned int*)cursor = val; - cursor += sizeof(unsigned int); - } - - - inline size_t get_pk_size(_In_ const unsigned int &val) - { - UNREFERENCED_PARAMETER(val); - return sizeof(unsigned int); - } - - - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ unsigned int &val) - { - val = *(unsigned int*)cursor; - cursor += sizeof(unsigned int); - } - - -#ifdef _WIN64 - inline void pack(_Inout_ unsigned char *&cursor, _In_ const size_t &val) - { - *(size_t*)cursor = val; - cursor += sizeof(size_t); - } - - - inline size_t get_pk_size(_In_ const size_t &val) - { - UNREFERENCED_PARAMETER(val); - return sizeof(size_t); - } - - - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ size_t &val) - { - val = *(size_t*)cursor; - cursor += sizeof(size_t); - } -#endif - - - template - inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string<_Elem, _Traits, _Ax> &val) - { - std::basic_string<_Elem, _Traits, _Ax>::size_type count = val.length(); - assert(strlen(val.c_str()) == count); // String should not contain null characters - size_t nSize = sizeof(_Elem)*(count + 1); - memcpy(cursor, (const _Elem*)val.c_str(), nSize); - cursor += nSize; - } - - - template - inline size_t get_pk_size(const std::basic_string<_Elem, _Traits, _Ax> &val) - { - return sizeof(_Elem)*(val.length() + 1); - } - - - template - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string<_Elem, _Traits, _Ax> &val) - { - std::basic_string<_Elem, _Traits, _Ax>::size_type count = strlen((const _Elem*&)cursor); - val.assign((const _Elem*&)cursor, count); - cursor += sizeof(_Elem)*(count + 1); - } - - - template - inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::basic_string &val) - { - std::string val_utf8; - WideCharToMultiByte(CP_UTF8, 0, val.c_str(), (int)val.length(), val_utf8, NULL, NULL); - pack(cursor, val_utf8); - } - - - template - inline size_t get_pk_size(const std::basic_string &val) - { - return sizeof(std::string::size_type) + WideCharToMultiByte(CP_UTF8, 0, val.c_str(), (int)val.length(), NULL, 0, NULL, NULL); - } - - - template - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::basic_string &val) - { - std::string val_utf8; - unpack(cursor, val_utf8); - MultiByteToWideChar(CP_UTF8, 0, val_utf8.c_str(), (int)val_utf8.length(), val); - } - - - template - inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::vector<_Ty, _Ax> &val) - { - std::vector<_Ty, _Ax>::size_type count = val.size(); - pack(cursor, count); - - // Since we do not know wheter vector elements are primitives or objects, iterate instead of memcpy. - // For performance critical vectors of flat opaque data types write specialized template instantiation. - for (std::vector<_Ty, _Ax>::size_type i = 0; i < count; i++) - pack(cursor, val[i]); - } - - - template - inline size_t get_pk_size(const std::vector<_Ty, _Ax> &val) - { - // Since we do not know wheter vector elements are primitives or objects, iterate instead of sizeof(). - // For performance critical vectors of flat opaque data types write specialized template instantiation. - std::vector<_Ty, _Ax>::size_type count = val.size(); - size_t size = get_pk_size(count); - for (std::vector<_Ty, _Ax>::size_type i = 0; i < count; i++) - size += get_pk_size(val[i]); - return size; - } - - - template - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::vector<_Ty, _Ax> &val) - { - std::vector<_Ty, _Ax>::size_type count; - unpack(cursor, count); - - // Since we do not know wheter vector elements are primitives or objects, iterate instead of assign(). - // For performance critical vectors of flat opaque data types write specialized template instantiation. - val.clear(); - val.reserve(count); - for (std::vector<_Ty, _Ax>::size_type i = 0; i < count; i++) { - _Ty el; - unpack(cursor, el); - val.push_back(el); - } - } - - - template - inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::list<_Ty, _Ax> &val) - { - std::list<_Ty, _Ax>::size_type count = val.size(); - pack(cursor, count); - - // Since we do not know wheter list elements are primitives or objects, iterate instead of memcpy. - // For performance critical vectors of flat opaque data types write specialized template instantiation. - for (std::list<_Ty, _Ax>::const_iterator i = val.cbegin(), i_end = val.cend(); i != i_end; ++i) - pack(cursor, *i); - } - - - template - inline size_t get_pk_size(const std::list<_Ty, _Ax> &val) - { - // Since we do not know wheter list elements are primitives or objects, iterate instead of sizeof(). - // For performance critical vectors of flat opaque data types write specialized template instantiation. - std::list<_Ty, _Ax>::size_type count = val.size(); - size_t size = get_pk_size(count); - for (std::list<_Ty, _Ax>::const_iterator i = val.cbegin(), i_end = val.cend(); i != i_end; ++i) - size += get_pk_size(*i); - return size; - } - - - template - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ std::list<_Ty, _Ax> &val) - { - std::list<_Ty, _Ax>::size_type count; - unpack(cursor, count); - - // Since we do not know wheter list elements are primitives or objects, iterate instead of assign(). - // For performance critical vectors of flat opaque data types write specialized template instantiation. - val.clear(); - for (std::list<_Ty, _Ax>::size_type i = 0; i < count; i++) { - _Ty el; - unpack(cursor, el); - val.push_back(el); - } - } - - - template - inline void pack(_Inout_ unsigned char *&cursor, _In_ const std::unique_ptr<_Ty, _Dx> &val) - { - if (val) { - pack(cursor, true); - pack(cursor, *val); - } else - pack(cursor, false); - } - - - template - inline size_t get_pk_size(const std::unique_ptr<_Ty, _Dx> &val) - { - return - val ? - get_pk_size(true) + - get_pk_size(*val) : - get_pk_size(false); - } - - - inline void pack(_Inout_ unsigned char *&cursor, _In_ const winstd::cert_context &val) - { - if (val) { - pack(cursor, (unsigned int)val->dwCertEncodingType); - pack(cursor, (unsigned int)val->cbCertEncoded ); - memcpy(cursor, val->pbCertEncoded, val->cbCertEncoded); - cursor += val->cbCertEncoded; - } else { - pack(cursor, (unsigned int)0); - pack(cursor, (unsigned int)0); - } - } - - - inline size_t get_pk_size(const winstd::cert_context &val) - { - return - val ? - get_pk_size((unsigned int)val->dwCertEncodingType) + - get_pk_size((unsigned int)val->cbCertEncoded ) + - val->cbCertEncoded : - get_pk_size((unsigned int)0) + - get_pk_size((unsigned int)0); - } - - - inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ winstd::cert_context &val) - { - DWORD dwCertEncodingType; - unpack(cursor, (unsigned int&)dwCertEncodingType); - - DWORD dwCertEncodedSize; - unpack(cursor, (unsigned int&)dwCertEncodedSize); - - if (dwCertEncodedSize) { - val.create(dwCertEncodingType, (BYTE*)cursor, dwCertEncodedSize); - cursor += dwCertEncodedSize; - } else - val.free(); - } -} diff --git a/lib/EAPBase/src/StdAfx.h b/lib/EAPBase/src/StdAfx.h index 438ad9e..31224be 100644 --- a/lib/EAPBase/src/StdAfx.h +++ b/lib/EAPBase/src/StdAfx.h @@ -26,7 +26,6 @@ #include "../include/Session.h" #include "../include/EAP.h" -#include "../include/EAPSerial.h" #include "../include/EAPXML.h" #include diff --git a/lib/PAP/include/Credentials.h b/lib/PAP/include/Credentials.h index d65ec3a..6cd3ccf 100644 --- a/lib/PAP/include/Credentials.h +++ b/lib/PAP/include/Credentials.h @@ -18,9 +18,6 @@ along with GÉANTLink. If not, see . */ -#include "../../EAPBase/include/EAP.h" - - namespace eap { /// diff --git a/lib/TLS/include/Credentials.h b/lib/TLS/include/Credentials.h index df6abb2..b625675 100644 --- a/lib/TLS/include/Credentials.h +++ b/lib/TLS/include/Credentials.h @@ -31,7 +31,6 @@ namespace eap #pragma once #include "../../EAPBase/include/Credentials.h" -#include "../../EAPBase/include/EAPSerial.h" #include