From: Timo Sirainen Date: Mon, 12 Oct 2015 14:12:17 +0000 (+0300) Subject: fs-dict: Implemented hex-encoding for values. X-Git-Tag: 2.2.20.rc1~157 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1126bfe4ebe4e2c00ce56292df7c8eb2bfbd9c5c;p=thirdparty%2Fdovecot%2Fcore.git fs-dict: Implemented hex-encoding for values. --- diff --git a/src/lib-fs/fs-dict.c b/src/lib-fs/fs-dict.c index a2c0819ebe..e062b6a656 100644 --- a/src/lib-fs/fs-dict.c +++ b/src/lib-fs/fs-dict.c @@ -4,6 +4,7 @@ #include "buffer.h" #include "str.h" #include "guid.h" +#include "hex-binary.h" #include "base64.h" #include "istream.h" #include "ostream.h" @@ -12,6 +13,7 @@ enum fs_dict_value_encoding { FS_DICT_VALUE_ENCODING_RAW, + FS_DICT_VALUE_ENCODING_HEX, FS_DICT_VALUE_ENCODING_BASE64 }; @@ -58,6 +60,8 @@ fs_dict_init(struct fs *_fs, const char *args, const struct fs_settings *set) encoding_str = t_strdup_until(args, p++); if (strcmp(encoding_str, "raw") == 0) fs->encoding = FS_DICT_VALUE_ENCODING_RAW; + else if (strcmp(encoding_str, "hex") == 0) + fs->encoding = FS_DICT_VALUE_ENCODING_HEX; else if (strcmp(encoding_str, "base64") == 0) fs->encoding = FS_DICT_VALUE_ENCODING_BASE64; else { @@ -196,6 +200,13 @@ static int fs_dict_write_stream_finish(struct fs_file *_file, bool success) case FS_DICT_VALUE_ENCODING_RAW: dict_set(trans, file->key, str_c(file->write_buffer)); break; + case FS_DICT_VALUE_ENCODING_HEX: { + string_t *hex = t_str_new(file->write_buffer->used * 2 + 1); + binary_to_hex_append(hex, file->write_buffer->data, + file->write_buffer->used); + dict_set(trans, file->key, str_c(hex)); + break; + } case FS_DICT_VALUE_ENCODING_BASE64: { const unsigned int base64_size = MAX_BASE64_ENCODED_SIZE(file->write_buffer->used);