]> WPIA git - cassiopeia.git/commitdiff
fix: Make CppCheck happy by fixing the code
authorFelix Dörre <felix@dogcraft.de>
Sat, 31 Jan 2015 02:21:07 +0000 (03:21 +0100)
committerBenny Baumann <BenBE@geshi.org>
Mon, 9 Feb 2015 19:06:03 +0000 (20:06 +0100)
Used CppCheck command:
    cppcheck --enable=all -v --inconclusive

13 files changed:
src/apps/client.cpp
src/apps/signer.cpp
src/crypto/X509.cpp
src/crypto/X509.h
src/crypto/remoteSigner.cpp
src/crypto/sslUtil.cpp
src/crypto/sslUtil.h
src/io/bios.cpp
src/io/opensslBIO.cpp
src/io/record.cpp
src/io/record.h
src/io/recordHandler.cpp
src/io/slipBio.cpp

index e1855190673870e998e3aeb78ff5ed405a0e9302..7c5bf0888b5a9bb3ac6996e7e02cd1ec19ca2aa7 100644 (file)
@@ -78,7 +78,7 @@ int main( int argc, const char* argv[] ) {
     std::shared_ptr<JobProvider> jp( new MySQLJobProvider( sqlHost, sqlUser, sqlPass, sqlDB ) );
     std::shared_ptr<BIO> b = openSerial( serialPath );
     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
-    ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
+    static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( b ) ) );
     std::shared_ptr<RemoteSigner> sign( new RemoteSigner( slip1, generateSSLContext( false ) ) );
     // std::shared_ptr<Signer> sign( new SimpleOpensslSigner() );
 
@@ -170,7 +170,7 @@ int main( int argc, const char* argv[] ) {
                 continue;
             } catch( const char* c ) {
                 log << "ERROR: " << c << std::endl;
-            } catch( std::string c ) {
+            } catch( std::string& c ) {
                 log << "ERROR: " << c << std::endl;
             }
 
