I wrote this function with hmac 0.11, digest 0.9:
fn hmac<D>(secret: AnyLuaValue, msg: AnyLuaValue) -> Result<AnyLuaValue>
where
D: Update + BlockInput + FixedOutput + Reset + Default + Clone,
D::BlockSize: ArrayLength<u8> + Clone,
D::OutputSize: ArrayLength<u8>,
{
let secret = byte_array(secret)?;
let msg = byte_array(msg)?;
let mut mac = match Hmac::<D>::new_from_slice(&secret) {
Ok(mac) => mac,
Err(_) => bail!("Invalid key length"),
};
mac.update(&msg);
let result = mac.finalize();
Ok(lua_bytes(&result.into_bytes()))
}
I'm having trouble porting this to the latest version of those crates, I'm getting errors like this:
error[E0599]: the function or associated item `new_from_slice` exists for struct `CoreWrapper<HmacCore<D>>`, but its trait bounds were not satisfied
--> src/runtime.rs:161:36
|
161 | let mut mac = match Hmac::<D>::new_from_slice(&secret) {
| ^^^^^^^^^^^^^^ function or associated item cannot be called on `CoreWrapper<HmacCore<D>>` due to unsatisfied trait bounds
|
::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/digest-0.10.3/src/core_api/wrapper.rs:22:1
|
22 | / pub struct CoreWrapper<T>
23 | | where
24 | | T: BufferKindUser,
25 | | T::BlockSize: IsLess<U256>,
... |
29 | | buffer: BlockBuffer<T::BlockSize, T::BufferKind>,
30 | | }
| | -
| | |
| | doesn't satisfy `CoreWrapper<HmacCore<D>>: FixedOutput`
| | doesn't satisfy `CoreWrapper<HmacCore<D>>: MacMarker`
| |_doesn't satisfy `CoreWrapper<HmacCore<D>>: Mac`
| doesn't satisfy `CoreWrapper<HmacCore<D>>: Update`
|
= note: the following trait bounds were not satisfied:
`CoreWrapper<HmacCore<D>>: Update`
which is required by `CoreWrapper<HmacCore<D>>: Mac`
`CoreWrapper<HmacCore<D>>: FixedOutput`
which is required by `CoreWrapper<HmacCore<D>>: Mac`
`CoreWrapper<HmacCore<D>>: MacMarker`
which is required by `CoreWrapper<HmacCore<D>>: Mac`
`&CoreWrapper<HmacCore<D>>: Update`
which is required by `&CoreWrapper<HmacCore<D>>: Mac`
`&CoreWrapper<HmacCore<D>>: FixedOutput`
which is required by `&CoreWrapper<HmacCore<D>>: Mac`
`&CoreWrapper<HmacCore<D>>: MacMarker`
which is required by `&CoreWrapper<HmacCore<D>>: Mac`
`&CoreWrapper<HmacCore<D>>: InnerInit`
which is required by `&CoreWrapper<HmacCore<D>>: digest::KeyInit`
`&CoreWrapper<HmacCore<D>>: InnerUser`
which is required by `&CoreWrapper<HmacCore<D>>: digest::KeyInit`
`&mut CoreWrapper<HmacCore<D>>: Update`
which is required by `&mut CoreWrapper<HmacCore<D>>: Mac`
`&mut CoreWrapper<HmacCore<D>>: FixedOutput`
which is required by `&mut CoreWrapper<HmacCore<D>>: Mac`
`&mut CoreWrapper<HmacCore<D>>: MacMarker`
which is required by `&mut CoreWrapper<HmacCore<D>>: Mac`
`&mut CoreWrapper<HmacCore<D>>: InnerInit`
which is required by `&mut CoreWrapper<HmacCore<D>>: digest::KeyInit`
`&mut CoreWrapper<HmacCore<D>>: InnerUser`
which is required by `&mut CoreWrapper<HmacCore<D>>: digest::KeyInit`
error[E0277]: the trait bound `<D as digest::core_api::CoreProxy>::Core: FixedOutputCore` is not satisfied
--> src/runtime.rs:161:25
|
161 | let mut mac = match Hmac::<D>::new_from_slice(&secret) {
| ^^^^^^^^^ the trait `FixedOutputCore` is not implemented for `<D as digest::core_api::CoreProxy>::Core`
|
= note: required because of the requirements on the impl of `BlockSizeUser` for `HmacCore<D>`
help: consider further restricting the associated type
|
142 | <D as digest::core_api::CoreProxy>::Core: HashMarker, <D as digest::core_api::CoreProxy>::Core: FixedOutputCore
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
warning: unused import: `Update`
--> src/runtime.rs:9:22
|
9 | use digest::{Digest, Update, FixedOutput, Reset};
| ^^^^^^
warning: unused import: `Mac`
--> src/runtime.rs:11:18
|
11 | use hmac::{Hmac, Mac};
| ^^^
warning: unused import: `typenum`
--> src/runtime.rs:130:5
|
130 | use typenum::*;
| ^^^^^^^
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
warning: `authoscope` (lib) generated 6 warnings
error: could not compile `authoscope` due to 2 previous errors; 6 warnings emitted
but the suggested code errors like this:
error[E0277]: the trait bound `<<D as digest::core_api::CoreProxy>::Core as BlockSizeUser>::BlockSize: Cmp<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>` is not satisfied
--> src/runtime.rs:142:64
|
142 | <D as digest::core_api::CoreProxy>::Core: HashMarker + FixedOutputCore,
| ^^^^^^^^^^^^^^^ the trait `Cmp<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>` is not implemented for `<<D as digest::core_api::CoreProxy>::Core as BlockSizeUser>::BlockSize`
|
= note: required because of the requirements on the impl of `IsLess<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>` for `<<D as digest::core_api::CoreProxy>::Core as BlockSizeUser>::BlockSize`
help: consider further restricting the associated type
|
142 | <D as digest::core_api::CoreProxy>::Core: HashMarker + FixedOutputCore, <<D as digest::core_api::CoreProxy>::Core as BlockSizeUser>::BlockSize: Cmp<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0283]: type annotations needed
--> src/runtime.rs:142:64
|
142 | <D as digest::core_api::CoreProxy>::Core: HashMarker + FixedOutputCore,
| ^^^^^^^^^^^^^^^ cannot infer type
|
= note: multiple `impl`s satisfying `<<D as digest::core_api::CoreProxy>::Core as BlockSizeUser>::BlockSize: IsLessPrivate<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, _>` found in the `typenum` crate:
- impl<A, B> IsLessPrivate<B, digest::typenum::Equal> for A;
- impl<A, B> IsLessPrivate<B, digest::typenum::Greater> for A;
- impl<A, B> IsLessPrivate<B, digest::typenum::Less> for A;
= note: required because of the requirements on the impl of `IsLess<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<digest::typenum::UInt<UTerm, B1>, B0>, B0>, B0>, B0>, B0>, B0>, B0>, B0>>` for `<<D as digest::core_api::CoreProxy>::Core as BlockSizeUser>::BlockSize`
Some errors have detailed explanations: E0277, E0283.
For more information about an error, try `rustc --explain E0277`.
warning: `authoscope` (lib) generated 3 warnings
error: could not compile `authoscope` due to 2 previous errors; 3 warnings emitted
any pointers?