mrhooray / crc-rs

Rust implementation of CRC(16, 32, 64) with support of various standards
Apache License 2.0
186 stars 49 forks source link

`Crc::new` doesn't need to require a `'static` `Algorithm` reference #68

Open wwylele opened 2 years ago

wwylele commented 2 years ago

This restricts how a program could construct a custom algorithm locally ands use it on the fly.

I noticed that the current internal of Crc holds the reference. Relaxing the lifetime means Crc would need a lifetime parameter as well, which is a breaking change unfortunately. An alternative way is to let Crc clone the data Algorithm has.

akhilles commented 2 years ago

Would https://github.com/mrhooray/crc-rs/pull/69 be sufficient for this? I can't really think of a use case where parameters other than init have to be generated dynamically.

wwylele commented 2 years ago

I think originally when I opened this issue, I was trying to bruteforce an unknown CRC algorithm given data and the end result. In that case, every parameter can be unknown and needs to be constructed on the fly.

But I agree that the init value is the most useful one to allow customizing

nathanaelg commented 1 year ago

@wwylele Did you find a way of doing it? I have a fairly similar use case. I also wasn't really sure how to get around passing in check and residue if you're cycling through and don't have those values pre calculated.

wwylele commented 1 year ago

@nathanaelg No, I didn't. I didn't finish that project for other reasons.

akhilles commented 1 year ago

If the list of possible algorithms is bounded, then could you create a const array of all the ones you want to test? Maybe with a const fn.