pack() => operator <<, unpack() => operator >>, get_pk_size() => pksizeof()

This commit is contained in:
2016-07-21 09:20:09 +02:00
parent 51428d290f
commit 627b20aabc
14 changed files with 779 additions and 792 deletions

View File

@@ -45,33 +45,30 @@ namespace eap
class config_providers;
}
namespace eapserial
{
///
/// Packs a configuration
///
/// \param[inout] cursor Memory cursor
/// \param[in] val Configuration to pack
///
inline void pack(_Inout_ cursor_out &cursor, _In_ const eap::config &val);
///
/// Packs a configuration
///
/// \param[inout] cursor Memory cursor
/// \param[in] val Configuration to pack
///
inline void operator<<(_Inout_ eap::cursor_out &cursor, _In_ const eap::config &val);
///
/// Returns packed size of a configuration
///
/// \param[in] val Configuration to pack
///
/// \returns Size of data when packed (in bytes)
///
inline size_t get_pk_size(const eap::config &val);
///
/// Returns packed size of a configuration
///
/// \param[in] val Configuration to pack
///
/// \returns Size of data when packed (in bytes)
///
inline size_t pksizeof(const eap::config &val);
///
/// Unpacks a configuration
///
/// \param[inout] cursor Memory cursor
/// \param[out] val Configuration to unpack to
///
inline void unpack(_Inout_ cursor_in &cursor, _Out_ eap::config &val);
}
///
/// Unpacks a configuration
///
/// \param[inout] cursor Memory cursor
/// \param[out] val Configuration to unpack to
///
inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ eap::config &val);
#pragma once
@@ -181,7 +178,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void pack(_Inout_ eapserial::cursor_out &cursor) const;
virtual void operator<<(_Inout_ cursor_out &cursor) const;
///
/// Returns packed size of a configuration
@@ -195,7 +192,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void unpack(_Inout_ eapserial::cursor_in &cursor);
virtual void operator>>(_Inout_ cursor_in &cursor);
/// @}
@@ -288,7 +285,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void pack(_Inout_ eapserial::cursor_out &cursor) const;
virtual void operator<<(_Inout_ cursor_out &cursor) const;
///
/// Returns packed size of a configuration
@@ -302,7 +299,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void unpack(_Inout_ eapserial::cursor_in &cursor);
virtual void operator>>(_Inout_ cursor_in &cursor);
/// @}
@@ -412,7 +409,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void pack(_Inout_ eapserial::cursor_out &cursor) const;
virtual void operator<<(_Inout_ cursor_out &cursor) const;
///
/// Returns packed size of a configuration
@@ -426,7 +423,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void unpack(_Inout_ eapserial::cursor_in &cursor);
virtual void operator>>(_Inout_ cursor_in &cursor);
/// @}
@@ -531,7 +528,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void pack(_Inout_ eapserial::cursor_out &cursor) const;
virtual void operator<<(_Inout_ cursor_out &cursor) const;
///
/// Returns packed size of a configuration
@@ -545,7 +542,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void unpack(_Inout_ eapserial::cursor_in &cursor);
virtual void operator>>(_Inout_ cursor_in &cursor);
/// @}
@@ -555,22 +552,19 @@ namespace eap
}
namespace eapserial
inline void operator<<(_Inout_ eap::cursor_out &cursor, _In_ const eap::config &val)
{
inline void pack(_Inout_ cursor_out &cursor, _In_ const eap::config &val)
{
val.pack(cursor);
}
inline size_t get_pk_size(const eap::config &val)
{
return val.get_pk_size();
}
inline void unpack(_Inout_ cursor_in &cursor, _Out_ eap::config &val)
{
val.unpack(cursor);
}
val.operator<<(cursor);
}
inline size_t pksizeof(const eap::config &val)
{
return val.get_pk_size();
}
inline void operator>>(_Inout_ eap::cursor_in &cursor, _Out_ eap::config &val)
{
val.operator>>(cursor);
}

View File

@@ -293,7 +293,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void pack(_Inout_ eapserial::cursor_out &cursor) const;
virtual void operator<<(_Inout_ cursor_out &cursor) const;
///
/// Returns packed size of a configuration
@@ -307,7 +307,7 @@ namespace eap
///
/// \param[inout] cursor Memory cursor
///
virtual void unpack(_Inout_ eapserial::cursor_in &cursor);
virtual void operator>>(_Inout_ cursor_in &cursor);
/// @}

File diff suppressed because it is too large Load Diff

View File

@@ -561,13 +561,13 @@ namespace eap
if (!decrypt_md5(cp, pDataIn, dwDataInSize, data, ppEapError))
return false;
eapserial::cursor_in cursor = { data.data(), data.data() + data.size() };
eapserial::unpack(cursor, record);
cursor_in cursor = { data.data(), data.data() + data.size() };
cursor >> record;
#else
UNREFERENCED_PARAMETER(ppEapError);
eapserial::cursor_in cursor = { pDataIn, pDataIn + dwDataInSize };
eapserial::unpack(cursor, record);
cursor_in cursor = { pDataIn, pDataIn + dwDataInSize };
cursor >> record;
#endif
return true;
@@ -596,11 +596,11 @@ namespace eap
#if EAP_ENCRYPT_BLOBS
// Allocate BLOB.
std::vector<unsigned char, winstd::sanitizing_allocator<unsigned char> > data;
data.resize(eapserial::get_pk_size(record));
data.resize(pksizeof(record));
// Pack to BLOB.
eapserial::cursor_out cursor = { data.data(), data.data() + data.size() };
eapserial::pack(cursor, record);
cursor_out cursor = { data.data(), data.data() + data.size() };
cursor << record;
data.resize(cursor.ptr - &data.front());
// Prepare cryptographics provider.
@@ -629,7 +629,7 @@ namespace eap
// Allocate BLOB.
assert(ppDataOut);
assert(pdwDataOutSize);
*pdwDataOutSize = (DWORD)eapserial::get_pk_size(record);
*pdwDataOutSize = (DWORD)pksizeof(record);
*ppDataOut = alloc_memory(*pdwDataOutSize);
if (!*ppDataOut) {
log_error(*ppEapError = g_peer.make_error(ERROR_OUTOFMEMORY, tstring_printf(_T(__FUNCTION__) _T(" Error allocating memory for BLOB (%uB)."), *pdwDataOutSize).c_str()));
@@ -637,8 +637,8 @@ namespace eap
}
// Pack to BLOB.
eapserial::cursor_out cursor = { *ppDataOut, *ppDataOut + *pdwDataOutSize };
eapserial::pack(cursor, record);
cursor_out cursor = { *ppDataOut, *ppDataOut + *pdwDataOutSize };
cursor << record;
*pdwDataOutSize = cursor.ptr - *ppDataOut;
#endif

View File

