diff options
Diffstat (limited to 'src/security')
-rw-r--r-- | src/security/cert/gnutls/X509Certificate_GnuTLS.cpp | 6 | ||||
-rw-r--r-- | src/security/cert/openssl/X509Certificate_OpenSSL.cpp | 14 | ||||
-rw-r--r-- | src/security/digest/md5/md5MessageDigest.cpp | 19 | ||||
-rw-r--r-- | src/security/digest/messageDigest.cpp | 4 | ||||
-rw-r--r-- | src/security/digest/sha1/sha1MessageDigest.cpp | 10 | ||||
-rw-r--r-- | src/security/sasl/SASLContext.cpp | 4 | ||||
-rw-r--r-- | src/security/sasl/SASLSession.cpp | 4 | ||||
-rw-r--r-- | src/security/sasl/SASLSocket.cpp | 50 | ||||
-rw-r--r-- | src/security/sasl/builtinSASLMechanism.cpp | 12 |
9 files changed, 63 insertions, 60 deletions
diff --git a/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp b/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp index 327ddefa..f96ddddb 100644 --- a/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp +++ b/src/security/cert/gnutls/X509Certificate_GnuTLS.cpp @@ -92,11 +92,11 @@ void* X509Certificate_GnuTLS::getInternalData() shared_ptr <X509Certificate> X509Certificate::import(utility::inputStream& is) { byteArray bytes; - utility::stream::value_type chunk[4096]; + byte_t chunk[4096]; while (!is.eof()) { - const utility::stream::size_type len = is.read(chunk, sizeof(chunk)); + const size_t len = is.read(chunk, sizeof(chunk)); bytes.insert(bytes.end(), chunk, chunk + len); } @@ -146,7 +146,7 @@ void X509Certificate_GnuTLS::write gnutls_x509_crt_export(m_data->cert, fmt, &data[0], &dataSize); - os.write(reinterpret_cast <utility::stream::value_type*>(&data[0]), dataSize); + os.write(reinterpret_cast <byte_t*>(&data[0]), dataSize); } diff --git a/src/security/cert/openssl/X509Certificate_OpenSSL.cpp b/src/security/cert/openssl/X509Certificate_OpenSSL.cpp index 8c7174a0..5f81b2bf 100644 --- a/src/security/cert/openssl/X509Certificate_OpenSSL.cpp +++ b/src/security/cert/openssl/X509Certificate_OpenSSL.cpp @@ -171,11 +171,11 @@ shared_ptr <X509Certificate> X509Certificate_OpenSSL::importInternal(X509* cert) shared_ptr <X509Certificate> X509Certificate::import(utility::inputStream& is) { byteArray bytes; - utility::stream::value_type chunk[4096]; + byte_t chunk[4096]; while (!is.eof()) { - const int len = is.read(chunk, sizeof(chunk)); + const size_t len = is.read(chunk, sizeof(chunk)); bytes.insert(bytes.end(), chunk, chunk + len); } @@ -189,7 +189,7 @@ shared_ptr <X509Certificate> X509Certificate::import { shared_ptr <X509Certificate_OpenSSL> cert = make_shared <X509Certificate_OpenSSL>(); - BIO* membio = BIO_new_mem_buf(const_cast <byte_t*>(data), length); + BIO* membio = BIO_new_mem_buf(const_cast <byte_t*>(data), static_cast <int>(length)); if (!PEM_read_bio_X509(membio, &(cert->m_data->cert), 0, 0)) { @@ -207,7 +207,7 @@ void X509Certificate_OpenSSL::write (utility::outputStream& os, const Format format) const { BIO* membio = 0; - int dataSize = 0; + long dataSize = 0; unsigned char* out = 0; if (format == FORMAT_DER) @@ -215,7 +215,7 @@ void X509Certificate_OpenSSL::write if ((dataSize = i2d_X509(m_data->cert, &out)) < 0) goto err; - os.write(reinterpret_cast <utility::stream::value_type*>(out), dataSize); + os.write(reinterpret_cast <byte_t*>(out), dataSize); os.flush(); OPENSSL_free(out); } @@ -228,7 +228,7 @@ void X509Certificate_OpenSSL::write goto pem_err; dataSize = BIO_get_mem_data(membio, &out); - os.write(reinterpret_cast <utility::stream::value_type*>(out), dataSize); + os.write(reinterpret_cast <byte_t*>(out), dataSize); os.flush(); BIO_vfree(membio); } @@ -281,7 +281,7 @@ bool X509Certificate_OpenSSL::checkIssuer(shared_ptr <const X509Certificate> cer out = BIO_new(BIO_s_mem()); X509_NAME_print_ex(out, X509_get_issuer_name(m_data->cert), 0, XN_FLAG_RFC2253); - int n = BIO_get_mem_data(out, &issuer); + long n = BIO_get_mem_data(out, &issuer); vmime::string thisIssuerName((char*)issuer, n); BIO_free(out); diff --git a/src/security/digest/md5/md5MessageDigest.cpp b/src/security/digest/md5/md5MessageDigest.cpp index 88f9c9de..a83f0623 100644 --- a/src/security/digest/md5/md5MessageDigest.cpp +++ b/src/security/digest/md5/md5MessageDigest.cpp @@ -83,7 +83,7 @@ void md5MessageDigest::init() } -static void copyUint8Array(vmime_uint8* dest, const vmime_uint8* src, unsigned long count) +static void copyUint8Array(vmime_uint8* dest, const vmime_uint8* src, size_t count) { for ( ; count >= 4 ; count -= 4, dest += 4, src += 4) { @@ -104,7 +104,7 @@ static inline vmime_uint32 swapUint32(const vmime_uint32 D) } -static inline void swapUint32Array(vmime_uint32* buf, unsigned long words) +static inline void swapUint32Array(vmime_uint32* buf, size_t words) { for ( ; words >= 4 ; words -= 4, buf += 4) { @@ -131,17 +131,16 @@ void md5MessageDigest::update(const string& s) } -void md5MessageDigest::update(const byte_t* data, const unsigned long offset, - const unsigned long len) +void md5MessageDigest::update(const byte_t* data, const size_t offset, const size_t len) { update(data + offset, len); } -void md5MessageDigest::update(const byte_t* data, const unsigned long length) +void md5MessageDigest::update(const byte_t* data, const size_t length) { - const unsigned long avail = 64 - (m_byteCount & 0x3f); - unsigned long len = length; + const size_t avail = 64 - (m_byteCount & 0x3f); + size_t len = length; m_byteCount += len; @@ -177,7 +176,7 @@ void md5MessageDigest::finalize(const string& s) } -void md5MessageDigest::finalize(const byte_t* buffer, const unsigned long len) +void md5MessageDigest::finalize(const byte_t* buffer, const size_t len) { update(buffer, len); finalize(); @@ -185,7 +184,7 @@ void md5MessageDigest::finalize(const byte_t* buffer, const unsigned long len) void md5MessageDigest::finalize(const byte_t* buffer, - const unsigned long offset, const unsigned long len) + const size_t offset, const size_t len) { update(buffer, offset, len); finalize(); @@ -329,7 +328,7 @@ void md5MessageDigest::transform() } -int md5MessageDigest::getDigestLength() const +size_t md5MessageDigest::getDigestLength() const { return 16; } diff --git a/src/security/digest/messageDigest.cpp b/src/security/digest/messageDigest.cpp index 2cc11617..18fc8628 100644 --- a/src/security/digest/messageDigest.cpp +++ b/src/security/digest/messageDigest.cpp @@ -34,14 +34,14 @@ namespace digest { const string messageDigest::getHexDigest() const { const byte_t* hash = getDigest(); - const int len = getDigestLength(); + const size_t len = getDigestLength(); static const unsigned char hex[] = "0123456789abcdef"; std::ostringstream oss; oss.imbue(std::locale::classic()); - for (int i = 0 ; i < len ; ++i) + for (size_t i = 0 ; i < len ; ++i) { oss << hex[(hash[i] & 0xf0) >> 4]; oss << hex[(hash[i] & 0x0f)]; diff --git a/src/security/digest/sha1/sha1MessageDigest.cpp b/src/security/digest/sha1/sha1MessageDigest.cpp index e022eb8a..aa055af5 100644 --- a/src/security/digest/sha1/sha1MessageDigest.cpp +++ b/src/security/digest/sha1/sha1MessageDigest.cpp @@ -95,14 +95,14 @@ void sha1MessageDigest::update(const string& s) } -void sha1MessageDigest::update(const byte_t* buffer, const unsigned long offset, +void sha1MessageDigest::update(const byte_t* buffer, const size_t offset, const unsigned long len) { update(buffer + offset, len); } -void sha1MessageDigest::update(const byte_t* buffer, const unsigned long len) +void sha1MessageDigest::update(const byte_t* buffer, const size_t len) { unsigned int i, j; @@ -174,7 +174,7 @@ void sha1MessageDigest::finalize(const string& s) } -void sha1MessageDigest::finalize(const byte_t* buffer, const unsigned long len) +void sha1MessageDigest::finalize(const byte_t* buffer, const size_t len) { update(buffer, len); finalize(); @@ -182,7 +182,7 @@ void sha1MessageDigest::finalize(const byte_t* buffer, const unsigned long len) void sha1MessageDigest::finalize(const byte_t* buffer, - const unsigned long offset, const unsigned long len) + const size_t offset, const size_t len) { finalize(buffer + offset, len); } @@ -251,7 +251,7 @@ void sha1MessageDigest::transform } -int sha1MessageDigest::getDigestLength() const +size_t sha1MessageDigest::getDigestLength() const { return 20; } diff --git a/src/security/sasl/SASLContext.cpp b/src/security/sasl/SASLContext.cpp index c4d60bd9..3474cbeb 100644 --- a/src/security/sasl/SASLContext.cpp +++ b/src/security/sasl/SASLContext.cpp @@ -106,7 +106,7 @@ shared_ptr <SASLMechanism> SASLContext::suggestMechanism } -void SASLContext::decodeB64(const string& input, byte_t** output, long* outputLen) +void SASLContext::decodeB64(const string& input, byte_t** output, size_t* outputLen) { string res; @@ -127,7 +127,7 @@ void SASLContext::decodeB64(const string& input, byte_t** output, long* outputLe } -const string SASLContext::encodeB64(const byte_t* input, const long inputLen) +const string SASLContext::encodeB64(const byte_t* input, const size_t inputLen) { string res; diff --git a/src/security/sasl/SASLSession.cpp b/src/security/sasl/SASLSession.cpp index 1bdd0889..087ef27b 100644 --- a/src/security/sasl/SASLSession.cpp +++ b/src/security/sasl/SASLSession.cpp @@ -99,8 +99,8 @@ shared_ptr <SASLContext> SASLSession::getContext() bool SASLSession::evaluateChallenge - (const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen) + (const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen) { return m_mech->step(dynamicCast <SASLSession>(shared_from_this()), challenge, challengeLen, response, responseLen); diff --git a/src/security/sasl/SASLSocket.cpp b/src/security/sasl/SASLSocket.cpp index 37e297dc..12d634c2 100644 --- a/src/security/sasl/SASLSocket.cpp +++ b/src/security/sasl/SASLSocket.cpp @@ -30,9 +30,12 @@ #include "vmime/security/sasl/SASLSocket.hpp" #include "vmime/security/sasl/SASLSession.hpp" +#include "vmime/utility/stringUtils.hpp" + #include "vmime/exception.hpp" #include <algorithm> +#include <cstring> #include <gsasl.h> @@ -75,7 +78,7 @@ bool SASLSocket::isConnected() const } -SASLSocket::size_type SASLSocket::getBlockSize() const +size_t SASLSocket::getBlockSize() const { return m_wrapped->getBlockSize(); } @@ -95,17 +98,17 @@ const string SASLSocket::getPeerAddress() const void SASLSocket::receive(string& buffer) { - const size_type n = receiveRaw(m_recvBuffer, sizeof(m_recvBuffer)); + const size_t n = receiveRaw(m_recvBuffer, sizeof(m_recvBuffer)); - buffer = string(m_recvBuffer, n); + buffer = utility::stringUtils::makeStringFromBytes(m_recvBuffer, n); } -SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count) +size_t SASLSocket::receiveRaw(byte_t* buffer, const size_t count) { if (m_pendingLen != 0) { - const size_type copyLen = + const size_t copyLen = (count >= m_pendingLen ? m_pendingLen : count); std::copy(m_pendingBuffer + m_pendingPos, @@ -127,14 +130,13 @@ SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count return copyLen; } - const size_type n = m_wrapped->receiveRaw(buffer, count); + const size_t n = m_wrapped->receiveRaw(buffer, count); byte_t* output = 0; - long outputLen = 0; + size_t outputLen = 0; m_session->getMechanism()->decode - (m_session, reinterpret_cast <const byte_t*>(buffer), n, - &output, &outputLen); + (m_session, buffer, n, &output, &outputLen); // If we can not copy all decoded data into the output buffer, put // remaining data into a pending buffer for next calls to receive() @@ -161,23 +163,27 @@ SASLSocket::size_type SASLSocket::receiveRaw(char* buffer, const size_type count void SASLSocket::send(const string& buffer) { - sendRaw(buffer.data(), buffer.length()); + sendRaw(reinterpret_cast <const byte_t*>(buffer.data()), buffer.length()); +} + + +void SASLSocket::send(const char* str) +{ + sendRaw(reinterpret_cast <const byte_t*>(str), strlen(str)); } -void SASLSocket::sendRaw(const char* buffer, const size_type count) +void SASLSocket::sendRaw(const byte_t* buffer, const size_t count) { byte_t* output = 0; - long outputLen = 0; + size_t outputLen = 0; m_session->getMechanism()->encode - (m_session, reinterpret_cast <const byte_t*>(buffer), count, - &output, &outputLen); + (m_session, buffer, count, &output, &outputLen); try { - m_wrapped->sendRaw - (reinterpret_cast <const char*>(output), outputLen); + m_wrapped->sendRaw(output, outputLen); } catch (...) { @@ -189,21 +195,19 @@ void SASLSocket::sendRaw(const char* buffer, const size_type count) } -SASLSocket::size_type SASLSocket::sendRawNonBlocking(const char* buffer, const size_type count) +size_t SASLSocket::sendRawNonBlocking(const byte_t* buffer, const size_t count) { byte_t* output = 0; - long outputLen = 0; + size_t outputLen = 0; m_session->getMechanism()->encode - (m_session, reinterpret_cast <const byte_t*>(buffer), count, - &output, &outputLen); + (m_session, buffer, count, &output, &outputLen); - size_type bytesSent = 0; + size_t bytesSent = 0; try { - bytesSent = m_wrapped->sendRawNonBlocking - (reinterpret_cast <const char*>(output), outputLen); + bytesSent = m_wrapped->sendRawNonBlocking(output, outputLen); } catch (...) { diff --git a/src/security/sasl/builtinSASLMechanism.cpp b/src/security/sasl/builtinSASLMechanism.cpp index e7bd723e..e179e715 100644 --- a/src/security/sasl/builtinSASLMechanism.cpp +++ b/src/security/sasl/builtinSASLMechanism.cpp @@ -63,8 +63,8 @@ const string builtinSASLMechanism::getName() const bool builtinSASLMechanism::step - (shared_ptr <SASLSession> sess, const byte_t* challenge, const long challengeLen, - byte_t** response, long* responseLen) + (shared_ptr <SASLSession> sess, const byte_t* challenge, const size_t challengeLen, + byte_t** response, size_t* responseLen) { char* output = 0; size_t outputLen = 0; @@ -121,8 +121,8 @@ bool builtinSASLMechanism::isComplete() const void builtinSASLMechanism::encode - (shared_ptr <SASLSession> sess, const byte_t* input, const long inputLen, - byte_t** output, long* outputLen) + (shared_ptr <SASLSession> sess, const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen) { char* coutput = 0; size_t coutputLen = 0; @@ -154,8 +154,8 @@ void builtinSASLMechanism::encode void builtinSASLMechanism::decode - (shared_ptr <SASLSession> sess, const byte_t* input, const long inputLen, - byte_t** output, long* outputLen) + (shared_ptr <SASLSession> sess, const byte_t* input, const size_t inputLen, + byte_t** output, size_t* outputLen) { char* coutput = 0; size_t coutputLen = 0; |