diff options
author | whichbug <whichbug@github.com> | 2022-02-11 04:49:41 +0100 |
---|---|---|
committer | whichbug <whichbug@github.com> | 2022-02-22 21:27:30 +0100 |
commit | ac3133450de12ba86c051265fc0f1b12bc57b40c (patch) | |
tree | 0e02aac6f1277627c326c0d4d373af88887d4e30 /lib/yang_wrappers.c | |
parent | Merge pull request #8890 from rameshabhinay/ospf6_auth_trailer (diff) | |
download | frr-ac3133450de12ba86c051265fc0f1b12bc57b40c.tar.xz frr-ac3133450de12ba86c051265fc0f1b12bc57b40c.zip |
isisd: fix #10505 using base64 encoding
Using base64 instead of the raw string to encode
the binary data.
Signed-off-by: whichbug <whichbug@github.com>
Diffstat (limited to 'lib/yang_wrappers.c')
-rw-r--r-- | lib/yang_wrappers.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c index 85aa003db..bee76c6e0 100644 --- a/lib/yang_wrappers.c +++ b/lib/yang_wrappers.c @@ -19,6 +19,7 @@ #include <zebra.h> +#include "base64.h" #include "log.h" #include "lib_errors.h" #include "northbound.h" @@ -677,6 +678,64 @@ void yang_get_default_string_buf(char *buf, size_t size, const char *xpath_fmt, } /* + * Primitive type: binary. + */ +struct yang_data *yang_data_new_binary(const char *xpath, const char *value, + size_t len) +{ + char *value_str; + struct base64_encodestate s; + int cnt; + char *c; + struct yang_data *data; + + value_str = (char *)malloc(len * 2); + base64_init_encodestate(&s); + cnt = base64_encode_block(value, len, value_str, &s); + c = value_str + cnt; + cnt = base64_encode_blockend(c, &s); + c += cnt; + *c = 0; + data = yang_data_new(xpath, value_str); + free(value_str); + return data; +} + +size_t yang_dnode_get_binary_buf(char *buf, size_t size, + const struct lyd_node *dnode, + const char *xpath_fmt, ...) +{ + const char *canon; + size_t cannon_len; + size_t decode_len; + size_t ret_len; + size_t cnt; + char *value_str; + struct base64_decodestate s; + + canon = YANG_DNODE_XPATH_GET_CANON(dnode, xpath_fmt); + cannon_len = strlen(canon); + decode_len = cannon_len; + value_str = (char *)malloc(decode_len); + base64_init_decodestate(&s); + cnt = base64_decode_block(canon, cannon_len, value_str, &s); + + ret_len = size > cnt ? cnt : size; + memcpy(buf, value_str, ret_len); + if (size < cnt) { + char xpath[XPATH_MAXLEN]; + + yang_dnode_get_path(dnode, xpath, sizeof(xpath)); + flog_warn(EC_LIB_YANG_DATA_TRUNCATED, + "%s: value was truncated [xpath %s]", __func__, + xpath); + } + free(value_str); + return ret_len; +} + + +/* * Primitive type: empty. */ struct yang_data *yang_data_new_empty(const char *xpath) |