[machineid] Apply new STATICTEST specifier, hide implementation details

main
Adriaan de Groot 6 years ago
parent 92260e7d0b
commit b42520b0ef

@ -28,6 +28,9 @@
#include <QFile> #include <QFile>
#include <QtTest/QtTest> #include <QtTest/QtTest>
// Internals of Workers.cpp
extern int getUrandomPoolSize();
class MachineIdTests : public QObject class MachineIdTests : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -93,10 +96,10 @@ MachineIdTests::testPoolSize()
{ {
#ifdef Q_OS_FREEBSD #ifdef Q_OS_FREEBSD
// It hardly makes sense, but also the /proc entry is missing // It hardly makes sense, but also the /proc entry is missing
QCOMPARE( MachineId::getUrandomPoolSize(), 512 ); QCOMPARE( getUrandomPoolSize(), 512 );
#else #else
// Based on a sample size of 1, Netrunner // Based on a sample size of 1, Netrunner
QCOMPARE( MachineId::getUrandomPoolSize(), 4096 ); QCOMPARE( getUrandomPoolSize(), 4096 );
#endif #endif
} }

@ -27,6 +27,34 @@
#include <QFile> #include <QFile>
/// @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 namespace MachineId
{ {
@ -59,33 +87,6 @@ copyFile( const QString& rootMountPoint, const QString& fileName )
return Calamares::JobResult::ok(); 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 Calamares::JobResult
createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName ) createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName )
{ {

@ -48,9 +48,6 @@ enum class EntropyGeneration
CopyFromHost 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 /// @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 ); Calamares::JobResult createNewEntropy( int poolSize, const QString& rootMountPoint, const QString& fileName );

Loading…
Cancel
Save