mirror of
https://github.com/debauchee/barrier.git
synced 2024-11-23 09:43:24 +03:00
Refactored string operations
Conflicts: src/lib/base/String.cpp
This commit is contained in:
parent
cb0f0dd06d
commit
39e183da3e
@ -27,6 +27,9 @@
|
||||
#include <algorithm>
|
||||
#include <stdio.h>
|
||||
#include <cstdarg>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
namespace synergy {
|
||||
namespace string {
|
||||
@ -180,6 +183,30 @@ removeFileExt(String filename)
|
||||
return filename.substr(0, dot);
|
||||
}
|
||||
|
||||
void
|
||||
toHex(CString& subject, int width, const char fill)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::hex;
|
||||
for (unsigned int i = 0; i < subject.length(); i++) {
|
||||
ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i];
|
||||
}
|
||||
|
||||
subject = ss.str();
|
||||
}
|
||||
|
||||
void
|
||||
uppercase(CString& subject)
|
||||
{
|
||||
std::transform(subject.begin(), subject.end(), subject.begin(), ::toupper);
|
||||
}
|
||||
|
||||
void
|
||||
removeChar(CString& subject, const char c)
|
||||
{
|
||||
subject.erase(std::remove(subject.begin(), subject.end(), c), subject.end());
|
||||
}
|
||||
|
||||
//
|
||||
// CaselessCmp
|
||||
//
|
||||
|
@ -70,6 +70,25 @@ Finds the last dot and remove all characters from the dot to the end
|
||||
*/
|
||||
String removeFileExt(String filename);
|
||||
|
||||
//! Convert into hexdecimal
|
||||
/*!
|
||||
Convert each character in \c subject into hexdecimal form with \c width
|
||||
*/
|
||||
void toHex(CString& subject, int width, const char fill = '0');
|
||||
|
||||
//! Convert to all uppercase
|
||||
/*!
|
||||
Convert each character in \c subject to uppercase
|
||||
*/
|
||||
void uppercase(CString& subject);
|
||||
|
||||
//! Remove all specific char in suject
|
||||
/*!
|
||||
Remove all specific \c char in \c suject
|
||||
*/
|
||||
void removeChar(CString& subject, const char c);
|
||||
|
||||
|
||||
//! Case-insensitive comparisons
|
||||
/*!
|
||||
This class provides case-insensitve comparison functions.
|
||||
|
@ -28,10 +28,7 @@
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// SecureSocket
|
||||
@ -419,15 +416,11 @@ CSecureSocket::verifyCertFingerprint()
|
||||
}
|
||||
|
||||
// convert fingerprint into hexdecimal format
|
||||
std::stringstream ss;
|
||||
ss << std::hex;
|
||||
for (unsigned int i = 0; i < tempFingerprintLen; i++) {
|
||||
ss << std::setw(2) << std::setfill('0') << (int)tempFingerprint[i];
|
||||
}
|
||||
CString fingerprint(reinterpret_cast<char*>(tempFingerprint), tempFingerprintLen);
|
||||
synergy::string::toHex(fingerprint, 2);
|
||||
|
||||
// all uppercase
|
||||
CString fingerprint = ss.str();
|
||||
std::transform(fingerprint.begin(), fingerprint.end(), fingerprint.begin(), ::toupper);
|
||||
synergy::string::uppercase(fingerprint);
|
||||
|
||||
// check if this fingerprint exist
|
||||
CString fileLine;
|
||||
@ -445,7 +438,7 @@ CSecureSocket::verifyCertFingerprint()
|
||||
|
||||
if (!certificateFingerprint.empty()) {
|
||||
// remove colons
|
||||
certificateFingerprint.erase(std::remove(certificateFingerprint.begin(), certificateFingerprint.end(), ':'), certificateFingerprint.end());
|
||||
synergy::string::removeChar(certificateFingerprint, ':');
|
||||
|
||||
if(certificateFingerprint.compare(fingerprint) == 0) {
|
||||
file.close();
|
||||
|
Loading…
Reference in New Issue
Block a user