Skip to content

Commit a0e8c2f

Browse files
committed
lyb UPDATE store hash algorithm used
1 parent 206e72a commit a0e8c2f

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/lyb.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @author Michal Vasko <[email protected]>
44
* @brief Header for LYB format printer & parser
55
*
6-
* Copyright (c) 2020 - 2022 CESNET, z.s.p.o.
6+
* Copyright (c) 2020 - 2025 CESNET, z.s.p.o.
77
*
88
* This source code is licensed under BSD 3-Clause License (the "License").
99
* You may not use this file except in compliance with the License.
@@ -111,10 +111,20 @@ void lyd_lyb_ctx_free(struct lyd_ctx *lydctx);
111111
#define LYB_SIBLING_STEP 4
112112

113113
/* current LYB format version */
114-
#define LYB_VERSION_NUM 0x05
114+
#define LYB_HEADER_VERSION_NUM 0x06
115115

116116
/* LYB format version mask of the header byte */
117-
#define LYB_VERSION_MASK 0x0F
117+
#define LYB_HEADER_VERSION_MASK 0x0F
118+
119+
/* current LYB hash function */
120+
#ifdef LY_XXHASH_SUPPORT
121+
# define LYB_HEADER_HASH_ALG 0x20 /**< xxhash */
122+
#else
123+
# define LYB_HEADER_HASH_ALG 0x10 /**< one-at-a-time hash */
124+
#endif
125+
126+
/* LYB hash algorithm mask of the header byte */
127+
#define LYB_HEADER_HASH_MASK 0x30
118128

119129
/**
120130
* LYB schema hash constants

src/parser_lyb.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,12 +1657,18 @@ lyb_parse_header(struct lylyb_ctx *lybctx)
16571657
{
16581658
uint8_t byte = 0;
16591659

1660-
/* version, future flags */
1660+
/* version, hash algorithm (flags) */
16611661
lyb_read((uint8_t *)&byte, sizeof byte, lybctx);
16621662

1663-
if ((byte & LYB_VERSION_MASK) != LYB_VERSION_NUM) {
1663+
if ((byte & LYB_HEADER_VERSION_MASK) != LYB_HEADER_VERSION_NUM) {
16641664
LOGERR(lybctx->ctx, LY_EINVAL, "Invalid LYB format version \"0x%02x\", expected \"0x%02x\".",
1665-
byte & LYB_VERSION_MASK, LYB_VERSION_NUM);
1665+
byte & LYB_HEADER_VERSION_MASK, LYB_HEADER_VERSION_NUM);
1666+
return LY_EINVAL;
1667+
}
1668+
1669+
if ((byte & LYB_HEADER_HASH_MASK) != LYB_HEADER_HASH_ALG) {
1670+
LOGERR(lybctx->ctx, LY_EINVAL, "Different LYB format hash algorithm \"0x%02x\" used, expected \"0x%02x\".",
1671+
byte & LYB_HEADER_HASH_MASK, LYB_HEADER_HASH_ALG);
16661672
return LY_EINVAL;
16671673
}
16681674

src/printer_lyb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,9 @@ lyb_print_header(struct ly_out *out)
611611
{
612612
uint8_t byte = 0;
613613

614-
/* version, future flags */
615-
byte |= LYB_VERSION_NUM;
614+
/* version, hash algorithm (flags) */
615+
byte |= LYB_HEADER_VERSION_NUM;
616+
byte |= LYB_HEADER_HASH_ALG;
616617

617618
LY_CHECK_RET(ly_write_(out, (char *)&byte, 1));
618619

0 commit comments

Comments
 (0)