@@ -4991,8 +4991,85 @@ static QVariant fcnFileSize( const QVariantList &values, const QgsExpressionCont
4991
4991
return QFileInfo ( file ).size ();
4992
4992
}
4993
4993
4994
+ static QVariant fcnHash ( const QString str, const QCryptographicHash::Algorithm algorithm )
4995
+ {
4996
+ return QString ( QCryptographicHash::hash ( str.toUtf8 (), algorithm ).toHex () );
4997
+ }
4998
+
4999
+ static QVariant fcnHashMd4 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5000
+ {
5001
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Md4 );
5002
+ }
5003
+
5004
+ static QVariant fcnHashMd5 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5005
+ {
5006
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Md5 );
5007
+ }
5008
+
5009
+ static QVariant fcnHashSha1 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5010
+ {
5011
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha1 );
5012
+ }
5013
+
5014
+ static QVariant fcnHashSha224 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5015
+ {
5016
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha224 );
5017
+ }
5018
+
5019
+ static QVariant fcnHashSha256 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5020
+ {
5021
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha256 );
5022
+ }
5023
+
5024
+ static QVariant fcnHashSha384 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5025
+ {
5026
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha384 );
5027
+ }
5028
+
5029
+ static QVariant fcnHashSha512 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5030
+ {
5031
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha512 );
5032
+ }
4994
5033
5034
+ static QVariant fcnHashSha3_224 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5035
+ {
5036
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha3_224 );
5037
+ }
5038
+
5039
+ static QVariant fcnHashSha3_256 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5040
+ {
5041
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha3_256 );
5042
+ }
5043
+
5044
+ static QVariant fcnHashSha3_384 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5045
+ {
5046
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha3_384 );
5047
+ }
4995
5048
5049
+ static QVariant fcnHashSha3_512 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5050
+ {
5051
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Sha3_512 );
5052
+ }
5053
+
5054
+ static QVariant fcnHashKeccak_224 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5055
+ {
5056
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Keccak_224 );
5057
+ }
5058
+
5059
+ static QVariant fcnHashKeccak_256 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5060
+ {
5061
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Keccak_256 );
5062
+ }
5063
+
5064
+ static QVariant fcnHashKeccak_384 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5065
+ {
5066
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Keccak_384 );
5067
+ }
5068
+
5069
+ static QVariant fcnHashKeccak_512 ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
5070
+ {
5071
+ return fcnHash ( QgsExpressionUtils::getStringValue ( values.at ( 0 ), parent ), QCryptographicHash::Keccak_512 );
5072
+ }
4996
5073
4997
5074
const QList<QgsExpressionFunction *> &QgsExpression::Functions ()
4998
5075
{
@@ -5288,6 +5365,38 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
5288
5365
<< new QgsStaticExpressionFunction ( QStringLiteral ( " file_size" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " path" ) ),
5289
5366
fcnFileSize, QStringLiteral ( " Files and Paths" ) )
5290
5367
5368
+ // hash
5369
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " md4" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5370
+ fcnHashMd4, QStringLiteral ( " Hash" ) )
5371
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " md5" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5372
+ fcnHashMd5, QStringLiteral ( " Hash" ) )
5373
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha1" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5374
+ fcnHashSha1, QStringLiteral ( " Hash" ) )
5375
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha224" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5376
+ fcnHashSha224, QStringLiteral ( " Hash" ) )
5377
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha256" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5378
+ fcnHashSha256, QStringLiteral ( " Hash" ) )
5379
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha384" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5380
+ fcnHashSha384, QStringLiteral ( " Hash" ) )
5381
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha512" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5382
+ fcnHashSha512, QStringLiteral ( " Hash" ) )
5383
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha3_224" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5384
+ fcnHashSha3_224, QStringLiteral ( " Hash" ) )
5385
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha3_256" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5386
+ fcnHashSha3_256, QStringLiteral ( " Hash" ) )
5387
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha3_384" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5388
+ fcnHashSha3_384, QStringLiteral ( " Hash" ) )
5389
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " sha3_512" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5390
+ fcnHashSha3_512, QStringLiteral ( " Hash" ) )
5391
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " keccak_224" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5392
+ fcnHashKeccak_224, QStringLiteral ( " Hash" ) )
5393
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " keccak_256" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5394
+ fcnHashKeccak_256, QStringLiteral ( " Hash" ) )
5395
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " keccak_384" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5396
+ fcnHashKeccak_384, QStringLiteral ( " Hash" ) )
5397
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " keccak_512" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ),
5398
+ fcnHashKeccak_512, QStringLiteral ( " Hash" ) )
5399
+
5291
5400
// deprecated stuff - hidden from users
5292
5401
<< new QgsStaticExpressionFunction ( QStringLiteral ( " $scale" ), QgsExpressionFunction::ParameterList (), fcnMapScale, QStringLiteral ( " deprecated" ) );
5293
5402
0 commit comments