From 9604d1c89ad503354726c7fece12551a6b4e7642 Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Sat, 15 Dec 2018 18:44:59 -0200 Subject: [PATCH] Misc. --- .../README.builtin_functions.txt | 14 +++---- src/common/cvt.cpp | 7 ++-- src/dsql/parse.y | 42 +++++++++---------- src/jrd/SysFunction.cpp | 32 +++++++------- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/doc/sql.extensions/README.builtin_functions.txt b/doc/sql.extensions/README.builtin_functions.txt index 80afbd53b3..7c87be0c40 100644 --- a/doc/sql.extensions/README.builtin_functions.txt +++ b/doc/sql.extensions/README.builtin_functions.txt @@ -424,7 +424,7 @@ Function: Encrypts/decrypts data using symmetric cipher. Format: - {ENCRYPT | DECRYPT} ( USING [MODE ] KEY \ + {ENCRYPT | DECRYPT} ( USING [MODE ] KEY [IV ] [] [CTR_LENGTH ] [COUNTER ]) algorithm ::= { block_cipher | stream_cipher } @@ -776,17 +776,17 @@ RDB$GET_TRANSACTION_CN Function: Returns commit number of given transaction. Result type is BIGINT. - Note, engine internally uses unsigned 8-byte integer for commit numbers, - and unsigned 6-byte integer for transaction numbers. Thus, despite of + Note, engine internally uses unsigned 8-byte integer for commit numbers, + and unsigned 6-byte integer for transaction numbers. Thus, despite of SQL language have no unsigned integers and RDB$GET_TRANSACTION_CN returns - signed BIGINT, it is impossible to see negative commit numbers except of - few special values used for non-committed transactions. + signed BIGINT, it is impossible to see negative commit numbers except of + few special values used for non-committed transactions. Summary, numbers returned by RDB$GET_TRANSACTION_CN could have values below: -2 - transaction is dead (rolled back) -1 - transaction is in limbo 0 - transaction is active, - 1 - transaction committed before database started or less than database + 1 - transaction committed before database started or less than database Oldest Interesting Transaction >1 - transaction committed after database started NULL - given transaction number is NULL or greater than database Next Transaction @@ -970,7 +970,7 @@ Format: KEY should be a value, returhed by RSA_PRIVATE function. LPARAM is the same variable passed to RSA_ENCRYPT. If it does not match what was used during encoding this function will not decrypt the packet. - hash ::= { MD5 | SHA1 | SHA256 | SHA512 } Default is SHA256. + hash ::= { MD5 | SHA1 | SHA256 | SHA512 } Default is SHA256. Example: (tip - start running samples one by one from RSA_PRIVATE function) diff --git a/src/common/cvt.cpp b/src/common/cvt.cpp index f41b838ca0..25b366e438 100644 --- a/src/common/cvt.cpp +++ b/src/common/cvt.cpp @@ -3072,19 +3072,18 @@ const UCHAR* CVT_get_bytes(const dsc* desc, unsigned& size) { case dtype_varying: { - vary* v = (vary*)(desc->dsc_address); + vary* v = (vary*) desc->dsc_address; size = v->vary_length; - return (const UCHAR*)v->vary_string; + return (const UCHAR*) v->vary_string; } case dtype_cstring: - size = strlen((const char*)desc->dsc_address); + size = strlen((const char*) desc->dsc_address); return desc->dsc_address; default: size = desc->dsc_length; return desc->dsc_address; - break; } return nullptr; // compiler warning silencer diff --git a/src/dsql/parse.y b/src/dsql/parse.y index e735b11e87..f268e14d2c 100644 --- a/src/dsql/parse.y +++ b/src/dsql/parse.y @@ -8045,50 +8045,50 @@ rsa_encrypt_decrypt %type opt_lparam opt_lparam - : LPARAM value - { $$ = $2; } - | /* nothing */ + : // nothing { $$ = MAKE_str_constant(newIntlString(""), CS_ASCII); } + | LPARAM value + { $$ = $2; } ; %type opt_hash opt_hash - : HASH valid_symbol_name - { $$ = $2; } - | /* nothing */ + : // nothing { $$ = newNode(""); } + | HASH valid_symbol_name + { $$ = $2; } ; %type opt_saltlen opt_saltlen - : SALT_LENGTH value - { $$ = $2; } - | /* nothing */ + : // nothing { $$ = MAKE_str_constant(newIntlString(""), CS_ASCII); } + | SALT_LENGTH value + { $$ = $2; } ; %type opt_mode opt_mode - : MODE valid_symbol_name - { $$ = $2; } - | /* nothing */ + : // nothing { $$ = newNode(""); } + | MODE valid_symbol_name + { $$ = $2; } ; %type opt_iv opt_iv - : IV value - { $$ = $2; } - | /* nothing */ + : // nothing { $$ = MAKE_str_constant(newIntlString(""), CS_ASCII); } + | IV value + { $$ = $2; } ; %type opt_counter_type opt_counter_type - : counter_type - { $$ = $1; } - | /* nothing */ + : // nothing { $$ = newNode(""); } + | counter_type + { $$ = $1; } ; %type counter_type @@ -8098,10 +8098,10 @@ counter_type %type opt_counter opt_counter - : counter_name value - { $$ = $2; } - | /* nothing */ + : // nothing { $$ = MAKE_str_constant(newIntlString(""), CS_ASCII); } + | counter_name value + { $$ = $2; } ; %type counter_name diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index efddfd691f..7a3a37c03f 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -1199,7 +1199,7 @@ void makeGetSetContext(DataTypeUtilBase* /*dataTypeUtil*/, const SysFunction* fu } -void makeGetTranCN(DataTypeUtilBase* /*dataTypeUtil*/, const SysFunction* /*function*/, dsc* result, +void makeGetTranCN(DataTypeUtilBase* /*dataTypeUtil*/, const SysFunction* /*function*/, dsc* result, int /*argsCount*/, const dsc** /*args*/) { result->makeInt64(0); @@ -1234,9 +1234,10 @@ void makeEncrypt(DataTypeUtilBase* dataTypeUtil, const SysFunction* function, ds fb_assert(argsCount == CRYPT_ARG_MAX); if (args[0]->isBlob()) - result->makeBlob(0, ttype_binary); + result->makeBlob(0, ttype_binary); else result->makeVarying(args[0]->getStringLength(), ttype_binary); + result->setNullable(args[0]->isNullable()); } @@ -1247,9 +1248,10 @@ void makeDecrypt(DataTypeUtilBase* dataTypeUtil, const SysFunction* function, ds fb_assert(argsCount == CRYPT_ARG_MAX); if (args[0]->isBlob()) - result->makeBlob(0, ttype_none); + result->makeBlob(0, ttype_none); else result->makeVarying(args[0]->getStringLength(), ttype_none); + result->setNullable(args[0]->isNullable()); } @@ -2665,7 +2667,7 @@ dsc* evlEncryptDecrypt(thread_db* tdbb, const SysFunction* function, const NestV { if (!modeName.hasData()) raise("Should specify MODE parameter for symmetric algorithm"); - + m = find(modes, modeName); if (!m) raise("Unknown symmetric crypt mode"); @@ -2737,7 +2739,7 @@ dsc* evlEncryptDecrypt(thread_db* tdbb, const SysFunction* function, const NestV if (iv.hasData() && iv.getCount() != blockLen) raise("Invalid IV length @2, need @1"); // block_length, iv.getCount - switch(m->code) + switch (m->code) { case MODE_ECB: { @@ -2830,7 +2832,7 @@ dsc* evlEncryptDecrypt(thread_db* tdbb, const SysFunction* function, const NestV else { fb_assert(a); - switch(a->code) + switch (a->code) { case ALG_RC4: { @@ -2851,7 +2853,7 @@ dsc* evlEncryptDecrypt(thread_db* tdbb, const SysFunction* function, const NestV { chacha_state chacha; tomCheck(chacha_setup(&chacha, key.begin(), key.getCount(), 20), "initializing CHACHA#20"); - switch(iv.getCount()) + switch (iv.getCount()) { case 12: tomCheck(chacha_ivctr32(&chacha, iv.begin(), iv.getCount(), ctrVal), "setting IV for CHACHA#20"); @@ -3107,7 +3109,7 @@ dsc* evlRsaSign(thread_db* tdbb, const SysFunction* function, const NestValueArr } -dsc* boolResult(thread_db* tdbb, impure_value* impure, bool value) +static dsc* boolResult(thread_db* tdbb, impure_value* impure, bool value) { dsc result; FB_BOOLEAN rc = value ? FB_TRUE : FB_FALSE; @@ -4017,7 +4019,7 @@ dsc* evlSetContext(thread_db* tdbb, const SysFunction*, const NestValueArray& ar } -dsc* evlGetTranCN(thread_db* tdbb, const SysFunction* function, const NestValueArray& args, +dsc* evlGetTranCN(thread_db* tdbb, const SysFunction* function, const NestValueArray& args, impure_value* impure) { fb_assert(args.getCount() == 1); @@ -5704,12 +5706,6 @@ const SysFunction SysFunction::functions[] = {"DATEDIFF", 3, 3, setParamsDateDiff, makeInt64Result, evlDateDiff, NULL}, {"DECRYPT", 7, 7, setParamsEncrypt, makeDecrypt, evlDecrypt, NULL}, {"ENCRYPT", 7, 7, setParamsEncrypt, makeEncrypt, evlEncrypt, NULL}, - {"RSA_DECRYPT", 4, 4, setParamsRsaEncrypt, makeRsaDecrypt, evlRsaDecrypt, NULL}, - {"RSA_ENCRYPT", 4, 4, setParamsRsaEncrypt, makeRsaEncrypt, evlRsaEncrypt, NULL}, - {"RSA_PRIVATE", 1, 1, setParamsInteger, makeRsaPrivate, evlRsaPrivate, NULL}, - {"RSA_PUBLIC", 1, 1, setParamsRsaPublic, makeRsaPublic, evlRsaPublic, NULL}, - {"RSA_SIGN", 4, 4, setParamsRsaSign, makeRsaSign, evlRsaSign, NULL}, - {"RSA_VERIFY", 5, 5, setParamsRsaVerify, makeBoolResult, evlRsaVerify, NULL}, {"EXP", 1, 1, setParamsDblDec, makeDblDecResult, evlExp, NULL}, {"FIRST_DAY", 2, 2, setParamsFirstLastDay, makeFirstLastDayResult, evlFirstLastDay, (void*) funFirstDay}, {"FLOOR", 1, 1, setParamsDblDec, makeCeilFloor, evlFloor, NULL}, @@ -5741,6 +5737,12 @@ const SysFunction SysFunction::functions[] = {"RIGHT", 2, 2, setParamsSecondInteger, makeLeftRight, evlRight, NULL}, {"ROUND", 1, 2, setParamsRoundTrunc, makeRound, evlRound, NULL}, {"RPAD", 2, 3, setParamsSecondInteger, makePad, evlPad, (void*) funRPad}, + {"RSA_DECRYPT", 4, 4, setParamsRsaEncrypt, makeRsaDecrypt, evlRsaDecrypt, NULL}, + {"RSA_ENCRYPT", 4, 4, setParamsRsaEncrypt, makeRsaEncrypt, evlRsaEncrypt, NULL}, + {"RSA_PRIVATE", 1, 1, setParamsInteger, makeRsaPrivate, evlRsaPrivate, NULL}, + {"RSA_PUBLIC", 1, 1, setParamsRsaPublic, makeRsaPublic, evlRsaPublic, NULL}, + {"RSA_SIGN", 4, 4, setParamsRsaSign, makeRsaSign, evlRsaSign, NULL}, + {"RSA_VERIFY", 5, 5, setParamsRsaVerify, makeBoolResult, evlRsaVerify, NULL}, {"SIGN", 1, 1, setParamsDblDec, makeShortResult, evlSign, NULL}, {"SIN", 1, 1, setParamsDouble, makeDoubleResult, evlStdMath, (void*) trfSin}, {"SINH", 1, 1, setParamsDouble, makeDoubleResult, evlStdMath, (void*) trfSinh},