mirror of
https://github.com/parchlinux/calamares.git
synced 2025-06-27 09:25:36 -04:00
[libcalamares] Introduce redaction-of-names class for logging
- redacted names are stable inside of one run of Calamares - random, private displays of a given string for a context SEE #1593
This commit is contained in:
parent
7b3c4db8f0
commit
152b3c333b
2 changed files with 49 additions and 0 deletions
|
@ -20,6 +20,8 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
#include <QRandomGenerator>
|
||||||
|
#include <QTextStream>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
@ -252,4 +254,34 @@ operator<<( QDebug& s, const RedactedCommand& l )
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief Returns a stable-but-private hash of @p context and @p s
|
||||||
|
*
|
||||||
|
* Identical strings with the same context will be hashed the same,
|
||||||
|
* so that they can be logged and still recognized as the-same.
|
||||||
|
*/
|
||||||
|
static uint insertRedactedName( const QString& context, const QString& s )
|
||||||
|
{
|
||||||
|
static uint salt = QRandomGenerator::global()->generate(); // Just once
|
||||||
|
|
||||||
|
uint val = qHash(context, salt);
|
||||||
|
return qHash(s, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
RedactedName::RedactedName( const QString& context, const QString& s )
|
||||||
|
: m_id( insertRedactedName(context, s) ),
|
||||||
|
m_context(context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RedactedName::RedactedName(const char *context, const QString& s )
|
||||||
|
: RedactedName( QString::fromLatin1(context), s )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QDebug&
|
||||||
|
operator<< ( QDebug& s, const RedactedName& n )
|
||||||
|
{
|
||||||
|
return s << NoQuote << n.m_context << '$' << n.m_id << Quote;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Logger
|
} // namespace Logger
|
||||||
|
|
|
@ -226,6 +226,23 @@ struct RedactedCommand
|
||||||
|
|
||||||
QDebug& operator<<( QDebug& s, const RedactedCommand& l );
|
QDebug& operator<<( QDebug& s, const RedactedCommand& l );
|
||||||
|
|
||||||
|
/** @brief When logging "private" identifiers, keep them consistent but private
|
||||||
|
*
|
||||||
|
* Send a string to a logger in such a way that each time it is logged,
|
||||||
|
* it logs the same way, but without revealing the actual contents.
|
||||||
|
* This can be applied to user names, UUIDs, etc.
|
||||||
|
*/
|
||||||
|
struct RedactedName
|
||||||
|
{
|
||||||
|
RedactedName( const char* context, const QString& s );
|
||||||
|
RedactedName( const QString& context, const QString& s );
|
||||||
|
|
||||||
|
const uint m_id;
|
||||||
|
const QString m_context;
|
||||||
|
};
|
||||||
|
|
||||||
|
QDebug& operator<<( QDebug& s, const RedactedName& n );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Formatted logging of a pointer
|
* @brief Formatted logging of a pointer
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue