mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: sample: add the sha1 converter
This converter can be used to generate a SHA1 digest from binary type sample. The result is a binary sample with length of 20 bytes.
This commit is contained in:
parent
7389dd086c
commit
6e5a9ca948
@ -12912,6 +12912,10 @@ set-var(<var name>)
|
|||||||
This prefix is followed by a name. The separator is a '.'. The name may only
|
This prefix is followed by a name. The separator is a '.'. The name may only
|
||||||
contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.
|
contain characters 'a-z', 'A-Z', '0-9', '.' and '_'.
|
||||||
|
|
||||||
|
sha1
|
||||||
|
Converts a binary input sample to a SHA1 digest. The result is a binary
|
||||||
|
sample with length of 20 bytes.
|
||||||
|
|
||||||
sub(<value>)
|
sub(<value>)
|
||||||
Subtracts <value> from the input value of type signed integer, and returns
|
Subtracts <value> from the input value of type signed integer, and returns
|
||||||
the result as an signed integer. Note: in order to subtract the input from
|
the result as an signed integer. Note: in order to subtract the input from
|
||||||
|
20
src/sample.c
20
src/sample.c
@ -33,6 +33,7 @@
|
|||||||
#include <proto/stick_table.h>
|
#include <proto/stick_table.h>
|
||||||
#include <proto/vars.h>
|
#include <proto/vars.h>
|
||||||
|
|
||||||
|
#include <import/sha1.h>
|
||||||
#include <import/xxhash.h>
|
#include <import/xxhash.h>
|
||||||
|
|
||||||
/* sample type names */
|
/* sample type names */
|
||||||
@ -1504,6 +1505,24 @@ static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp, v
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sample_conv_sha1(const struct arg *arg_p, struct sample *smp, void *private)
|
||||||
|
{
|
||||||
|
blk_SHA_CTX ctx;
|
||||||
|
struct chunk *trash = get_trash_chunk();
|
||||||
|
|
||||||
|
memset(&ctx, 0, sizeof(ctx));
|
||||||
|
|
||||||
|
blk_SHA1_Init(&ctx);
|
||||||
|
blk_SHA1_Update(&ctx, smp->data.u.str.str, smp->data.u.str.len);
|
||||||
|
blk_SHA1_Final((unsigned char *)trash->str, &ctx);
|
||||||
|
|
||||||
|
trash->len = 20;
|
||||||
|
smp->data.u.str = *trash;
|
||||||
|
smp->data.type = SMP_T_BIN;
|
||||||
|
smp->flags &= ~SMP_F_CONST;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp, void *private)
|
static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp, void *private)
|
||||||
{
|
{
|
||||||
struct chunk *trash = get_trash_chunk();
|
struct chunk *trash = get_trash_chunk();
|
||||||
@ -2756,6 +2775,7 @@ static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
|||||||
{ "field", sample_conv_field, ARG2(2,SINT,STR), sample_conv_field_check, SMP_T_STR, SMP_T_STR },
|
{ "field", sample_conv_field, ARG2(2,SINT,STR), sample_conv_field_check, SMP_T_STR, SMP_T_STR },
|
||||||
{ "word", sample_conv_word, ARG2(2,SINT,STR), sample_conv_field_check, SMP_T_STR, SMP_T_STR },
|
{ "word", sample_conv_word, ARG2(2,SINT,STR), sample_conv_field_check, SMP_T_STR, SMP_T_STR },
|
||||||
{ "regsub", sample_conv_regsub, ARG3(2,REG,STR,STR), sample_conv_regsub_check, SMP_T_STR, SMP_T_STR },
|
{ "regsub", sample_conv_regsub, ARG3(2,REG,STR,STR), sample_conv_regsub_check, SMP_T_STR, SMP_T_STR },
|
||||||
|
{ "sha1", sample_conv_sha1, 0, NULL, SMP_T_BIN, SMP_T_BIN },
|
||||||
|
|
||||||
{ "and", sample_conv_binary_and, ARG1(1,STR), check_operator, SMP_T_SINT, SMP_T_SINT },
|
{ "and", sample_conv_binary_and, ARG1(1,STR), check_operator, SMP_T_SINT, SMP_T_SINT },
|
||||||
{ "or", sample_conv_binary_or, ARG1(1,STR), check_operator, SMP_T_SINT, SMP_T_SINT },
|
{ "or", sample_conv_binary_or, ARG1(1,STR), check_operator, SMP_T_SINT, SMP_T_SINT },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user