Hello There ,
I used from compiler to give a meaningful and pretty helpful error messages, But recently i faced this.
error[E0308]: mismatched types
--> src/identity_key.rs:80:19
|
80 | public_key: pub_key,
| ^^^^^^^ expected opaque type, found a different opaque type
|
= note: expected type `impl ecc::ECKey` (opaque type)
found type `impl ecc::ECKey` (opaque type)
which left me wondering, what is just happened ?
Here is a little bit information about what kind of project that i'm working on:
I'm working on porting the libsignal-protocol-java from java to pure rust.
Here is the repo libsignal-protocol-rs the pure-rust
brach.
the master
branch is just a wrapper around the libsignal-protocol-c which is fine, but it has a lot of unsafe code.
anyway, here is a little snippet from where the errors happens
// i have this trait here, an abstraction over the Keys
trait ECKey {
fn serialize(&self) -> Vec<u8>;
fn get_type(&self) -> u8;
fn get_key(&self) -> Vec<u8>;
}
and here is a simplified version of it's usage and where is the error happens !.
/// Holder for public and private identity key pair.
pub struct IdentityKeyPair<E: ECKey> {
public_key: E,
private_key: E,
}
impl<E: ECKey> IdentityKeyPair<E> {
pub fn new(public_key: E, private_key: E) -> IdentityKeyPair<E> {
IdentityKeyPair {
public_key,
private_key,
}
}
pub fn from_raw(serialized: &[u8]) -> IdentityKeyPair<impl ECKey> {
// ... some code...
// ignore the `public_key` and `private_key` for now, they are a `Vec<u8>`
let pub_key = Curve::decode_point(&public_key, 0)?; // -> impl ECKey
let prv_key = Curve::decode_private_point(&private_key); // -> impl ECKey
let pair = IdentityKeyPair {
private_key: prv_key, // this ok here
public_key: pub_key, // but this a error in compile
};
pair
}
}
For the full code see here.
Thank you