pgp: refresh documentation, fix encryption/signing

Closes #259
pull/260/head
Manos Pitsidianakis 2023-07-15 19:32:39 +03:00
parent cf9a04a591
commit ab418c1d39
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
3 changed files with 242 additions and 332 deletions

File diff suppressed because it is too large Load Diff

View File

@ -904,7 +904,7 @@ impl Component for Composer {
),
(
get_x(bottom_right!(header_area)),
get_y(upper_left!(attachment_area)) - 1,
get_y(upper_left!(attachment_area)).saturating_sub(1),
),
);
@ -947,7 +947,7 @@ impl Component for Composer {
(
(
get_x(bottom_right).saturating_sub(mid),
get_y(upper_left) - 1,
get_y(upper_left).saturating_sub(1),
),
bottom_right,
),

View File

@ -33,6 +33,7 @@ use std::{
io::{AsRawFd, RawFd},
},
path::Path,
pin::Pin,
sync::{Arc, Mutex},
};
@ -412,6 +413,7 @@ impl Context {
pub fn new_data_mem(&self, bytes: &[u8]) -> Result<Data> {
let mut ptr = core::ptr::null_mut();
let bytes: Pin<Vec<u8>> = Pin::new(bytes.to_vec());
unsafe {
gpgme_error_try(
&self.inner.lib,
@ -427,6 +429,7 @@ impl Context {
Ok(Data {
lib: self.inner.lib.clone(),
kind: DataKind::Memory,
bytes,
inner: core::ptr::NonNull::new(ptr).ok_or_else(|| {
Error::new("Could not create libgpgme data").set_kind(ErrorKind::Bug)
})?,
@ -442,12 +445,12 @@ impl Context {
)));
}
let os_str: &OsStr = path.as_ref();
let b = CString::new(os_str.as_bytes())?;
let bytes = Pin::new(os_str.as_bytes().to_vec());
let mut ptr = core::ptr::null_mut();
unsafe {
let ret: GpgmeError = call!(&self.inner.lib, gpgme_data_new_from_file)(
&mut ptr,
b.as_ptr() as *const ::std::os::raw::c_char,
bytes.as_ptr() as *const ::std::os::raw::c_char,
1,
);
gpgme_error_try(&self.inner.lib, ret)?;
@ -456,6 +459,7 @@ impl Context {
Ok(Data {
lib: self.inner.lib.clone(),
kind: DataKind::Memory,
bytes,
inner: core::ptr::NonNull::new(ptr).ok_or_else(|| {
Error::new("Could not create libgpgme data").set_kind(ErrorKind::Bug)
})?,
@ -722,6 +726,7 @@ impl Context {
let mut sig = Data {
lib: self.inner.lib.clone(),
kind: DataKind::Memory,
bytes: Pin::new(vec![]),
inner: core::ptr::NonNull::new(sig)
.ok_or_else(|| Error::new("internal libgpgme error").set_kind(ErrorKind::Bug))?,
};
@ -799,6 +804,7 @@ impl Context {
.chain_err_summary(|| {
"libgpgme error: could not perform seek on signature data object"
})?;
_ = text;
sig.into_bytes()
})
}
@ -825,6 +831,7 @@ impl Context {
let mut plain = Data {
lib: self.inner.lib.clone(),
kind: DataKind::Memory,
bytes: Pin::new(vec![]),
inner: core::ptr::NonNull::new(plain)
.ok_or_else(|| Error::new("internal libgpgme error").set_kind(ErrorKind::Bug))?,
};
@ -1034,6 +1041,7 @@ impl Context {
let mut cipher = Data {
lib: self.inner.lib.clone(),
kind: DataKind::Memory,
bytes: Pin::new(vec![]),
inner: core::ptr::NonNull::new(cipher)
.ok_or_else(|| Error::new("internal libgpgme error").set_kind(ErrorKind::Bug))?,
};
@ -1119,6 +1127,7 @@ impl Context {
cipher
.seek(std::io::SeekFrom::Start(0))
.chain_err_summary(|| "libgpgme error: could not perform seek on plain text")?;
_ = plain;
cipher.into_bytes()
})
}
@ -1156,6 +1165,8 @@ enum DataKind {
pub struct Data {
inner: core::ptr::NonNull<bindings::gpgme_data>,
kind: DataKind,
#[allow(dead_code)]
bytes: std::pin::Pin<Vec<u8>>,
lib: Arc<libloading::Library>,
}