Comments (5)
The functionality of binary_macros
is exactly what I needed to load the signing keys for JSON web tokens. I am already using data-encoding to decode and encode JSON web tokens, so it would be nice from a consistency standpoint to know that the same implementation is used for the different sources of encoded data in my program.
+1 on merging.
from data-encoding.
Hi,
I am currently trying to finish v2. When it's done I could consider this for v2.1. In the meantime, just so that I understand better what it is about, could you provide me with examples and links to how and when this feature would be useful?
My current understanding is that it permits to decode encoded strings from files, environnement variables, or constant strings at compile time. At first glance this looks outside the scope of data-encoding in the sense that reading files or environnement variables is something orthogonal to the purpose of data-encoding. The compile-time aspect could be considered, but there are already solutions like lazy_static (which is not really compile-time), build.rs, and hard-coded literals. I would prefer to make those tools easier to use, rather than bake their use in data-encoding.
I am actually currently facing such decisions for v2.0.0-rc.2 to allow users to define custom encodings as global variables, with either lazy_static, build.rs, or hard-coded literals (with const fn).
from data-encoding.
Thanks for asking! First of all, my motivation for the crate was that I wanted to bundle a compile-time pepper (in addition to the normal salt) for hashing passwords. It has also other uses, but the main ones I've come up with are bundling crypto stuff like keys, secrets and certs at compile time, while having the file as a nice base64 or hex format, instead of a binary.
Because I'm bundling the data at compile time, a macro is necessary. Of course, there exists macros for bundling binary data at compile time, but if you also want to decode encoded data, it's better to do the decoding at compile time too. The reason is simple: in the case your data is borked, you get the error messages earlier (during compilation, not after deployment) and you get the assurance that at least that part of the app is fine.
So, one could bundle the raw data using the macros from the std, but they would still be in an ASCII format. Using this library as a macro is necessary if you want to end up with a binary with the ASCII already decoded into the final binary data.
from data-encoding.
Hi Pyry,
I created #15 which adds a data-encoding-macro crate with the following macros:
- A set of macros to define a compile-time byte array using common encodings (
base64
,base32
,hexlower
, etc.) to decode a string literal - A generic
decode
macro that does the same for custom encodings - A
new_encoding
macro to define a compile-time custom encoding
The main differences that I can see with binary_macros
are:
- It requires a nightly compiler (I should take a look at
proc-macro-hack
when I get time) - It defines the compile-time byte array directly instead of defining it in a hidden scope and returning a reference
If you have some time, I could use your input before submitting. Here are the two files that describe how to use those macros:
- https://github.com/ia0/data-encoding/pull/15/files#diff-f87df0c0c8471eddc7a5449f877b1f8d
- https://github.com/ia0/data-encoding/pull/15/files#diff-7d13849c3e2602b35ad820d75df23d34
I'll probably submit this week-end and do further modifications if needed.
Thanks,
Julien
from data-encoding.
I ended up closing the differences with the binary_macros
crate:
- There is now a "stable" feature (enabled by default) relying on
proc-macro-hack
to permit usage with a stable compiler. - The simple macros return a slice (there is still a macro to build an array, but only in nightly).
from data-encoding.
Related Issues (20)
- Consider `check_trailing_bits=false` for BASE64_MIME decoder HOT 1
- Release 3.0.0
- Support Nix base32 HOT 1
- feature `std` leaking when using macro in no_std env HOT 7
- Missing a new line and decode error HOT 2
- Rust 2021 edition is a major, not a "patch" change HOT 6
- Removing dependency on syn HOT 7
- Make `{encode,decode}_len` const fns? HOT 4
- Encode into an "impl std::fmt::Write" and/or "impl std::io::Write" HOT 5
- Breaking change wish list
- Use doc_auto_cfg once stable HOT 2
- Use as_chunks family of functions once stable
- Internal symbols array is publicly exposed and unsound HOT 4
- Deny warnings in rustdoc
- Partial encoding with padding HOT 3
- Question about Specification HOT 6
- Release 2.5.0
- SIMD optimization HOT 4
- `Encoding::encode_mut` is very code-size heavy HOT 15
- feature request - base58 d/encoding HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data-encoding.