Skip to content
API Documentation
BastionGuard™
PasswordVault.cpp File Reference

Go to the source code of this file.

Functions

static void secureClear (std::string &s)
static std::string toHex (const unsigned char *data, size_t len)
static std::string toHex (const std::string &s)
static std::string fromHex (const std::string &hex)
static std::string csvEscape (const std::string &s)

Function Documentation

◆ csvEscape()

std::string csvEscape ( const std::string & s)
static

Definition at line 77 of file PasswordVault.cpp.

77 {
78 bool needs = s.find_first_of(",\"\n\r") != std::string::npos;
79 if (!needs) return s;
80 std::string out = "\"";
81 for (char c : s) { if (c == '"') out += "\"\""; else out += c; }
82 return out + '"';
83}

References csvEscape().

Referenced by csvEscape(), and PasswordVault::exportToCSV().

◆ fromHex()

std::string fromHex ( const std::string & hex)
static

Definition at line 62 of file PasswordVault.cpp.

62 {
63 std::string out;
64 out.reserve(hex.size() / 2);
65 for (size_t i = 0; i + 1 < hex.size(); i += 2) {
66 try {
67 out.push_back(static_cast<char>(std::stoi(hex.substr(i, 2), nullptr, 16)));
68 } catch (...) {
69 // byte non valido (vault corrotto o non-hex): restituisci vuoto
70 // così il caller sa che la decodifica è fallita.
71 return {};
72 }
73 }
74 return out;
75}

References fromHex().

Referenced by PasswordVault::deriveKey(), fromHex(), PasswordVault::loadSecretsFile(), PasswordVault::pbkdf2Hex(), and PasswordVault::saveSecretsFile().

◆ secureClear()

void secureClear ( std::string & s)
static

Definition at line 41 of file PasswordVault.cpp.

41 {
42 if (!s.empty()) {
43 volatile char* p = const_cast<volatile char*>(s.data());
44 std::memset(const_cast<char*>(s.data()), 0, s.size());
45 (void)p;
46 s.clear();
47 }
48}

References secureClear().

Referenced by PasswordVault::lock(), and secureClear().

◆ toHex() [1/2]

std::string toHex ( const std::string & s)
static

Definition at line 58 of file PasswordVault.cpp.

58 {
59 return toHex(reinterpret_cast<const unsigned char*>(s.data()), s.size());
60}
static std::string toHex(const unsigned char *data, size_t len)

References toHex().

◆ toHex() [2/2]

std::string toHex ( const unsigned char * data,
size_t len )
static

Definition at line 50 of file PasswordVault.cpp.

50 {
51 std::ostringstream oss;
52 oss << std::hex << std::setfill('0');
53 for (size_t i = 0; i < len; ++i)
54 oss << std::setw(2) << static_cast<int>(data[i]);
55 return oss.str();
56}

References toHex().

Referenced by PasswordVault::generateNonceHex(), PasswordVault::generateSaltHex(), PasswordVault::pbkdf2Hex(), PasswordVault::saveSecretsFile(), toHex(), and toHex().