diff --git a/doc/xml/release.xml b/doc/xml/release.xml index c9d4fde18..bbafa1981 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -13,6 +13,17 @@ + + + + + + + +

Add helper function for adding CipherBlock filters to groups.

+
+
+
diff --git a/src/Makefile.in b/src/Makefile.in index 0c5318ba7..2c5428049 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -305,7 +305,7 @@ common/compress/gzip/compress.o: common/compress/gzip/compress.c build.auto.h co common/compress/gzip/decompress.o: common/compress/gzip/decompress.c build.auto.h common/assert.h common/compress/gzip/common.h common/compress/gzip/decompress.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h $(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c common/compress/gzip/decompress.c -o common/compress/gzip/decompress.o -common/crypto/cipherBlock.o: common/crypto/cipherBlock.c build.auto.h common/assert.h common/crypto/cipherBlock.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h +common/crypto/cipherBlock.o: common/crypto/cipherBlock.c build.auto.h common/assert.h common/crypto/cipherBlock.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/filter.intern.h common/io/filter/group.h common/log.h common/logLevel.h common/macro.h common/memContext.h common/object.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h $(CC) $(CPPFLAGS) $(CFLAGS) $(CMAKE) -c common/crypto/cipherBlock.c -o common/crypto/cipherBlock.o common/crypto/common.o: common/crypto/common.c build.auto.h common/assert.h common/crypto/common.h common/debug.h common/error.auto.h common/error.h common/log.h common/logLevel.h common/stackTrace.h common/type/convert.h diff --git a/src/common/crypto/cipherBlock.c b/src/common/crypto/cipherBlock.c index 22a1547d1..25bef08b1 100644 --- a/src/common/crypto/cipherBlock.c +++ b/src/common/crypto/cipherBlock.c @@ -460,3 +460,25 @@ cipherBlockNewVar(const VariantList *paramList) (CipherMode)varUIntForce(varLstGet(paramList, 0)), (CipherType)varUIntForce(varLstGet(paramList, 1)), BUFSTR(varStr(varLstGet(paramList, 2))), varLstGet(paramList, 3) == NULL ? NULL : varStr(varLstGet(paramList, 3))); } + +/*********************************************************************************************************************************** +Helper function to add a block cipher to an io object +***********************************************************************************************************************************/ +IoFilterGroup * +cipherBlockFilterGroupAdd(IoFilterGroup *filterGroup, CipherType type, CipherMode mode, const String *pass) +{ + FUNCTION_LOG_BEGIN(logLevelTrace); + FUNCTION_LOG_PARAM(IO_FILTER_GROUP, filterGroup); + FUNCTION_LOG_PARAM(ENUM, type); + FUNCTION_LOG_PARAM(ENUM, mode); + FUNCTION_LOG_PARAM(STRING, pass); + FUNCTION_LOG_END(); + + ASSERT(filterGroup != NULL); + ASSERT((type == cipherTypeNone && pass == NULL) || (type != cipherTypeNone && pass != NULL)); + + if (type != cipherTypeNone) + ioFilterGroupAdd(filterGroup, cipherBlockNew(mode, type, BUFSTR(pass), NULL)); + + FUNCTION_LOG_RETURN(IO_FILTER_GROUP, filterGroup); +} diff --git a/src/common/crypto/cipherBlock.h b/src/common/crypto/cipherBlock.h index 3a8964e65..ad9ef7ef2 100644 --- a/src/common/crypto/cipherBlock.h +++ b/src/common/crypto/cipherBlock.h @@ -4,7 +4,7 @@ Block Cipher Header #ifndef COMMON_CRYPTO_CIPHERBLOCK_H #define COMMON_CRYPTO_CIPHERBLOCK_H -#include "common/io/filter/filter.h" +#include "common/io/filter/group.h" #include "common/crypto/common.h" /*********************************************************************************************************************************** @@ -19,4 +19,9 @@ Constructor IoFilter *cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const String *digestName); IoFilter *cipherBlockNewVar(const VariantList *paramList); +/*********************************************************************************************************************************** +Helper functions +***********************************************************************************************************************************/ +IoFilterGroup *cipherBlockFilterGroupAdd(IoFilterGroup *filterGroup, CipherType type, CipherMode mode, const String *pass); + #endif diff --git a/test/src/module/common/cryptoTest.c b/test/src/module/common/cryptoTest.c index c4e70e24d..f9dc27942 100644 --- a/test/src/module/common/cryptoTest.c +++ b/test/src/module/common/cryptoTest.c @@ -285,6 +285,18 @@ testRun(void) TEST_ERROR(ioFilterProcessInOut(blockDecryptFilter, NULL, decryptBuffer), CryptoError, "unable to flush"); ioFilterFree(blockDecryptFilter); + + // Helper function + // ------------------------------------------------------------------------------------------------------------------------- + IoFilterGroup *filterGroup = ioFilterGroupNew(); + + TEST_RESULT_PTR( + cipherBlockFilterGroupAdd(filterGroup, cipherTypeNone, cipherModeEncrypt, NULL), filterGroup, " no filter add"); + TEST_RESULT_UINT(ioFilterGroupSize(filterGroup), 0, " check no filter add"); + + TEST_RESULT_VOID( + cipherBlockFilterGroupAdd(filterGroup, cipherTypeAes256Cbc, cipherModeEncrypt, STRDEF("X")), " filter add"); + TEST_RESULT_UINT(ioFilterGroupSize(filterGroup), 1, " check filter add"); } // *****************************************************************************************************************************