Fix build failures on Windows.

dvn/new-ci
Neal H. Walfield 10 months ago
parent 285accb6a8
commit 81f582c64d
  1. 1
      src/keystore.rs
  2. 21
      src/lib.rs
  3. 24
      src/pep.rs

@ -1,4 +1,5 @@
use std::cmp;
#[cfg(not(windows))]
use std::env;
use std::path::Path;
use std::path::PathBuf;

@ -3,7 +3,6 @@ use std::convert::TryInto;
use std::env;
use std::ffi::{
CStr,
OsStr,
};
use std::io::{
Read,
@ -19,6 +18,9 @@ use std::time::{
UNIX_EPOCH,
};
#[allow(unused_imports)]
use anyhow::Context;
use libc::{
c_char,
c_uint,
@ -284,16 +286,23 @@ ffi!(fn pgp_init_(session: *mut Session, _in_first: bool,
#[cfg(not(windows))]
let per_user_directory = {
use std::ffi::OsStr;
use std::os::unix::ffi::OsStrExt;
OsStr::from_bytes(per_user_directory.to_bytes())
};
#[cfg(windows)]
let per_user_directory = {
use std::ffi::OsString;
use std::os::windows::prelude::*;
let os_string = OsString::from_wide(per_user_directory.as_bytes());
os_string.as_os_str()
// The engine guarantees that it is UTF-8 encoded.
//
// https://gitea.pep.foundation/pEp.foundation/pEpEngine/src/commit/2f0927554ac1b7ca10e27b19650b5158d97dfc3f/src/platform_windows.cpp#L177
match per_user_directory.to_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))?;

@ -1,6 +1,7 @@
use std::ops::BitAnd;
use std::convert::TryFrom;
#[cfg(not(windows))]
use libc::tm;
use sequoia_openpgp as openpgp;
@ -218,20 +219,23 @@ pub enum Error {
// https://gitea.pep.foundation/pEp.foundation/pEpEngine/src/branch/master/src/timestamp.h
#[cfg(not(windows))]
pub type Timestamp = tm;
#[cfg(windows)]
use libc::{c_int, c_long};
#[cfg(windows)]
#[repr(C)]
// for time values all functions are using POSIX struct tm
pub struct Timestamp {
tm_sec: c_int,
tm_min: c_int,
tm_hour: c_int,
tm_mday: c_int,
tm_mon: c_int,
tm_year: c_int,
tm_wday: c_int,
tm_yday: c_int,
tm_isdst: c_int,
tm_gmtoff: c_long, // offset from GMT in seconds
pub tm_sec: c_int,
pub tm_min: c_int,
pub tm_hour: c_int,
pub tm_mday: c_int,
pub tm_mon: c_int,
pub tm_year: c_int,
pub tm_wday: c_int,
pub tm_yday: c_int,
pub tm_isdst: c_int,
pub tm_gmtoff: c_long, // offset from GMT in seconds
}
// See pEpEngine/src/pEpEngine.h:PEP_comm_format.

Loading…
Cancel
Save