- Added runtime and compiletime version information

This commit is contained in:
Paul Bakker 2010-06-18 22:47:29 +00:00
parent 690b93d91a
commit 3ac1b2d952
9 changed files with 199 additions and 2 deletions

View file

@ -76,6 +76,11 @@
*/
#define POLARSSL_SELF_TEST
/*
* Enable run-time version information functions
*/
#define POLARSSL_VERSION_C
/*
* Enable the prime-number generation code.
*/

View file

@ -0,0 +1,74 @@
/**
* \file version.h
*
* Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
* All rights reserved.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* This set of compile-time defines and run-time variables can be used to
* determine the version number of the PolarSSL library used.
*/
#ifndef POLARSSL_VERSION_H
#define POLARSSL_VERSION_H
#include "polarssl/config.h"
/**
* The version number x.y.z is split into three parts.
* Major, Minor, Patchlevel
*/
#define POLARSSL_VERSION_MAJOR 0
#define POLARSSL_VERSION_MINOR 13
#define POLARSSL_VERSION_PATCH 1
/**
* The single version number has the following structure:
* MMNNPP00
* Major version | Minor version | Patch version
*/
#define POLARSSL_VERSION_NUMBER 0x000D0100
#define POLARSSL_VERSION_STRING "0.13.1"
#define POLARSSL_VERSION_STRING_FULL "PolarSSL 0.13.1"
#if defined(POLARSSL_VERSION_C)
/**
* Get the version number.
*
* @return The constructed version number in the format
* MMNNPP00 (Major, Minor, Patch).
*/
unsigned int version_get_number();
/**
* Get the version string ("x.y.z").
*
* @param string The string that will receive the value.
* (Should be at least 9 bytes in size)
*/
void version_get_string( char *string );
/**
* Get the full version string ("PolarSSL x.y.z").
*
* @param string The string that will receive the value.
* (Should be at least 18 bytes in size)
*/
void version_get_string_full( char *string );
#endif /* POLARSSL_VERSION_C */
#endif /* version.h */

View file

@ -22,6 +22,7 @@ add_library(polarssl STATIC
ssl_srv.c
ssl_tls.c
timing.c
version.c
x509parse.c
xtea.c
)

View file

@ -25,7 +25,7 @@ OBJS= aes.o arc4.o base64.o \
sha1.o sha2.o sha4.o \
ssl_cli.o ssl_srv.o ssl_tls.o \
timing.o x509parse.o xtea.o \
camellia.o
camellia.o version.o
.SILENT:

46
library/version.c Normal file
View file

@ -0,0 +1,46 @@
/*
* Version information
*
* Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
* All rights reserved.
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "polarssl/config.h"
#if defined(POLARSSL_VERSION_C)
#include "polarssl/version.h"
#include <string.h>
const char version[] = POLARSSL_VERSION_STRING;
unsigned int version_get_number()
{
return POLARSSL_VERSION_NUMBER;
}
void version_get_string( char *string )
{
memcpy( string, POLARSSL_VERSION_STRING, sizeof( POLARSSL_VERSION_STRING ) );
}
void version_get_string_full( char *string )
{
memcpy( string, POLARSSL_VERSION_STRING_FULL, sizeof( POLARSSL_VERSION_STRING_FULL ) );
}
#endif /* POLARSSL_VERSION_C */

View file

@ -26,3 +26,4 @@ add_test_suite(xtea)
add_test_suite(dhm)
add_test_suite(x509parse)
add_test_suite(debug)
add_test_suite(version)

View file

@ -14,7 +14,8 @@ APPS = test_suite_aes test_suite_arc4 \
test_suite_hmac_shax test_suite_mdx \
test_suite_mpi test_suite_rsa \
test_suite_shax test_suite_x509parse\
test_suite_xtea test_suite_debug
test_suite_xtea test_suite_debug \
test_suite_version
.SILENT:
@ -80,6 +81,10 @@ test_suite_debug: test_suite_debug.c ../library/libpolarssl.a
echo " CC $@.c"
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
test_suite_version: test_suite_version.c ../library/libpolarssl.a
echo " CC $@.c"
$(CC) $(CFLAGS) $(OFLAGS) $@.c $(LDFLAGS) -o $@
clean:
rm -f $(APPS) *.c

View file

@ -0,0 +1,5 @@
Check compiletime library version
check_compiletime_version:"0.13.1"
Check runtime library version
check_runtime_version:"0.13.1"

View file

@ -0,0 +1,60 @@
BEGIN_HEADER
#include <polarssl/version.h>
END_HEADER
BEGIN_CASE
check_compiletime_version:version_str
{
char build_str[100];
char build_str_full[100];
unsigned int build_int;
memset( build_str, 0, 100 );
memset( build_str_full, 0, 100 );
snprintf (build_str, 100, "%d.%d.%d", POLARSSL_VERSION_MAJOR,
POLARSSL_VERSION_MINOR, POLARSSL_VERSION_PATCH );
snprintf( build_str_full, 100, "PolarSSL %d.%d.%d", POLARSSL_VERSION_MAJOR,
POLARSSL_VERSION_MINOR, POLARSSL_VERSION_PATCH );
build_int = POLARSSL_VERSION_MAJOR << 24 |
POLARSSL_VERSION_MINOR << 16 |
POLARSSL_VERSION_PATCH << 8;
TEST_ASSERT( build_int == POLARSSL_VERSION_NUMBER );
TEST_ASSERT( strcmp( build_str, POLARSSL_VERSION_STRING ) == 0 );
TEST_ASSERT( strcmp( build_str_full, POLARSSL_VERSION_STRING_FULL ) == 0 );
TEST_ASSERT( strcmp( {version_str}, POLARSSL_VERSION_STRING ) == 0 );
}
END_CASE
BEGIN_CASE
check_runtime_version:version_str
{
char build_str[100];
char get_str[100];
char build_str_full[100];
char get_str_full[100];
unsigned int get_int;
memset( build_str, 0, 100 );
memset( get_str, 0, 100 );
memset( build_str_full, 0, 100 );
memset( get_str_full, 0, 100 );
get_int = version_get_number();
version_get_string( get_str );
version_get_string_full( get_str_full );
snprintf( build_str, 100, "%d.%d.%d",
(get_int >> 24) & 0xFF,
(get_int >> 16) & 0xFF,
(get_int >> 8) & 0xFF );
snprintf( build_str_full, 100, "PolarSSL %s", {version_str} );
TEST_ASSERT( strcmp( build_str, {version_str} ) == 0 );
TEST_ASSERT( strcmp( build_str_full, get_str_full ) == 0 );
TEST_ASSERT( strcmp( {version_str}, get_str ) == 0 );
}
END_CASE