From b42520b0ef9d05586a840fa5957daca2cb633521 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 17 Feb 2020 11:51:56 +0100 Subject: [PATCH] [machineid] Apply new STATICTEST specifier, hide implementation details --- src/modules/machineid/Tests.cpp | 7 ++-- src/modules/machineid/Workers.cpp | 55 ++++++++++++++++--------------- src/modules/machineid/Workers.h | 3 -- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/modules/machineid/Tests.cpp b/src/modules/machineid/Tests.cpp index 53abd0482..874fac3cb 100644 --- a/src/modules/machineid/Tests.cpp +++ b/src/modules/machineid/Tests.cpp @@ -28,6 +28,9 @@ #include #include +// Internals of Workers.cpp +extern int getUrandomPoolSize(); + class MachineIdTests : public QObject { Q_OBJECT @@ -93,10 +96,10 @@ MachineIdTests::testPoolSize() { #ifdef Q_OS_FREEBSD // It hardly makes sense, but also the /proc entry is missing - QCOMPARE( MachineId::getUrandomPoolSize(), 512 ); + QCOMPARE( getUrandomPoolSize(), 512 ); #else // Based on a sample size of 1, Netrunner - QCOMPARE( MachineId::getUrandomPoolSize(), 4096 ); + QCOMPARE( getUrandomPoolSize(), 4096 ); #endif } diff --git a/src/modules/machineid/Workers.cpp b/src/modules/machineid/Workers.cpp index 39acdfbf2..76e466435 100644 --- a/src/modules/machineid/Workers.cpp +++ b/src/modules/machineid/Workers.cpp @@ -27,6 +27,34 @@ #include +/// @brief Returns a recommended size for the entropy pool (in bytes) +STATICTEST int +getUrandomPoolSize() +{ + QFile f( "/proc/sys/kernel/random/poolsize" ); + constexpr const int minimumPoolSize = 512; + int poolSize = minimumPoolSize; + + if ( f.exists() && f.open( QIODevice::ReadOnly | QIODevice::Text ) ) + { + QByteArray v = f.read( 16 ); + if ( v.length() > 2 ) + { + if ( v.endsWith( '\n' ) ) + { + v.chop( 1 ); + } + bool ok = false; + poolSize = v.toInt( &ok ); + if ( !ok ) + { + poolSize = minimumPoolSize; + } + } + } + return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize; +} + namespace MachineId { @@ -59,33 +87,6 @@ copyFile( const QString& rootMountPoint, const QString& fileName ) return Calamares::JobResult::ok(); } -int -getUrandomPoolSize() -{ - QFile f( "/proc/sys/kernel/random/poolsize" ); - constexpr const int minimumPoolSize = 512; - int poolSize = minimumPoolSize; - - if ( f.exists() && f.open( QIODevice::ReadOnly | QIODevice::Text ) ) - { - QByteArray v = f.read( 16 ); - if ( v.length() > 2 ) - { - if ( v.endsWith( '\n' ) ) - { - v.chop( 1 ); - } - bool ok = false; - poolSize = v.toInt( &ok ); - if ( !ok ) - { - poolSize = minimumPoolSize; - } - } - } - return ( poolSize >= minimumPoolSize ) ? poolSize : minimumPoolSize; -} - Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName ) { diff --git a/src/modules/machineid/Workers.h b/src/modules/machineid/Workers.h index 31561af1b..8cb8d74ff 100644 --- a/src/modules/machineid/Workers.h +++ b/src/modules/machineid/Workers.h @@ -48,9 +48,6 @@ enum class EntropyGeneration CopyFromHost }; -/// @brief Returns a recommended size for the entropy pool (in bytes) -int getUrandomPoolSize(); - /// @brief Creates a new entropy file @p fileName in the target system at @p rootMountPoint Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName );