File indexing completed on 2024-04-28 05:50:07
0001 /* 0002 * SPDX-License-Identifier: GPL-3.0-or-later 0003 * SPDX-FileCopyrightText: 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com> 0004 */ 0005 #include "validation.h" 0006 0007 #include "../base32/base32.h" 0008 #include "../oath/oath.h" 0009 0010 namespace accounts 0011 { 0012 0013 bool checkId(const QUuid &id) 0014 { 0015 return !id.isNull(); 0016 } 0017 0018 bool checkSecret(const QString &secret) 0019 { 0020 return !secret.isEmpty() && base32::validate(secret); 0021 } 0022 0023 bool checkName(const QString &name) 0024 { 0025 return !name.isEmpty(); 0026 } 0027 0028 bool checkIssuer(const QString &issuer) 0029 { 0030 return issuer.isNull() || (!issuer.isEmpty() && !issuer.contains(QLatin1Char(':'))); 0031 } 0032 0033 bool checkTokenLength(uint tokenLength) 0034 { 0035 return tokenLength >= 6U && tokenLength <= 10U; 0036 } 0037 0038 bool checkTimeStep(uint timeStep) 0039 { 0040 return timeStep > 0U; 0041 } 0042 0043 bool checkEpoch(const QDateTime &epoch, const std::function<qint64(void)> &clock) 0044 { 0045 return epoch.isValid() && epoch.toMSecsSinceEpoch() <= clock(); 0046 } 0047 0048 bool checkOffset(const std::optional<uint> &offset, QCryptographicHash::Algorithm algorithm) 0049 { 0050 return oath::Algorithm::validate(algorithm, offset); 0051 } 0052 }