krb5 commit: Add k5-buf.h helpers for serializing integers
Greg Hudson <[email protected]>
| Newsgroups | gmane.comp.encryption.kerberos.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://github.com/krb5/krb5/commit/c3e08616316aff2314feb9358c5c02f9a61a67b9 commit c3e08616316aff2314feb9358c5c02f9a61a67b9 Author: Greg Hudson <[email protected]> Date: Wed Nov 13 00:53:24 2019 -0500 Add k5-buf.h helpers for serializing integers src/include/k5-buf.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/src/include/k5-buf.h b/src/include/k5-buf.h index 48e2a7d..f2cdb0c 100644 --- a/src/include/k5-buf.h +++ b/src/include/k5-buf.h @@ -108,4 +108,58 @@ int k5_buf_status(struct k5buf *buf); */ void k5_buf_free(struct k5buf *buf); +static inline void +k5_buf_add_uint16_be(struct k5buf *buf, uint16_t val) +{ + void *p = k5_buf_get_space(buf, 2); + + if (p != NULL) + store_16_be(val, p); +} + +static inline void +k5_buf_add_uint16_le(struct k5buf *buf, uint16_t val) +{ + void *p = k5_buf_get_space(buf, 2); + + if (p != NULL) + store_16_le(val, p); +} + +static inline void +k5_buf_add_uint32_be(struct k5buf *buf, uint32_t val) +{ + void *p = k5_buf_get_space(buf, 4); + + if (p != NULL) + store_32_be(val, p); +} + +static inline void +k5_buf_add_uint32_le(struct k5buf *buf, uint32_t val) +{ + void *p = k5_buf_get_space(buf, 4); + + if (p != NULL) + store_32_le(val, p); +} + +static inline void +k5_buf_add_uint64_be(struct k5buf *buf, uint64_t val) +{ + void *p = k5_buf_get_space(buf, 8); + + if (p != NULL) + store_64_be(val, p); +} + +static inline void +k5_buf_add_uint64_le(struct k5buf *buf, uint64_t val) +{ + void *p = k5_buf_get_space(buf, 8); + + if (p != NULL) + store_64_le(val, p); +} + #endif /* K5_BUF_H */