gui: Extract certificate path generation to separate functions

This commit is contained in:
Povilas Kanapickas 2020-07-19 11:56:16 +03:00
parent 93ef15774b
commit 7210bfa615
2 changed files with 17 additions and 13 deletions

View File

@ -37,8 +37,8 @@ static const char kConfigFile[] = "barrier.conf";
SslCertificate::SslCertificate(QObject *parent) : SslCertificate::SslCertificate(QObject *parent) :
QObject(parent) QObject(parent)
{ {
m_ProfileDir = QString::fromStdString(DataDirectories::profile()); m_ProfileDir = DataDirectories::profile();
if (m_ProfileDir.isEmpty()) { if (m_ProfileDir.empty()) {
emit error(tr("Failed to get profile directory.")); emit error(tr("Failed to get profile directory."));
} }
} }
@ -91,15 +91,7 @@ std::pair<bool, std::string> SslCertificate::runTool(const QStringList& args)
void SslCertificate::generateCertificate() void SslCertificate::generateCertificate()
{ {
QString sslDirPath = QString("%1%2%3") auto filename = QString::fromStdString(getCertificatePath());
.arg(m_ProfileDir)
.arg(QDir::separator())
.arg(kSslDir);
QString filename = QString("%1%2%3")
.arg(sslDirPath)
.arg(QDir::separator())
.arg(kCertificateFilename);
QFile file(filename); QFile file(filename);
if (!file.exists()) { if (!file.exists()) {
@ -124,7 +116,7 @@ void SslCertificate::generateCertificate()
arguments.append("-newkey"); arguments.append("-newkey");
arguments.append("rsa:2048"); arguments.append("rsa:2048");
QDir sslDir(sslDirPath); QDir sslDir(QString::fromStdString(getCertificateDirectory()));
if (!sslDir.exists()) { if (!sslDir.exists()) {
sslDir.mkpath("."); sslDir.mkpath(".");
} }
@ -182,3 +174,12 @@ void SslCertificate::generateFingerprint(const QString& certificateFilename)
} }
} }
std::string SslCertificate::getCertificatePath()
{
return getCertificateDirectory() + QDir::separator().toLatin1() + kCertificateFilename;
}
std::string SslCertificate::getCertificateDirectory()
{
return m_ProfileDir + QDir::separator().toLatin1() + kSslDir;
}

View File

@ -39,6 +39,9 @@ private:
std::pair<bool, std::string> runTool(const QStringList& args); std::pair<bool, std::string> runTool(const QStringList& args);
void generateFingerprint(const QString& certificateFilename); void generateFingerprint(const QString& certificateFilename);
std::string getCertificatePath();
std::string getCertificateDirectory();
private: private:
QString m_ProfileDir; std::string m_ProfileDir;
}; };