use std::cmp; use std::cmp;
#[cfg(not(windows))]
use std::env; use std::env;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
......
...@@ -3,7 +3,6 @@ use std::convert::TryInto; ...@@ -3,7 +3,6 @@ use std::convert::TryInto;
use std::env; use std::env;
use std::ffi::{ use std::ffi::{
CStr, CStr,
OsStr,
}; };
use std::io::{ use std::io::{
Read, Read,
...@@ -19,6 +18,9 @@ use std::time::{ ...@@ -19,6 +18,9 @@ use std::time::{
UNIX_EPOCH, UNIX_EPOCH,
}; };
#[allow(unused_imports)]
use anyhow::Context;
use libc::{ use libc::{
c_char, c_char,
c_uint, c_uint,
...@@ -284,16 +286,23 @@ ffi!(fn pgp_init_(session: *mut Session, _in_first: bool, ...@@ -284,16 +286,23 @@ ffi!(fn pgp_init_(session: *mut Session, _in_first: bool,
#[cfg(not(windows))] #[cfg(not(windows))]
let per_user_directory = { let per_user_directory = {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
OsStr::from_bytes(per_user_directory.to_bytes()) OsStr::from_bytes(per_user_directory.to_bytes())
}; };
#[cfg(windows)] #[cfg(windows)]
let per_user_directory = { let per_user_directory = {
use std::ffi::OsString; // The engine guarantees that it is UTF-8 encoded.
use std::os::windows::prelude::*; //
// https://gitea.pep.foundation/pEp.foundation/pEpEngine/src/commit/2f0927554ac1b7ca10e27b19650b5158d97dfc3f/src/platform_windows.cpp#L177
let os_string = OsString::from_wide(per_user_directory.as_bytes()); match per_user_directory.to_str() {
os_string.as_os_str() Ok(s) => s,
Err(err) =>
return Err(Error::IllegalValue(
format!("\
API violation: per_user_directory not UTF-8 encoded ({:?}: {})",
per_user_directory, err))),
}
}; };
let ks = keystore::Keystore::init(Path::new(per_user_directory))?; let ks = keystore::Keystore::init(Path::new(per_user_directory))?;
......
use std::ops::BitAnd; use std::ops::BitAnd;
use std::convert::TryFrom; use std::convert::TryFrom;
#[cfg(not(windows))]
use libc::tm; use libc::tm;
use sequoia_openpgp as openpgp; use sequoia_openpgp as openpgp;
...@@ -218,20 +219,23 @@ pub enum Error { ...@@ -218,20 +219,23 @@ pub enum Error {
// https://gitea.pep.foundation/pEp.foundation/pEpEngine/src/branch/master/src/timestamp.h // https://gitea.pep.foundation/pEp.foundation/pEpEngine/src/branch/master/src/timestamp.h
#[cfg(not(windows))] #[cfg(not(windows))]
pub type Timestamp = tm; pub type Timestamp = tm;
#[cfg(windows)]
use libc::{c_int, c_long};
#[cfg(windows)] #[cfg(windows)]
#[repr(C)] #[repr(C)]
// for time values all functions are using POSIX struct tm // for time values all functions are using POSIX struct tm
pub struct Timestamp { pub struct Timestamp {
tm_sec: c_int, pub tm_sec: c_int,
tm_min: c_int, pub tm_min: c_int,
tm_hour: c_int, pub tm_hour: c_int,
tm_mday: c_int, pub tm_mday: c_int,
tm_mon: c_int, pub tm_mon: c_int,
tm_year: c_int, pub tm_year: c_int,
tm_wday: c_int, pub tm_wday: c_int,
tm_yday: c_int, pub tm_yday: c_int,
tm_isdst: c_int, pub tm_isdst: c_int,
tm_gmtoff: c_long, // offset from GMT in seconds pub tm_gmtoff: c_long, // offset from GMT in seconds
} }
// See pEpEngine/src/pEpEngine.h:PEP_comm_format. // See pEpEngine/src/pEpEngine.h:PEP_comm_format.
......