*/
#![allow(dead_code)]
-use std::ffi::{c_char, CStr, CString};
+use std::ffi::{c_char, c_int, CStr, CString};
+use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign};
use crate::dav::context::DavContext;
use crate::dav::ffi;
pub fn get_error(&self) -> DavError {
get_session_error(self.ptr)
}
+
+ pub fn enable_encryption(&self, flags: SessionFlags) {
+ unsafe {
+ dav_session_enable_encryption(self.ptr, flags.bits() as i32);
+ }
+ }
}
NetAuthRequired,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct SessionFlags(pub u16);
+
+impl SessionFlags {
+ pub const NONE: Self = Self(0);
+
+ pub const ENCRYPT_CONTENT: Self = Self(0x0001);
+ pub const ENCRYPT_NAME: Self = Self(0x0002);
+ pub const ENCRYPT_PROPERTIES: Self = Self(0x0004);
+
+ pub const DECRYPT_CONTENT: Self = Self(0x0008);
+ pub const DECRYPT_NAME: Self = Self(0x0010);
+ pub const DECRYPT_PROPERTIES: Self = Self(0x0020);
+
+ pub const STORE_HASH: Self = Self(0x0040);
+
+ pub const CONTENT_CRYPTO: Self =
+ Self(Self::ENCRYPT_CONTENT.0 | Self::DECRYPT_CONTENT.0);
+
+ pub const FULL_CRYPTO: Self =
+ Self(
+ Self::ENCRYPT_CONTENT.0
+ | Self::ENCRYPT_NAME.0
+ | Self::ENCRYPT_PROPERTIES.0
+ | Self::DECRYPT_CONTENT.0
+ | Self::DECRYPT_NAME.0
+ | Self::DECRYPT_PROPERTIES.0,
+ );
+
+ pub const fn contains(self, other: Self) -> bool {
+ (self.0 & other.0) == other.0
+ }
+
+ pub const fn intersects(self, other: Self) -> bool {
+ (self.0 & other.0) != 0
+ }
+
+ pub const fn bits(self) -> u16 {
+ self.0
+ }
+}
+
+impl BitOr for SessionFlags {
+ type Output = Self;
+
+ fn bitor(self, rhs: Self) -> Self {
+ Self(self.0 | rhs.0)
+ }
+}
+
+impl BitOrAssign for SessionFlags {
+ fn bitor_assign(&mut self, rhs: Self) {
+ self.0 |= rhs.0;
+ }
+}
+
+impl BitAnd for SessionFlags {
+ type Output = Self;
+
+ fn bitand(self, rhs: Self) -> Self {
+ Self(self.0 & rhs.0)
+ }
+}
+
+impl BitAndAssign for SessionFlags {
+ fn bitand_assign(&mut self, rhs: Self) {
+ self.0 &= rhs.0;
+ }
+}
+
unsafe extern "C" {
fn dav_session_new(ctx: *mut ffi::DavContext, base_url: *const libc::c_char) -> *mut ffi::DavSession;
//fn dav_session_ref(sn: *mut ffi::DavSession);
fn dav_session_get_error(sn: *const ffi::DavSession) -> ffi::DavError;
fn dav_session_get_errorstr(sn: *const ffi::DavSession) -> *const c_char;
+
+ fn dav_session_enable_encryption(sn: *mut ffi::DavSession, flags: c_int);
}
\ No newline at end of file