Generic_array issue: expected struct `cipher::generic_array::typenum::UInt`, found struct `cipher::generic_array::typenum::UTerm`

Please advise why there is error, all looks good, thanks

struct BlockCrypt {
    key: GenericArray<u8, U8>,
    iv: GenericArray<u8, U8>,
}

impl BlockCrypt {
    fn new(key: &[u8]) -> Self {
        let mut crc = CRCu64::crc64we();

        let iv = {
            crc.digest(&Initial_Vector);
            let result = crc.get_crc_vec_be();
            debug_assert_eq!(result.len(), 8);
            crc.reset();
            result
        };

        let key = {
            crc.digest(key);
            let result = crc.get_crc_vec_be();
            debug_assert_eq!(result.len(), 8);
            crc.reset();
            result
        };

        BlockCrypt {
            key: *GenericArray::from_slice(&key),
            iv: *GenericArray::from_slice(&iv),
        }
    }

fn encrypt(&self, src: &BytesMut) {
        let cipher = Des64Cbc::new_fix(&self.key, &self.iv); // error out for &self.key, see error below
  }
}
mismatched types

expected struct `cipher::generic_array::typenum::UInt`, found struct `cipher::generic_array::typenum::UTerm`

note: expected reference `&cipher::generic_array::GenericArray<u8, cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UTerm, cipher::consts::B1>, cipher::consts::B1>, cipher::consts::B0>, cipher::consts::B0>, cipher::consts::B0>>`
         found reference `&cipher::generic_array::GenericArray<u8, cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UInt<cipher::generic_array::typenum::UTerm, cipher::consts::B1>, cipher::consts::B0>, cipher::consts::B0>, cipher::consts::B0>>`rustc(E0308)

Post the full error please.

Looks like something was expecting GenericArray<u8, U24> and not GenericArray<u8, U8>. What's the definition of Des64Cbc::new_fix?

1 Like

that's the whole error, my dear, thanks anyway

thanks, now I understand why, because it's triple DES, so key size should be 3 * 8

No, it is not the whole error. I assume you copied the pieces from an IDE popup. Please make sure to post the error as printed by cargo build in the future.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.