Commit Graph

28 Commits (master)

Author SHA1 Message Date
Philippe Antoine 3bc2a14fbf rust: fix clippy 1.85 precedence warnings
warning: operator precedence can trip the unwary
   --> src/jsonbuilder.rs:781:36
    |
781 |                 buf[offset] = HEX[(x >> 4 & 0xf) as usize];
    |                                    ^^^^^^^^^^^^ help: consider parenthesizing your expression: `(x >> 4) & 0xf`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#precedence
    = note: `#[warn(clippy::precedence)]` on by default
1 week ago
Jason Ish 604e3c7422 rust/jsonbuilder: make set_uint generic over Into<u64>
Allow `set_uint` to accept any number value that can be converted to a
u64. Prevents callers from having to do `as u64`.

This required fixing up any callers that used `.into()` to just pass in
their value without the into conversion.

Most calls using `as u64` can have that cast removed, with the exception
of `usize` values which must still be cast is conversion can't be
guaranteed to be non-fallible.
2 months ago
Shivani Bhardwaj e93743a094 rust/base64: upgrade crate to latest
base64 crate is updated to the latest version 0.22.1. This came with
several API changes which are applied to the code. The old calls have
been replaced with the newer calls.

This was done following the availability of better fns to directly
decode into slices/vectors as needed and also that previous version was
too old.
Along with this change, update the Cargo.lock.in to reflect all changes
in the package versions.

Task 7219
6 months ago
Sascha Steinbiss e047ad25e2 mqtt: run rustfmt 8 months ago
Sascha Steinbiss dd972f72dd rust: add JsonBuilder::set_string_limited() 8 months ago
Jason Ish 71f59e529c jsonbuilder: fix serialization of nan and inf
When outputting a float, check if its infinity, or not a number and
output a null instead.

Using a null was chosen as this is what serde_yaml, Firefox, Chrome,
Node, etc. do.

Ticket: #6921
11 months ago
Philippe Antoine c4b8fb7aca ssh: limit length for banner logs
Ticket: 6770
12 months ago
Victor Julien b8440a0917 jsonbuilder: add set_int for signed ints
Bug: #6615
1 year ago
Daniel Olatunji 5c0af0b203 rust/doc: add docstring to rust module files.
Issue: #4584
1 year ago
Jason Ish 33827beae5 jsonbuilder: check buffer growth
Use try_reserve before growing the internal buffer, and the internal
state vector. This allows allocation errors to be caught and an error
returned instead of just aborting the process.

Ticket: #6057
2 years ago
Jason Ish 95cfc2b34f jsonbuilder: rustfmt
Some very minor changes to formatting.
2 years ago
Jason Ish 4a0859beeb jsonbuilder: add append_hex - add hex to array
New method, append_hex to add a byte array to a JSON array in hex
encoding.
2 years ago
Jason Ish 565da0d0af rust: fix clippy lints for clippy::redundant_field_names 2 years ago
Jason Ish c4034dafa1 rust: fix clippy lints for clippy::derive_partial_eq_without_eq 2 years ago
Jason Ish 2a42386c28 rust: fix clippy lint for null comparison
Use .is_null() instead of checking for equality against
std::ptr::null().
2 years ago
Philippe Antoine c4d9cb02ec util: better hex print function
Without dangerous snprintf pattern identified by CodeQL
even if this pattern is not a problem in those precise cases,
it may easily get copy pasted in a dangerous place, so better
get rid of it and make CodeQL happy
3 years ago
Jason Ish 8181030f72 jsonbuilder: add methods to encode values as base64
Add new methods to set a value as a base64 encoded string of
a byte array. This uses the Rust base64 crate and encodes
directly into the JsonBuilder buffer with no intermediate
buffer required.

jb_set_base64: set a field on an object
jb_append_base64: append a value to an array
3 years ago
Sam Muhammed 23768c7181 rust(lint): use is_null() instead of ptr::null()
Bug: #4594
3 years ago
Philippe Antoine cb30772372 style: remove latest warnings
about unused variables
3 years ago
Victor Julien b99ffd9ece eve: remove unused jansson code 5 years ago
Shivani Bhardwaj 35362b7bfa jsonbuilder: run test if not debug-validate 5 years ago
Jason Ish 03efbccfe6 jsonbuilder: set_float, append_float methods
New methods for setting and appending float values.
5 years ago
Jason Ish 07e88a7479 jsonbuilder: add debug_validate to state
If debug validation is enabled, panic on invalid state errors.

For example, calling close on an already closed jsonbuilder
object.
5 years ago
Jason Ish a545cdef6a jsonbuilder: setter for formatted data
Create a method to set preformatted data that contains the key
and the value already formatted.

This is an optimization for static data.
5 years ago
Jason Ish e3b7c58218 jsonbuilder: export {set,append}_string_from_bytes to C 5 years ago
Jason Ish f184bcc10e jsonbuilder: use Box::from_raw instead of transmute to free
I think this is a bad use of transmute, while the end result
is the same, Box::from_raw is more correct as we created this
pointer with Box::into_raw.
5 years ago
Jason Ish 60bfbd43fd jsonbuilder: add reset marks
Add methods to get the state of a JsonBuilder (called a mark),
then allow restoring to the mark.
5 years ago
Jason Ish 942dd08654 jsonbuilder: new module for generating json
JsonBuilder is a Rust module for creating JSON output. Unlike
Jansson, the final JSON string is built up as items are added,
instead of building up an object tree and rendering it when
done.

The idea is to create a more efficient JSON serializer instead
of a flexible one.
5 years ago