rusticata / der-parser

BER/DER parser written in pure Rust. Fast, zero-copy, safe.
Apache License 2.0
84 stars 29 forks source link

Add no_std support. #50

Closed yuguorui closed 3 years ago

yuguorui commented 3 years ago

You may need to accept https://github.com/rusticata/rusticata-macros/pull/3 first to use macro newtype_enum.

yuguorui commented 3 years ago

Seems some checks are not passed, I will check that.

chifflier commented 3 years ago

Hi, Thanks for your PR! I am interesting in adding no_std support, and originally I thought Cow would be a problem, and it's nice to have a solution. The most important error seems to be:

Error:  --> src/ber/serialize.rs:9:11
  |
9 | use core::io::Write;
  |           ^^ could not find `io` in `core`

Thanks!

yuguorui commented 3 years ago

Please note that other upstream repo (such as oid-registry) may not compile due to current changes, I am working on it.

chifflier commented 3 years ago

Thanks for the PR update The rustfmt error can be ignored, I'll fix it later

One question: how can we test that the crate is no_std-compliant? (and its dependencies?) I'd like to add that to the CI, to ensure no_std support is not broken by later commits

yuguorui commented 3 years ago

Thanks for the PR update The rustfmt error can be ignored, I'll fix it later

One question: how can we test that the crate is no_std-compliant? (and its dependencies?) I'd like to add that to the CI, to ensure no_std support is not broken by later commits

I think this could be checked by cargo test --no-default-features? But as I said at the beginning, in this case we will encounter errors related to newtype_enum.

$ cargo test --no-default-features
   Compiling der-parser v5.1.0 (/mnt/data1/Code/der-parser)
error[E0433]: failed to resolve: could not find `std` in the list of imported crates
  --> src/ber/ber.rs:47:1
   |
47 | / newtype_enum! {
48 | | impl debug BerTag {
49 | |     EndOfContent = 0x0,
50 | |     Boolean = 0x1,
...  |
83 | | }
84 | | }
   | |_^ could not find `std` in the list of imported crates
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
yuguorui commented 3 years ago

Please note that other upstream repo (such as oid-registry) may not compile due to current changes, I am working on it.

Now, oid-registry can be compiled directly without any modification.

chifflier commented 3 years ago

I think this could be checked by cargo test --no-default-features?

Indeed, I don't know why I was confused.

But as I said at the beginning, in this case we will encounter errors related to newtype_enum.

I encountered this one while testing another crate. I'll update rusticata-macros to provide a no_std-friendly version of the macro. I'm taking care of this one.

BTW, it's really annoying to have to add extern crate core, this makes providing an impl in the macro for both std and no_std quite complex :/

chifflier commented 3 years ago

I encountered this one while testing another crate. I'll update rusticata-macros to provide a no_std-friendly version of the macro. I'm taking care of this one.

Fixed in (released) rusticata-macros 3.1.0

chifflier commented 3 years ago

I'm merging this now, and will add some commits (rustfmt, add no_std to CI, and maybe update the exports for alloc). Thanks for your contribution!