@@ -178,7 +178,7 @@ int main( int argc, const char* argv[] ) {
                 jp->failJob( job );
             } catch( const char* c ) {
                 log << "ERROR: " << c << std::endl;
-            } catch( std::string c ) {
+            } catch( std::string& c ) {
                 log << "ERROR: " << c << std::endl;
             }
         } else if( job->task == "revoke" ) {
index dc9e702c54a7d6cc917d4ce962866a44a99ac0af..b607b9cd949152b8b13affce75fb96bb0f91614e 100644 (file)
@@ -46,7 +46,7 @@ int main( int argc, const char* argv[] ) {
 
     std::shared_ptr<BIO> conn = openSerial( serialPath );
     std::shared_ptr<BIO> slip1( BIO_new( toBio<SlipBIO>() ), BIO_free );
-    ( ( SlipBIO* )slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
+    static_cast<SlipBIO*>( slip1->ptr )->setTarget( std::shared_ptr<OpensslBIO>( new OpensslBIOWrapper( conn ) ) );
 
     DefaultRecordHandler* dh = new DefaultRecordHandler( std::shared_ptr<Signer>( new SimpleOpensslSigner( ) ), slip1 );
 
index ba39b4bcef68287bd15ef8ce5247c44b853f6ccd..d340a184fbb3c9676734c878b70cfc65c02d7261 100644 (file)
@@ -7,8 +7,7 @@
 #include <openssl/bio.h>
 #include <openssl/x509v3.h>
 
-X509Req::X509Req( X509_REQ* csr ) {
-    req = std::shared_ptr<X509_REQ>( csr, X509_REQ_free );
+X509Req::X509Req( X509_REQ* csr ) : req( csr, X509_REQ_free ) {
     EVP_PKEY* pkt = X509_REQ_get_pubkey( req.get() );
 
     if( !pkt ) {
@@ -48,7 +47,7 @@ int X509Req::verify() {
     return X509_REQ_verify( req.get(), pk.get() );
 }
 
-std::shared_ptr<EVP_PKEY> X509Req::getPkey() {
+std::shared_ptr<EVP_PKEY> X509Req::getPkey() const {
     return pk;
 }
 
index 04079994918f146901a6a0e44d6759a555e6ca70..ac0e3d3791baa28a813029b2c2b914d3873dd040 100644 (file)
@@ -19,7 +19,7 @@ public:
     static std::shared_ptr<X509Req> parseCSR( std::string content );
     static std::shared_ptr<X509Req> parseSPKAC( std::string content );
     int verify();
-    std::shared_ptr<EVP_PKEY> getPkey();
+    std::shared_ptr<EVP_PKEY> getPkey() const;
 };
 
 class X509Cert {
index b060f6cca116f25a4516357147f9f10612e6f512..b6c7c317d30047cf703c4c1824bb9c8836031ba2 100644 (file)
@@ -6,9 +6,7 @@
 #include <openssl/ssl.h>
 #include <openssl/bn.h>
 
-RemoteSigner::RemoteSigner( std::shared_ptr<BIO> target, std::shared_ptr<SSL_CTX> ctx ) {
-    this->target = target;
-    this->ctx = ctx;
+RemoteSigner::RemoteSigner( std::shared_ptr<BIO> target, std::shared_ptr<SSL_CTX> ctx ) : target( target ), ctx( ctx ) {
 }
 
 RemoteSigner::~RemoteSigner() {
index d0710e0a837d8d297dd343f37b1796f18d362e0f..753981c91195800dfd42cdee0b426a18658f08d7 100644 (file)
@@ -17,7 +17,7 @@ std::shared_ptr<int> ssl_lib_ref(
         CRYPTO_cleanup_all_ex_data();
     } );
 
-std::shared_ptr<X509> loadX509FromFile( std::string filename ) {
+std::shared_ptr<X509> loadX509FromFile( const std::string& filename ) {
     FILE* f = fopen( filename.c_str(), "r" );
 
     if( !f ) {
@@ -38,7 +38,7 @@ std::shared_ptr<X509> loadX509FromFile( std::string filename ) {
         } );
 }
 
-std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename ) {
+std::shared_ptr<EVP_PKEY> loadPkeyFromFile( const std::string& filename ) {
     FILE* f = fopen( filename.c_str(), "r" );
 
     if( !f ) {
@@ -162,7 +162,7 @@ void setupSerial( FILE* f ) {
     }
 }
 
-std::shared_ptr<BIO> openSerial( const std::string name ) {
+std::shared_ptr<BIO> openSerial( const std::string& name ) {
     FILE* f = fopen( name.c_str(), "r+" );
 
     if( !f ) {
@@ -175,9 +175,7 @@ std::shared_ptr<BIO> openSerial( const std::string name ) {
     return b;
 }
 
-CAConfig::CAConfig( std::string name ) {
-    this->name = name;
-    this->path = "ca/" + name;
+CAConfig::CAConfig( const std::string& name ) : path( "ca/" + name ), name( name ) {
     ca = loadX509FromFile( path + "/ca.crt" );
     caKey = loadPkeyFromFile( path + "/ca.key" );
     ASN1_TIME* tm = X509_get_notBefore( ca );
index c4193fe46766f656f2f7757c7d00fc4ad2eed700..1327a17bd47367dd0113ce8dec984e1ca93ccb27 100644 (file)
@@ -18,7 +18,7 @@ public:
     std::shared_ptr<X509> ca;
     std::shared_ptr<EVP_PKEY> caKey;
     std::shared_ptr<ASN1_TIME> notBefore;
-    CAConfig( std::string name );
+    CAConfig( const std::string& name );
     bool crlNeedsResign();
 };
 
@@ -43,10 +43,10 @@ struct Profile {
 
 extern std::shared_ptr<int> ssl_lib_ref;
 
-std::shared_ptr<X509> loadX509FromFile( std::string filename );
-std::shared_ptr<EVP_PKEY> loadPkeyFromFile( std::string filename );
+std::shared_ptr<X509> loadX509FromFile( const std::string& filename );
+std::shared_ptr<EVP_PKEY> loadPkeyFromFile( const std::string& filename );
 
 std::shared_ptr<SSL_CTX> generateSSLContext( bool server );
-std::shared_ptr<BIO> openSerial( const std::string name );
+std::shared_ptr<BIO> openSerial( const std::string& name );
 std::string timeToString( std::shared_ptr<ASN1_TIME> time );
 void extractTimes( std::shared_ptr<X509> source, std::shared_ptr<SignedCertificate> cert );
index 15d318c9ba38f5834cf35697bf967a0a0a7b2e21..9a1ea578fcac0422b894a158f5aee94bb44243b7 100644 (file)
@@ -5,27 +5,27 @@
 namespace BIOWrapper {
 
     int write( BIO* b, const char* buf, int num ) {
-        return ( ( OpensslBIO* )b->ptr )->write( buf, num );
+        return static_cast<OpensslBIO*>( b->ptr )->write( buf, num );
     }
 
     int read( BIO* b, char* buf, int size ) {
-        return ( ( OpensslBIO* )b->ptr )->read( buf, size );
+        return static_cast<OpensslBIO*>( b->ptr )->read( buf, size );
     }
 
     int puts( BIO* b, const char* str ) {
-        return ( ( OpensslBIO* )b->ptr )->puts( str );
+        return static_cast<OpensslBIO*>( b->ptr )->puts( str );
     }
 
     int gets( BIO* b, char* str, int size ) {
-        return ( ( OpensslBIO* )b->ptr )->gets( str, size );
+        return static_cast<OpensslBIO*>( b->ptr )->gets( str, size );
     }
 
     long ctrl( BIO* b, int cmod, long arg1, void* arg2 ) {
-        return ( ( OpensslBIO* )b->ptr )->ctrl( cmod, arg1, arg2 );
+        return static_cast<OpensslBIO*>( b->ptr )->ctrl( cmod, arg1, arg2 );
     }
 
     int free( BIO* b ) {
-        delete( ( OpensslBIO* ) b->ptr );
+        delete static_cast<OpensslBIO*>( b->ptr );
         b->ptr = 0;
         return 0;
     }
index 35628229ffdcbf00f162d5b134fb8196ecc4f582..03122db2ce738ec04c1df0f5660fc99ac5c26ecd 100644 (file)
@@ -1,7 +1,6 @@
 #include "opensslBIO.h"
 
-OpensslBIOWrapper::OpensslBIOWrapper( std::shared_ptr<BIO> b ) {
-    this->b = b;
+OpensslBIOWrapper::OpensslBIOWrapper( std::shared_ptr<BIO> b ) : b( b ) {
 }
 
 OpensslBIOWrapper::~OpensslBIOWrapper() {
index 8f81d02e683679fb764db59d16527e023d38f565..bd0cc1b8d1e965636575c4c122244bd5f50a076b 100644 (file)
@@ -52,7 +52,7 @@ int32_t fromHexDigit( char c ) {
     return res;
 }
 
-std::string parseCommand( RecordHeader& head, const std::string input, std::shared_ptr<std::ostream> log ) {
+std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log ) {
     if( log ) {
         ( *log.get() ) << "FINE: RECORD input: " << input << std::endl;
     }
index ba5a8d8be7d6f789557d91fe8f0bd813af1b592b..29c05ca04e7227745d64a8397ed700bfc39b71c6 100644 (file)
@@ -52,12 +52,12 @@ public:
     }
 
     template <class T>
-    void append( std::string& str, T val ) {
+    static void append( std::string& str, T val ) {
         str.append( ( char* ) &val, sizeof( T ) );
     }
 
     template <class T>
-    void read( std::string::iterator& it, T& val ) {
+    static void read( std::string::iterator& it, T& val ) {
         char* data = ( char* ) &val;
 
         for( size_t i = 0; i < sizeof( T ); i++ ) {
@@ -96,6 +96,6 @@ public:
 
 };
 
-std::string parseCommand( RecordHeader& head, const std::string input, std::shared_ptr<std::ostream> log );
+std::string parseCommand( RecordHeader& head, const std::string& input, std::shared_ptr<std::ostream> log );
 
 void sendCommand( RecordHeader& head, const std::string& data, std::shared_ptr<OpensslBIO> bio, std::shared_ptr<std::ostream> log );
index 2ba71c2675b821080fc39617523d6bd0096b4bc0..c46c84560d511c0f7ab338804210e27038769600 100644 (file)
@@ -221,14 +221,8 @@ public:
     }
 };
 
-DefaultRecordHandler::DefaultRecordHandler( std::shared_ptr<Signer> signer, std::shared_ptr<BIO> bio ) :
-    currentSession() {
-
-    this->signer = signer;
-
-    ctx = generateSSLContext( true );
-
-    this->bio = bio;
+DefaultRecordHandler::DefaultRecordHandler( std::shared_ptr<Signer> signer, std::shared_ptr<BIO> bio )
+    : bio( bio ), ctx( generateSSLContext( true ) ), signer( signer ), currentSession() {
 }
 
 void DefaultRecordHandler::reset() {
index 1a7ba04b6a9040a7b3bba3b53f2c0c2804d8fcdc..fb3f6c1925cbde5cb499008b1edfcb656fe1883d 100644 (file)
@@ -37,27 +37,14 @@ std::string toHex( const char* buf, int len ) {
     return data;
 }
 
-SlipBIO::SlipBIO() {
-    this->buffer = std::vector<char>( BUFFER_SIZE );
-    this->decodeTarget = 0;
-    this->decodePos = 0;
-    this->rawPos = 0;
-    this->failed = false;
+SlipBIO::SlipBIO() : buffer( std::vector<char>( BUFFER_SIZE ) ), decodeTarget( 0 ), decodePos( 0 ), rawPos( 0 ), failed( false ) {
 }
 
 void SlipBIO::setTarget( std::shared_ptr<OpensslBIO> target ) {
     this->target = target;
 }
 
-SlipBIO::SlipBIO( std::shared_ptr<OpensslBIO> target ) {
-    this->target = target;
-
-    this->buffer = std::vector<char>( BUFFER_SIZE );
-    this->decodeTarget = 0;
-    this->decodePos = 0;
-    this->rawPos = 0;
-
-    this->failed = false;
+SlipBIO::SlipBIO( std::shared_ptr<OpensslBIO> target ) : target( target ), buffer( std::vector<char>( BUFFER_SIZE ) ), decodeTarget( 0 ), decodePos( 0 ), rawPos( 0 ), failed( false ) {
 }
 
 SlipBIO::~SlipBIO() {}