mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 09:56:35 +03:00
refactor: remove sprintf
This commit is contained in:
19
src/pgp.rs
19
src/pgp.rs
@@ -10,7 +10,6 @@ use pgp::composed::{
|
||||
use pgp::crypto::{HashAlgorithm, SymmetricKeyAlgorithm};
|
||||
use pgp::types::{CompressionAlgorithm, KeyTrait, SecretKeyTrait, StringToKey};
|
||||
use rand::thread_rng;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::dc_tools::*;
|
||||
use crate::key::*;
|
||||
@@ -329,21 +328,3 @@ pub fn dc_pgp_symm_decrypt(
|
||||
.ok()
|
||||
.and_then(|content| content)
|
||||
}
|
||||
|
||||
/// Calculate the SHA256 hash of the given bytes.
|
||||
pub fn dc_hash_sha256(bytes_ptr: *const u8, bytes_len: libc::size_t) -> (*mut u8, libc::size_t) {
|
||||
assert!(!bytes_ptr.is_null());
|
||||
assert!(bytes_len > 0);
|
||||
|
||||
let bytes = unsafe { std::slice::from_raw_parts(bytes_ptr, bytes_len) };
|
||||
let result = Sha256::digest(bytes);
|
||||
|
||||
let mut r = result.to_vec();
|
||||
r.shrink_to_fit();
|
||||
|
||||
let ptr = r.as_ptr();
|
||||
let len = r.len();
|
||||
std::mem::forget(r);
|
||||
|
||||
(ptr as *mut _, len)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user