@@ -81,7 +81,7 @@ bool eap::config::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapErr
}
void eap::config::pack(_Inout_ eapserial::cursor_out &cursor) const
void eap::config::operator<<(_Inout_ cursor_out &cursor) const
{
UNREFERENCED_PARAMETER(cursor);
}
@@ -93,7 +93,7 @@ size_t eap::config::get_pk_size() const
}
void eap::config::unpack(_Inout_ eapserial::cursor_in &cursor)
void eap::config::operator>>(_Inout_ cursor_in &cursor)
{
UNREFERENCED_PARAMETER(cursor);
}
@@ -120,10 +120,10 @@ eap::config_method::config_method(_In_ const config_method &other) :
eap::config_method::config_method(_Inout_ config_method &&other) :
m_allow_save(move(other.m_allow_save)),
m_anonymous_identity(move(other.m_anonymous_identity)),
m_preshared(move(other.m_preshared)),
config(move(other))
m_allow_save(std::move(other.m_allow_save)),
m_anonymous_identity(std::move(other.m_anonymous_identity)),
m_preshared(std::move(other.m_preshared)),
config(std::move(other))
{
}
@@ -144,10 +144,10 @@ eap::config_method& eap::config_method::operator=(_In_ const config_method &othe
eap::config_method& eap::config_method::operator=(_Inout_ config_method &&other)
{
if (this != &other) {
(config&&)*this = move(other);
m_allow_save = move(other.m_allow_save);
m_anonymous_identity = move(other.m_anonymous_identity);
m_preshared = move(other.m_preshared);
(config&&)*this = std::move(other);
m_allow_save = std::move(other.m_allow_save);
m_anonymous_identity = std::move(other.m_anonymous_identity);
m_preshared = std::move(other.m_preshared);
}
return *this;
@@ -222,7 +222,7 @@ bool eap::config_method::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **p
unique_ptr<credentials> preshared(make_credentials());
assert(preshared);
if (preshared->load(pXmlElClientSideCredential, ppEapError)) {
m_preshared = move(preshared);
m_preshared = std::move(preshared);
} else {
// This is not really an error - merely an indication pre-shared credentials are unavailable.
if (*ppEapError) {
@@ -236,44 +236,44 @@ bool eap::config_method::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **p
}
void eap::config_method::pack(_Inout_ eapserial::cursor_out &cursor) const
void eap::config_method::operator<<(_Inout_ cursor_out &cursor) const
{
config::pack(cursor);
eapserial::pack(cursor, m_allow_save );
eapserial::pack(cursor, m_anonymous_identity);
config::operator<<(cursor);
cursor << m_allow_save ;
cursor << m_anonymous_identity;
if (m_preshared) {
eapserial::pack(cursor, true);
m_preshared->pack(cursor);
cursor << true;
cursor << *m_preshared;
} else
eapserial::pack(cursor, false);
cursor << false;
}
size_t eap::config_method::get_pk_size() const
{
return
config::get_pk_size() +
eapserial::get_pk_size(m_allow_save ) +
eapserial::get_pk_size(m_anonymous_identity) +
config::get_pk_size() +
pksizeof(m_allow_save ) +
pksizeof(m_anonymous_identity) +
(m_preshared ?
eapserial::get_pk_size(true) +
m_preshared->get_pk_size() :
eapserial::get_pk_size(false));
pksizeof(true ) +
pksizeof(*m_preshared) :
pksizeof(false ));
}
void eap::config_method::unpack(_Inout_ eapserial::cursor_in &cursor)
void eap::config_method::operator>>(_Inout_ cursor_in &cursor)
{
config::unpack(cursor);
eapserial::unpack(cursor, m_allow_save );
eapserial::unpack(cursor, m_anonymous_identity);
config::operator>>(cursor);
cursor >> m_allow_save ;
cursor >> m_anonymous_identity;
bool use_preshared;
eapserial::unpack(cursor, use_preshared);
cursor >> use_preshared;
if (use_preshared) {
m_preshared.reset(make_credentials());
assert(m_preshared);
m_preshared->unpack(cursor);
cursor >> *m_preshared;
} else
m_preshared.reset(nullptr);
}
@@ -303,22 +303,22 @@ eap::config_provider::config_provider(_In_ const config_provider &other) :
config(other)
{
for (list<unique_ptr<config_method> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
m_methods.push_back(move(unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
m_methods.push_back(std::move(unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
}
eap::config_provider::config_provider(_Inout_ config_provider &&other) :
m_read_only(move(other.m_read_only)),
m_id(move(other.m_id)),
m_name(move(other.m_name)),
m_help_email(move(other.m_help_email)),
m_help_web(move(other.m_help_web)),
m_help_phone(move(other.m_help_phone)),
m_lbl_alt_credential(move(other.m_lbl_alt_credential)),
m_lbl_alt_identity(move(other.m_lbl_alt_identity)),
m_lbl_alt_password(move(other.m_lbl_alt_password)),
m_methods(move(other.m_methods)),
config(move(other))
m_read_only(std::move(other.m_read_only)),
m_id(std::move(other.m_id)),
m_name(std::move(other.m_name)),
m_help_email(std::move(other.m_help_email)),
m_help_web(std::move(other.m_help_web)),
m_help_phone(std::move(other.m_help_phone)),
m_lbl_alt_credential(std::move(other.m_lbl_alt_credential)),
m_lbl_alt_identity(std::move(other.m_lbl_alt_identity)),
m_lbl_alt_password(std::move(other.m_lbl_alt_password)),
m_methods(std::move(other.m_methods)),
config(std::move(other))
{
}
@@ -339,7 +339,7 @@ eap::config_provider& eap::config_provider::operator=(_In_ const config_provider
m_methods.clear();
for (list<unique_ptr<config_method> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
m_methods.push_back(move(unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
m_methods.push_back(std::move(unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
}
return *this;
@@ -349,17 +349,17 @@ eap::config_provider& eap::config_provider::operator=(_In_ const config_provider
eap::config_provider& eap::config_provider::operator=(_Inout_ config_provider &&other)
{
if (this != &other) {
(config&&)*this = move(other);
m_read_only = move(m_read_only);
m_id = move(other.m_id);
m_name = move(other.m_name);
m_help_email = move(other.m_help_email);
m_help_web = move(other.m_help_web);
m_help_phone = move(other.m_help_phone);
m_lbl_alt_credential = move(other.m_lbl_alt_credential);
m_lbl_alt_identity = move(other.m_lbl_alt_identity);
m_lbl_alt_password = move(other.m_lbl_alt_password);
m_methods = move(other.m_methods);
(config&&)*this = std::move(other);
m_read_only = std::move(m_read_only);
m_id = std::move(other.m_id);
m_name = std::move(other.m_name);
m_help_email = std::move(other.m_help_email);
m_help_web = std::move(other.m_help_web);
m_help_phone = std::move(other.m_help_phone);
m_lbl_alt_credential = std::move(other.m_lbl_alt_credential);
m_lbl_alt_identity = std::move(other.m_lbl_alt_identity);
m_lbl_alt_password = std::move(other.m_lbl_alt_password);
m_methods = std::move(other.m_methods);
}
return *this;
@@ -583,69 +583,69 @@ bool eap::config_provider::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR *
return false;
// Add configuration to the list.
m_methods.push_back(move(cfg));
m_methods.push_back(std::move(cfg));
}
return true;
}
void eap::config_provider::pack(_Inout_ eapserial::cursor_out &cursor) const
void eap::config_provider::operator<<(_Inout_ cursor_out &cursor) const
{
config::pack(cursor);
eapserial::pack(cursor, m_read_only );
eapserial::pack(cursor, m_id );
eapserial::pack(cursor, m_name );
eapserial::pack(cursor, m_help_email );
eapserial::pack(cursor, m_help_web );
eapserial::pack(cursor, m_help_phone );
eapserial::pack(cursor, m_lbl_alt_credential);
eapserial::pack(cursor, m_lbl_alt_identity );
eapserial::pack(cursor, m_lbl_alt_password );
eapserial::pack(cursor, m_methods );
config::operator<<(cursor);
cursor << m_read_only ;
cursor << m_id ;
cursor << m_name ;
cursor << m_help_email ;
cursor << m_help_web ;
cursor << m_help_phone ;
cursor << m_lbl_alt_credential;
cursor << m_lbl_alt_identity ;
cursor << m_lbl_alt_password ;
cursor << m_methods ;
}
size_t eap::config_provider::get_pk_size() const
{
return
config::get_pk_size() +
eapserial::get_pk_size(m_read_only ) +
eapserial::get_pk_size(m_id ) +
eapserial::get_pk_size(m_name ) +
eapserial::get_pk_size(m_help_email ) +
eapserial::get_pk_size(m_help_web ) +
eapserial::get_pk_size(m_help_phone ) +
eapserial::get_pk_size(m_lbl_alt_credential) +
eapserial::get_pk_size(m_lbl_alt_identity ) +
eapserial::get_pk_size(m_lbl_alt_password ) +
eapserial::get_pk_size(m_methods );
config::get_pk_size() +
pksizeof(m_read_only ) +
pksizeof(m_id ) +
pksizeof(m_name ) +
pksizeof(m_help_email ) +
pksizeof(m_help_web ) +
pksizeof(m_help_phone ) +
pksizeof(m_lbl_alt_credential) +
pksizeof(m_lbl_alt_identity ) +
pksizeof(m_lbl_alt_password ) +
pksizeof(m_methods );
}
void eap::config_provider::unpack(_Inout_ eapserial::cursor_in &cursor)
void eap::config_provider::operator>>(_Inout_ cursor_in &cursor)
{
config::unpack(cursor);
eapserial::unpack(cursor, m_read_only );
eapserial::unpack(cursor, m_id );
eapserial::unpack(cursor, m_name );
eapserial::unpack(cursor, m_help_email );
eapserial::unpack(cursor, m_help_web );
eapserial::unpack(cursor, m_help_phone );
eapserial::unpack(cursor, m_lbl_alt_credential);
eapserial::unpack(cursor, m_lbl_alt_identity );
eapserial::unpack(cursor, m_lbl_alt_password );
config::operator>>(cursor);
cursor >> m_read_only ;
cursor >> m_id ;
cursor >> m_name ;
cursor >> m_help_email ;
cursor >> m_help_web ;
cursor >> m_help_phone ;
cursor >> m_lbl_alt_credential;
cursor >> m_lbl_alt_identity ;
cursor >> m_lbl_alt_password ;
list<config_method>::size_type count;
bool is_nonnull;
eapserial::unpack(cursor, count);
cursor >> count;
m_methods.clear();
for (list<config_method>::size_type i = 0; i < count; i++) {
eapserial::unpack(cursor, is_nonnull);
cursor >> is_nonnull;
if (is_nonnull) {
unique_ptr<config_method> el(m_module.make_config_method());
el->unpack(cursor);
m_methods.push_back(move(el));
cursor >> *el;
m_methods.push_back(std::move(el));
} else
m_methods.push_back(nullptr);
}
@@ -669,8 +669,8 @@ eap::config_providers::config_providers(_In_ const config_providers &other) :
eap::config_providers::config_providers(_Inout_ config_providers &&other) :
m_providers(move(other.m_providers)),
config(move(other))
m_providers(std::move(other.m_providers)),
config(std::move(other))
{
}
@@ -689,8 +689,8 @@ eap::config_providers& eap::config_providers::operator=(_In_ const config_provid
eap::config_providers& eap::config_providers::operator=(_Inout_ config_providers &&other)
{
if (this != &other) {
(config&&)*this = move(other);
m_providers = move(other.m_providers);
(config&&)*this = std::move(other);
m_providers = std::move(other.m_providers);
}
return *this;
@@ -769,17 +769,17 @@ bool eap::config_providers::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR
return false;
// Add provider to the list.
m_providers.push_back(move(prov));
m_providers.push_back(std::move(prov));
}
return true;
}
void eap::config_providers::pack(_Inout_ eapserial::cursor_out &cursor) const
void eap::config_providers::operator<<(_Inout_ cursor_out &cursor) const
{
config::pack(cursor);
eapserial::pack(cursor, m_providers);
config::operator<<(cursor);
cursor << m_providers;
}
@@ -787,20 +787,20 @@ size_t eap::config_providers::get_pk_size() const
{
return
config::get_pk_size() +
eapserial::get_pk_size(m_providers);
pksizeof(m_providers);
}
void eap::config_providers::unpack(_Inout_ eapserial::cursor_in &cursor)
void eap::config_providers::operator>>(_Inout_ cursor_in &cursor)
{
config::unpack(cursor);
config::operator>>(cursor);
list<config_provider>::size_type count;
eapserial::unpack(cursor, count);
cursor >> count;
m_providers.clear();
for (list<config_provider>::size_type i = 0; i < count; i++) {
config_provider el(m_module);
el.unpack(cursor);
m_providers.push_back(move(el));
cursor >> el;
m_providers.push_back(std::move(el));
}
}

View File

@@ -233,28 +233,28 @@ bool eap::credentials_pass::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR
}
void eap::credentials_pass::pack(_Inout_ eapserial::cursor_out &cursor) const
void eap::credentials_pass::operator<<(_Inout_ cursor_out &cursor) const
{
eap::credentials::pack(cursor);
eapserial::pack(cursor, m_identity);
eapserial::pack(cursor, m_password);
credentials::operator<<(cursor);
cursor << m_identity;
cursor << m_password;
}
size_t eap::credentials_pass::get_pk_size() const
{
return
eap::credentials::get_pk_size() +
eapserial::get_pk_size(m_identity) +
eapserial::get_pk_size(m_password);
credentials::get_pk_size() +
pksizeof(m_identity) +
pksizeof(m_password);
}
void eap::credentials_pass::unpack(_Inout_ eapserial::cursor_in &cursor)
void eap::credentials_pass::operator>>(_Inout_ cursor_in &cursor)
{
eap::credentials::unpack(cursor);
eapserial::unpack(cursor, m_identity);
eapserial::unpack(cursor, m_password);
credentials::operator>>(cursor);
cursor >> m_identity;
cursor >> m_password;
}