fix vec capacity problem

Signed-off-by: zhangwenzhi <zhangwenzhi3@huawei.com>
This commit is contained in:
zhang-wenzhi821 2024-09-02 16:38:28 +08:00
parent 5f500fa90e
commit bb7bc19596
2 changed files with 2 additions and 2 deletions

View File

@ -30,5 +30,6 @@ void Sha256(const uint8_t* input, uint32_t intputLen, uint8_t* output)
LOGE("invalid input for sha256");
return;
}
(void)SHA256((const unsigned char *)input, intputLen, (unsigned char *)output);
}

View File

@ -142,9 +142,8 @@ const SHA256_OUTPUT_LEN: usize = 32;
/// the function to execute sha256 by openssl.
fn sha256_new(message: &[u8]) -> Vec<u8> {
let mut res = Vec::with_capacity(SHA256_OUTPUT_LEN);
let mut res = vec![0; SHA256_OUTPUT_LEN];
unsafe { Sha256(message.as_ptr(), message.len() as u32, res.as_mut_ptr()) }
res
}