Skip to content

Commit 4b1e649

Browse files
committed
Compilation OK for community
1 parent a8ed9e9 commit 4b1e649

File tree

7 files changed

+83
-31
lines changed

7 files changed

+83
-31
lines changed

src/database.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ use crate::{
2222
c_api::{
2323
CBLDatabase, CBLDatabaseConfiguration, CBLDatabaseConfiguration_Default,
2424
CBLDatabase_AddChangeListener, CBLDatabase_BeginTransaction,
25-
CBLDatabase_BufferNotifications, CBLDatabase_ChangeEncryptionKey, CBLDatabase_Close,
26-
CBLDatabase_Count, CBLDatabase_Delete, CBLDatabase_EndTransaction, CBLDatabase_Name,
27-
CBLDatabase_Open, CBLDatabase_Path, CBLDatabase_PerformMaintenance,
28-
CBLDatabase_SendNotifications, CBLEncryptionKey, CBLError, CBL_DatabaseExists,
29-
CBL_DeleteDatabase, CBLEncryptionKey_FromPassword, FLString, kCBLMaintenanceTypeCompact,
30-
kCBLEncryptionAES256, kCBLEncryptionNone, kCBLMaintenanceTypeFullOptimize,
31-
kCBLMaintenanceTypeIntegrityCheck, kCBLMaintenanceTypeOptimize, kCBLMaintenanceTypeReindex,
32-
CBL_CopyDatabase, CBLDatabase_ScopeNames, CBLDatabase_CollectionNames, CBLDatabase_Scope,
25+
CBLDatabase_BufferNotifications, CBLDatabase_Close, CBLDatabase_Count, CBLDatabase_Delete,
26+
CBLDatabase_EndTransaction, CBLDatabase_Name, CBLDatabase_Open, CBLDatabase_Path,
27+
CBLDatabase_PerformMaintenance, CBLDatabase_SendNotifications, CBLError,
28+
CBL_DatabaseExists, CBL_DeleteDatabase, FLString, kCBLMaintenanceTypeCompact,
29+
kCBLMaintenanceTypeFullOptimize, kCBLMaintenanceTypeIntegrityCheck,
30+
kCBLMaintenanceTypeOptimize, kCBLMaintenanceTypeReindex, CBL_CopyDatabase,
31+
CBLDatabase_ScopeNames, CBLDatabase_CollectionNames, CBLDatabase_Scope,
3332
CBLDatabase_Collection, CBLDatabase_CreateCollection, CBLDatabase_DeleteCollection,
3433
CBLDatabase_DefaultScope, CBLDatabase_DefaultCollection,
3534
},
@@ -38,9 +37,15 @@ use crate::{
3837
scope::Scope,
3938
MutableArray,
4039
};
40+
#[cfg(feature = "enterprise")]
41+
use crate::c_api::{
42+
CBLDatabase_ChangeEncryptionKey, CBLEncryptionKey, CBLEncryptionKey_FromPassword,
43+
kCBLEncryptionAES256, kCBLEncryptionNone,
44+
};
4145
use std::path::{Path, PathBuf};
4246
use std::ptr;
4347

48+
#[cfg(feature = "enterprise")]
4449
enum_from_primitive! {
4550
/// Database encryption algorithms
4651
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -55,10 +60,12 @@ pub const ENCRYPTION_KEY_SIZE_AES256: i64 = 32;
5560

5661
/// Encryption key specified in a DatabaseConfiguration
5762
#[derive(Debug, Clone)]
63+
#[cfg(feature = "enterprise")]
5864
pub struct EncryptionKey {
5965
cbl_ref: Box<CBLEncryptionKey>,
6066
}
6167

68+
#[cfg(feature = "enterprise")]
6269
impl EncryptionKey {
6370
/// Derives an encryption key from a password. If your UI uses passwords, call this function to
6471
/// create the key used to encrypt the database. It is designed for security, and deliberately
@@ -85,6 +92,7 @@ impl EncryptionKey {
8592
}
8693
}
8794

95+
#[cfg(feature = "enterprise")]
8896
impl CblRef for EncryptionKey {
8997
type Output = *const CBLEncryptionKey;
9098
fn get_ref(&self) -> Self::Output {
@@ -96,6 +104,7 @@ impl CblRef for EncryptionKey {
96104
#[derive(Debug, Clone)]
97105
pub struct DatabaseConfiguration<'a> {
98106
pub directory: &'a std::path::Path,
107+
#[cfg(feature = "enterprise")]
99108
pub encryption_key: Option<EncryptionKey>,
100109
}
101110

@@ -192,6 +201,7 @@ impl Database {
192201
if let Some(cfg) = config {
193202
let mut c_config: CBLDatabaseConfiguration = CBLDatabaseConfiguration_Default();
194203
c_config.directory = from_str(cfg.directory.to_str().unwrap()).get_ref();
204+
#[cfg(feature = "enterprise")]
195205
if let Some(encryption_key) = cfg.encryption_key {
196206
c_config.encryptionKey = *encryption_key.get_ref();
197207
}
@@ -241,6 +251,7 @@ impl Database {
241251
)
242252
.get_ref();
243253

254+
#[cfg(feature = "enterprise")]
244255
if let Some(encryption_key) = cfg.encryption_key {
245256
c_config.encryptionKey = unsafe { *encryption_key.get_ref() };
246257
}
@@ -337,6 +348,7 @@ impl Database {
337348
}
338349

339350
/// Encrypts or decrypts a database, or changes its encryption key.
351+
#[cfg(feature = "enterprise")]
340352
pub fn change_encryption_key(&mut self, encryption_key: &EncryptionKey) -> Result<()> {
341353
unsafe {
342354
check_bool(|error| {

src/fleece.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ use crate::{
2020
slice::{NULL_SLICE, from_bytes, from_str},
2121
error::{Error, Result},
2222
c_api::{
23-
CBLEncryptable, FLArray, FLArrayIterator, FLArrayIterator_Begin, FLArrayIterator_GetCount,
23+
FLArray, FLArrayIterator, FLArrayIterator_Begin, FLArrayIterator_GetCount,
2424
FLArrayIterator_GetValue, FLArrayIterator_GetValueAt, FLArrayIterator_Next, FLArray_Count,
2525
FLArray_Get, FLArray_IsEmpty, FLDict, FLDictIterator, FLDictIterator_Begin,
2626
FLDictIterator_GetCount, FLDictIterator_GetKeyString, FLDictIterator_GetValue,
2727
FLDictIterator_Next, FLDictKey, FLDictKey_GetString, FLDictKey_Init, FLDict_Count,
28-
FLDict_Get, FLDict_GetEncryptableValue, FLDict_GetWithKey, FLDict_IsBlob, FLDict_IsEmpty,
29-
FLDict_IsEncryptableValue, FLDoc, FLDoc_FromJSON, FLDoc_FromResultData, FLDoc_GetData,
30-
FLDoc_GetRoot, FLDoc_Release, FLDoc_Retain, FLError, FLError_kFLInvalidData, FLSlice_Copy,
31-
FLValue, FLValue_AsArray, FLValue_AsBool, FLValue_AsData, FLValue_AsDict, FLValue_AsDouble,
32-
FLValue_AsFloat, FLValue_AsInt, FLValue_AsString, FLValue_AsTimestamp, FLValue_AsUnsigned,
33-
FLValue_GetType, FLValue_IsEqual, FLValue_IsInteger, FLValue_IsUnsigned, FLValue_IsDouble,
28+
FLDict_Get, FLDict_GetWithKey, FLDict_IsBlob, FLDict_IsEmpty, FLDoc, FLDoc_FromJSON,
29+
FLDoc_FromResultData, FLDoc_GetData, FLDoc_GetRoot, FLDoc_Release, FLDoc_Retain, FLError,
30+
FLError_kFLInvalidData, FLSlice_Copy, FLValue, FLValue_AsArray, FLValue_AsBool,
31+
FLValue_AsData, FLValue_AsDict, FLValue_AsDouble, FLValue_AsFloat, FLValue_AsInt,
32+
FLValue_AsString, FLValue_AsTimestamp, FLValue_AsUnsigned, FLValue_GetType,
33+
FLValue_IsEqual, FLValue_IsInteger, FLValue_IsUnsigned, FLValue_IsDouble,
3434
FLValue_IsMutable, FLValue_ToJSON, _FLValue, FLValue_FindDoc, FLDictIterator_End,
3535
},
36+
};
37+
#[cfg(feature = "enterprise")]
38+
use crate::{
39+
c_api::{CBLEncryptable, FLDict_GetEncryptableValue, FLDict_IsEncryptableValue},
3640
encryptable::Encryptable,
3741
};
3842

@@ -224,6 +228,7 @@ impl Value {
224228
unsafe { FLValue_IsMutable(self.get_ref()) }
225229
}
226230

231+
#[cfg(feature = "enterprise")]
227232
pub fn is_encryptable(&self) -> bool {
228233
unsafe { FLDict_IsEncryptableValue(FLValue_AsDict(self.get_ref())) }
229234
}
@@ -314,6 +319,7 @@ impl Value {
314319
}
315320
}
316321

322+
#[cfg(feature = "enterprise")]
317323
pub fn get_encryptable_value(&self) -> Encryptable {
318324
unsafe {
319325
let encryptable = FLDict_GetEncryptableValue(FLValue_AsDict(self.get_ref()));
@@ -567,6 +573,7 @@ impl Dict {
567573
unsafe { FLDict_IsEmpty(self.get_ref()) }
568574
}
569575

576+
#[cfg(feature = "enterprise")]
570577
pub fn is_encryptable(&self) -> bool {
571578
unsafe { FLDict_IsEncryptableValue(self.get_ref()) }
572579
}
@@ -587,6 +594,7 @@ impl Dict {
587594
}
588595
}
589596

597+
#[cfg(feature = "enterprise")]
590598
pub fn get_encryptable_value(&self) -> Encryptable {
591599
unsafe {
592600
let encryptable = FLDict_GetEncryptableValue(self.get_ref());

src/fleece_mutable.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
//
1717

1818
use crate::{
19-
CblRef, CouchbaseLiteError, Error, ErrorCode, Result, encryptable,
19+
CblRef, CouchbaseLiteError, Error, ErrorCode, Result,
2020
slice::{from_bytes, from_str},
2121
c_api::{
2222
FLArray_AsMutable, FLArray_MutableCopy, FLDict_AsMutable, FLDict_MutableCopy,
2323
FLMutableArray, FLMutableArray_Append, FLMutableArray_Insert, FLMutableArray_IsChanged,
2424
FLMutableArray_New, FLMutableArray_Remove, FLMutableArray_Set, FLMutableDict,
2525
FLMutableDict_IsChanged, FLMutableDict_New, FLMutableDict_Remove, FLMutableDict_RemoveAll,
26-
FLMutableDict_Set, FLSlot, FLSlot_SetBool, FLSlot_SetDouble, FLSlot_SetEncryptableValue,
27-
FLSlot_SetInt, FLSlot_SetNull, FLSlot_SetString, FLSlot_SetValue, FLValue, FLValue_Release,
28-
FLValue_Retain,
26+
FLMutableDict_Set, FLSlot, FLSlot_SetBool, FLSlot_SetDouble, FLSlot_SetInt, FLSlot_SetNull,
27+
FLSlot_SetString, FLSlot_SetValue, FLValue, FLValue_Release, FLValue_Retain,
2928
},
3029
fleece::{Array, ArrayIterator, Dict, DictIterator, DictKey, FleeceReference, Value},
31-
encryptable::Encryptable,
3230
};
31+
#[cfg(feature = "enterprise")]
32+
use crate::{c_api::FLSlot_SetEncryptableValue, encryptable::Encryptable};
3333

3434
use std::collections::HashMap;
3535
use std::fmt;
@@ -314,6 +314,7 @@ impl MutableDict {
314314
.collect::<HashMap<String, String>>()
315315
}
316316

317+
#[cfg(feature = "enterprise")]
317318
pub fn set_encryptable_value(dict: &Self, key: &str, encryptable: &Encryptable) {
318319
unsafe {
319320
FLSlot_SetEncryptableValue(
@@ -485,7 +486,8 @@ impl Slot<'_> {
485486
unsafe { FLSlot_SetValue(self.get_ref(), value._fleece_ref()) }
486487
}
487488

488-
pub fn put_encrypt(self, value: &encryptable::Encryptable) {
489+
#[cfg(feature = "enterprise")]
490+
pub fn put_encrypt(self, value: &Encryptable) {
489491
unsafe { FLSlot_SetEncryptableValue(self.get_ref(), value.get_ref()) }
490492
}
491493
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub mod blob;
3838
pub mod collection;
3939
pub mod database;
4040
pub mod document;
41+
#[cfg(feature = "enterprise")]
4142
pub mod encryptable;
4243
pub mod error;
4344
pub mod fleece;

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn main() {
2727
let tmp_dir = TempDir::new("cbl_rust").expect("create temp dir");
2828
let cfg = DatabaseConfiguration {
2929
directory: tmp_dir.path(),
30+
#[cfg(feature = "enterprise")]
3031
encryption_key: None,
3132
};
3233
let mut db = Database::open("main_db", Some(cfg)).expect("open db");

src/replicator.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,36 @@ use std::{
2424
time::Duration,
2525
};
2626
use crate::{
27-
CblRef, CouchbaseLiteError, Database, Dict, Document, Error, ErrorCode, ListenerToken,
28-
MutableDict, Result, check_error, release, retain,
29-
slice::{from_str, from_bytes, self},
27+
CblRef, Database, Dict, Document, Error, ListenerToken, MutableDict, Result, check_error,
28+
release, retain,
29+
slice::{from_str, self},
3030
c_api::{
3131
CBLListener_Remove, CBLAuth_CreatePassword, CBLAuth_CreateSession, CBLAuthenticator,
32-
CBLDocument, CBLDocumentFlags, CBLEndpoint, CBLEndpoint_CreateWithLocalDB,
33-
CBLEndpoint_CreateWithURL, CBLError, CBLProxySettings, CBLProxyType, CBLReplicatedDocument,
34-
CBLReplicator, CBLReplicatorConfiguration, CBLReplicatorStatus, CBLReplicatorType,
32+
CBLDocument, CBLDocumentFlags, CBLEndpoint, CBLEndpoint_CreateWithURL, CBLError,
33+
CBLProxySettings, CBLProxyType, CBLReplicatedDocument, CBLReplicator,
34+
CBLReplicatorConfiguration, CBLReplicatorStatus, CBLReplicatorType,
3535
CBLReplicator_AddChangeListener, CBLReplicator_AddDocumentReplicationListener,
3636
CBLReplicator_Create, CBLReplicator_IsDocumentPending, CBLReplicator_PendingDocumentIDs,
3737
CBLReplicator_SetHostReachable, CBLReplicator_SetSuspended, CBLReplicator_Start,
38-
CBLReplicator_Status, CBLReplicator_Stop, FLDict, FLSlice, FLSliceResult,
39-
FLSliceResult_New, FLSlice_Copy, FLString, FLStringResult, kCBLDocumentFlagsAccessRemoved,
38+
CBLReplicator_Status, CBLReplicator_Stop, FLDict, FLString, kCBLDocumentFlagsAccessRemoved,
4039
kCBLDocumentFlagsDeleted, kCBLProxyHTTP, kCBLProxyHTTPS, kCBLReplicatorBusy,
4140
kCBLReplicatorConnecting, kCBLReplicatorIdle, kCBLReplicatorOffline, kCBLReplicatorStopped,
4241
kCBLReplicatorTypePull, kCBLReplicatorTypePush, kCBLReplicatorTypePushAndPull,
4342
CBLReplicator_IsDocumentPending2, CBLReplicator_PendingDocumentIDs2,
4443
CBLReplicationCollection,
4544
},
46-
MutableArray, Listener, error,
45+
MutableArray, Listener,
4746
collection::Collection,
4847
};
48+
#[cfg(feature = "enterprise")]
49+
use crate::{
50+
CouchbaseLiteError, ErrorCode, error,
51+
c_api::{
52+
CBLEndpoint_CreateWithLocalDB, FLSlice, FLSliceResult, FLSliceResult_New, FLSlice_Copy,
53+
FLStringResult,
54+
},
55+
slice::from_bytes,
56+
};
4957

5058
// WARNING: THIS API IS UNIMPLEMENTED SO FAR
5159

@@ -79,6 +87,7 @@ impl Endpoint {
7987
}
8088
}
8189

90+
#[cfg(feature = "enterprise")]
8291
pub fn new_with_local_db(db: &Database) -> Self {
8392
unsafe {
8493
Self {
@@ -326,6 +335,7 @@ pub enum EncryptionError {
326335
replicate with the kCBLErrorCrypto error. For security reason, the encryption
327336
cannot be skipped. */
328337
#[deprecated(note = "please use `CollectionPropertyEncryptor` on default collection instead")]
338+
#[cfg(feature = "enterprise")]
329339
pub type DefaultCollectionPropertyEncryptor = fn(
330340
document_id: Option<String>,
331341
properties: Dict,
@@ -336,6 +346,7 @@ pub type DefaultCollectionPropertyEncryptor = fn(
336346
error: &Error,
337347
) -> std::result::Result<Vec<u8>, EncryptionError>;
338348
#[no_mangle]
349+
#[cfg(feature = "enterprise")]
339350
pub extern "C" fn c_default_collection_property_encryptor(
340351
context: *mut ::std::os::raw::c_void,
341352
document_id: FLString,
@@ -401,6 +412,7 @@ pub extern "C" fn c_default_collection_property_encryptor(
401412
\note If a null result or an error is returned, the document will be failed to
402413
replicate with the kCBLErrorCrypto error. For security reason, the encryption
403414
cannot be skipped. */
415+
#[cfg(feature = "enterprise")]
404416
pub type CollectionPropertyEncryptor = fn(
405417
scope: Option<String>,
406418
collection: Option<String>,
@@ -413,6 +425,7 @@ pub type CollectionPropertyEncryptor = fn(
413425
error: &Error,
414426
) -> std::result::Result<Vec<u8>, EncryptionError>;
415427
#[no_mangle]
428+
#[cfg(feature = "enterprise")]
416429
pub extern "C" fn c_collection_property_encryptor(
417430
context: *mut ::std::os::raw::c_void,
418431
scope: FLString,
@@ -483,6 +496,7 @@ pub extern "C" fn c_collection_property_encryptor(
483496
without an error is returned. If an error is returned, the document will be failed to replicate
484497
with the kCBLErrorCrypto error. */
485498
#[deprecated(note = "please use `CollectionPropertyDecryptor` on default collection instead")]
499+
#[cfg(feature = "enterprise")]
486500
pub type DefaultCollectionPropertyDecryptor = fn(
487501
document_id: Option<String>,
488502
properties: Dict,
@@ -493,6 +507,7 @@ pub type DefaultCollectionPropertyDecryptor = fn(
493507
error: &Error,
494508
) -> std::result::Result<Vec<u8>, EncryptionError>;
495509
#[no_mangle]
510+
#[cfg(feature = "enterprise")]
496511
pub extern "C" fn c_default_collection_property_decryptor(
497512
context: *mut ::std::os::raw::c_void,
498513
document_id: FLString,
@@ -558,6 +573,7 @@ pub extern "C" fn c_default_collection_property_decryptor(
558573
\note The decryption will be skipped (the encrypted data will be kept) when a null result
559574
without an error is returned. If an error is returned, the document will be failed to replicate
560575
with the kCBLErrorCrypto error. */
576+
#[cfg(feature = "enterprise")]
561577
pub type CollectionPropertyDecryptor = fn(
562578
scope: Option<String>,
563579
collection: Option<String>,
@@ -570,6 +586,7 @@ pub type CollectionPropertyDecryptor = fn(
570586
error: &Error,
571587
) -> std::result::Result<Vec<u8>, EncryptionError>;
572588
#[no_mangle]
589+
#[cfg(feature = "enterprise")]
573590
pub extern "C" fn c_collection_property_decryptor(
574591
context: *mut ::std::os::raw::c_void,
575592
scope: FLString,
@@ -640,9 +657,13 @@ pub struct ReplicationConfigurationContext {
640657
pub push_filter: Option<ReplicationFilter>, // TODO: deprecated
641658
pub pull_filter: Option<ReplicationFilter>, // TODO: deprecated
642659
pub conflict_resolver: Option<ConflictResolver>, // TODO: deprecated
660+
#[cfg(feature = "enterprise")]
643661
pub default_collection_property_encryptor: Option<DefaultCollectionPropertyEncryptor>, // TODO: deprecated
662+
#[cfg(feature = "enterprise")]
644663
pub default_collection_property_decryptor: Option<DefaultCollectionPropertyDecryptor>, // TODO: deprecated
664+
#[cfg(feature = "enterprise")]
645665
pub collection_property_encryptor: Option<CollectionPropertyEncryptor>,
666+
#[cfg(feature = "enterprise")]
646667
pub collection_property_decryptor: Option<CollectionPropertyDecryptor>,
647668
}
648669

@@ -805,18 +826,22 @@ impl Replicator {
805826
.conflict_resolver
806827
.as_ref()
807828
.and(Some(c_replication_conflict_resolver)),
829+
#[cfg(feature = "enterprise")]
808830
propertyEncryptor: context
809831
.default_collection_property_encryptor
810832
.as_ref()
811833
.and(Some(c_default_collection_property_encryptor)),
834+
#[cfg(feature = "enterprise")]
812835
propertyDecryptor: context
813836
.default_collection_property_decryptor
814837
.as_ref()
815838
.and(Some(c_default_collection_property_decryptor)),
839+
#[cfg(feature = "enterprise")]
816840
documentPropertyEncryptor: context
817841
.collection_property_encryptor
818842
.as_ref()
819843
.and(Some(c_collection_property_encryptor)),
844+
#[cfg(feature = "enterprise")]
820845
documentPropertyDecryptor: context
821846
.collection_property_decryptor
822847
.as_ref()

src/slice.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
use crate::{
1919
CblRef,
20-
c_api::{FLSlice, FLSlice_Copy, FLSliceResult, _FLBuf_Release, _FLBuf_Retain, FLData_Dump},
20+
c_api::{FLSlice, FLSliceResult, _FLBuf_Release, _FLBuf_Retain, FLData_Dump},
2121
};
22+
#[cfg(feature = "enterprise")]
23+
use crate::c_api::FLSlice_Copy;
2224

2325
use std::borrow::Cow;
2426
use std::ffi::{CStr, CString, c_void};
@@ -168,6 +170,7 @@ impl std::ops::Not for FLSlice {
168170
}
169171

170172
impl FLSliceResult {
173+
#[cfg(feature = "enterprise")]
171174
pub fn null() -> FLSliceResult {
172175
let s = FLSlice {
173176
buf: ptr::null(),

0 commit comments

Comments
 (0)