File indexing completed on 2024-10-06 13:24:48
0001 /* 0002 SPDX-FileCopyrightText: 2018 Bruce Anderson <banderson19com@san.rr.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "wireguardkeyvalidator.h" 0008 0009 WireGuardKeyValidator::WireGuardKeyValidator(QObject *parent) 0010 : QValidator(parent) 0011 , m_validator(new QRegularExpressionValidator(this)) 0012 { 0013 // A WireGuard key is Base64 encoded and in human readable form consists 0014 // of 43 Alpha-numeric or '+' or '/' with a 44th character of an equal sign. 0015 // The 43rd character is limited such that the converted character zeroes in 0016 // the 2 LSB. 0017 m_validator->setRegularExpression(QRegularExpression(QStringLiteral("[0-9a-zA-Z\\+/]{42,42}[AEIMQUYcgkosw048]="))); 0018 } 0019 0020 WireGuardKeyValidator::~WireGuardKeyValidator() = default; 0021 0022 QValidator::State WireGuardKeyValidator::validate(QString &address, int &pos) const 0023 { 0024 return m_validator->validate(address, pos); 0025 }