Skip to content

Commit

Permalink
gui: Extract certificate path generation to separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
p12tic committed Jul 19, 2020
1 parent 93ef157 commit 7210bfa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/gui/src/SslCertificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static const char kConfigFile[] = "barrier.conf";
SslCertificate::SslCertificate(QObject *parent) :
QObject(parent)
{
m_ProfileDir = QString::fromStdString(DataDirectories::profile());
if (m_ProfileDir.isEmpty()) {
m_ProfileDir = DataDirectories::profile();
if (m_ProfileDir.empty()) {
emit error(tr("Failed to get profile directory."));
}
}
Expand Down Expand Up @@ -91,15 +91,7 @@ std::pair<bool, std::string> SslCertificate::runTool(const QStringList& args)

void SslCertificate::generateCertificate()
{
QString sslDirPath = QString("%1%2%3")
.arg(m_ProfileDir)
.arg(QDir::separator())
.arg(kSslDir);

QString filename = QString("%1%2%3")
.arg(sslDirPath)
.arg(QDir::separator())
.arg(kCertificateFilename);
auto filename = QString::fromStdString(getCertificatePath());

QFile file(filename);
if (!file.exists()) {
Expand All @@ -124,7 +116,7 @@ void SslCertificate::generateCertificate()
arguments.append("-newkey");
arguments.append("rsa:2048");

QDir sslDir(sslDirPath);
QDir sslDir(QString::fromStdString(getCertificateDirectory()));
if (!sslDir.exists()) {
sslDir.mkpath(".");
}
Expand Down Expand Up @@ -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;
}
5 changes: 4 additions & 1 deletion src/gui/src/SslCertificate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public slots:
std::pair<bool, std::string> runTool(const QStringList& args);
void generateFingerprint(const QString& certificateFilename);

std::string getCertificatePath();
std::string getCertificateDirectory();

private:
QString m_ProfileDir;
std::string m_ProfileDir;
};

0 comments on commit 7210bfa

Please sign in to comment.