]> uap-core.de Git - note.git/commitdiff
add function for enabling session encryption main
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 26 Jun 2026 13:11:18 +0000 (15:11 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 26 Jun 2026 13:11:18 +0000 (15:11 +0200)
dav-rs/src/dav/session.rs

index d962d439fcac3b5e3fdee853d3db37b8746ea274..b7d4b11bb2f7d2eb500e7e87bab1a4bfd7471e95 100644 (file)
@@ -27,7 +27,8 @@
  */
 #![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;
 
@@ -65,6 +66,12 @@ impl Session {
     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);
+        }
+    }
 }
 
 
@@ -150,6 +157,76 @@ pub enum DavError {
     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);
@@ -159,4 +236,6 @@ unsafe extern "C" {
 
     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