From 4aa40d4f514a0a76cf7756c4d4daa817968b42e0 Mon Sep 17 00:00:00 2001
From: Paul Bakker
Date: Fri, 11 Oct 2013 10:49:24 +0200
Subject: [PATCH] Better support for MSVC
---
ChangeLog | 1 +
include/polarssl/compat-1.2.h | 19 ++++++++++++-------
library/x509_crt.c | 5 ++---
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8e3b0a9cb..81bafe9a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,7 @@ Bugfix
* Header files with 'polarssl/'
* Const correctness
* Possible naming collision in dhm_context
+ * Better support for MSVC
= PolarSSL-1.3.0 released on 2013-10-01
Features
diff --git a/include/polarssl/compat-1.2.h b/include/polarssl/compat-1.2.h
index b60c93292..ce4566cf0 100644
--- a/include/polarssl/compat-1.2.h
+++ b/include/polarssl/compat-1.2.h
@@ -32,6 +32,11 @@
// Comment out to disable prototype change warnings
#define SHOW_PROTOTYPE_CHANGE_WARNINGS
+#if defined _MSC_VER
+// MSVC does not support #warning
+#undef SHOW_PROTOTYPE_CHANGE_WARNINGS
+#endif
+
#if defined(SHOW_PROTOTYPE_CHANGE_WARNINGS)
#warning "You can disable these warnings by commenting SHOW_PROTOTYPE_CHANGE_WARNINGS in compat-1.2.h"
#endif
@@ -53,14 +58,14 @@ inline void sha2_update( sha256_context *ctx, const unsigned char *input,
sha256_update( ctx, input, ilen );
}
inline void sha2_finish( sha256_context *ctx, unsigned char output[32] ) {
- return sha256_finish( ctx, output );
+ sha256_finish( ctx, output );
}
inline int sha2_file( const char *path, unsigned char output[32], int is224 ) {
return sha256_file( path, output, is224 );
}
inline void sha2( const unsigned char *input, size_t ilen,
unsigned char output[32], int is224 ) {
- return sha256( input, ilen, output, is224 );
+ sha256( input, ilen, output, is224 );
}
inline void sha2_hmac_starts( sha256_context *ctx, const unsigned char *key,
size_t keylen, int is224 ) {
@@ -102,14 +107,14 @@ inline void sha4_update( sha512_context *ctx, const unsigned char *input,
sha512_update( ctx, input, ilen );
}
inline void sha4_finish( sha512_context *ctx, unsigned char output[64] ) {
- return sha512_finish( ctx, output );
+ sha512_finish( ctx, output );
}
inline int sha4_file( const char *path, unsigned char output[64], int is384 ) {
return sha512_file( path, output, is384 );
}
inline void sha4( const unsigned char *input, size_t ilen,
unsigned char output[32], int is384 ) {
- return sha512( input, ilen, output, is384 );
+ sha512( input, ilen, output, is384 );
}
inline void sha4_hmac_starts( sha512_context *ctx, const unsigned char *key,
size_t keylen, int is384 ) {
@@ -232,7 +237,7 @@ inline int x509parse_revoked( const x509_cert *crt, const x509_crl *crl ) {
return x509_crt_revoked( crt, crl );
}
inline void x509_free( x509_cert *crt ) {
- return x509_crt_free( crt );
+ x509_crt_free( crt );
}
#endif /* POLARSSL_X509_CRT_PARSE_C */
@@ -354,7 +359,7 @@ inline int x509_write_pubkey_der( unsigned char *buf, size_t len, rsa_context *r
int ret;
pk_context ctx;
if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret );
- if( ( ret = rsa_copy( ctx.pk_ctx, rsa ) ) != 0 ) return( ret );
+ if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret );
ret = pk_write_pubkey_der( &ctx, buf, len );
pk_free( &ctx );
return( ret );
@@ -363,7 +368,7 @@ inline int x509_write_key_der( unsigned char *buf, size_t len, rsa_context *rsa
int ret;
pk_context ctx;
if( ( ret = pk_init_ctx( &ctx, pk_info_from_type( POLARSSL_PK_RSA ) ) ) != 0 ) return( ret );
- if( ( ret = rsa_copy( ctx.pk_ctx, rsa ) ) != 0 ) return( ret );
+ if( ( ret = rsa_copy( pk_rsa( ctx ), rsa ) ) != 0 ) return( ret );
ret = pk_write_key_der( &ctx, buf, len );
pk_free( &ctx );
return( ret );
diff --git a/library/x509_crt.c b/library/x509_crt.c
index e6c840c9b..91d46264f 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -958,7 +958,7 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
w_ret = MultiByteToWideChar( CP_ACP, 0, path, len, szDir, MAX_PATH - 3 );
hFind = FindFirstFileW( szDir, &file_data );
- if (hFind == INVALID_HANDLE_VALUE)
+ if (hFind == INVALID_HANDLE_VALUE)
return( POLARSSL_ERR_X509_FILE_IO_ERROR );
len = MAX_PATH - len;
@@ -982,10 +982,9 @@ int x509_crt_parse_path( x509_crt *chain, const char *path )
}
while( FindNextFileW( hFind, &file_data ) != 0 );
- if (GetLastError() != ERROR_NO_MORE_FILES)
+ if (GetLastError() != ERROR_NO_MORE_FILES)
ret = POLARSSL_ERR_X509_FILE_IO_ERROR;
-cleanup:
FindClose( hFind );
#else
int t_ret, i;