Changeset View
Changeset View
Standalone View
Standalone View
libs/editor/wireguardkeyvalidator.cpp
- This file was moved from vpn/wireguard/wireguardkeyvalidator.cpp.
Show All 20 Lines | |||||
21 | #include "wireguardkeyvalidator.h" | 21 | #include "wireguardkeyvalidator.h" | ||
22 | 22 | | |||
23 | WireGuardKeyValidator::WireGuardKeyValidator(QObject *parent) | 23 | WireGuardKeyValidator::WireGuardKeyValidator(QObject *parent) | ||
24 | : QValidator(parent) | 24 | : QValidator(parent) | ||
25 | { | 25 | { | ||
26 | m_validator = new QRegularExpressionValidator(this); | 26 | m_validator = new QRegularExpressionValidator(this); | ||
27 | // A WireGuard key is Base64 encoded and in human readable form consists | 27 | // A WireGuard key is Base64 encoded and in human readable form consists | ||
28 | // of 43 Alpha-numeric or '+' or '/' with a 44th character of an equal sign. | 28 | // of 43 Alpha-numeric or '+' or '/' with a 44th character of an equal sign. | ||
29 | m_validator->setRegularExpression(QRegularExpression(QLatin1String("[0-9a-zA-Z\\+/]{43,43}="))); | 29 | // The 43rd character is limited such that the converted character zeroes in | ||
30 | // the 2 LSB. | ||||
31 | m_validator->setRegularExpression(QRegularExpression(QLatin1String("[0-9a-zA-Z\\+/]{42,42}[AEIMQUYcgkosw048]="))); | ||||
30 | } | 32 | } | ||
31 | 33 | | |||
32 | WireGuardKeyValidator::~WireGuardKeyValidator() | 34 | WireGuardKeyValidator::~WireGuardKeyValidator() | ||
33 | { | 35 | { | ||
34 | } | 36 | } | ||
35 | 37 | | |||
36 | QValidator::State WireGuardKeyValidator::validate(QString &address, int &pos) const | 38 | QValidator::State WireGuardKeyValidator::validate(QString &address, int &pos) const | ||
37 | { | 39 | { | ||
38 | return m_validator->validate(address, pos); | 40 | return m_validator->validate(address, pos); | ||
39 | } | 41 | } |