Couchbase Lite C++
Couchbase Lite C++ API
Loading...
Searching...
No Matches
Encryptable.hh
Go to the documentation of this file.
1//
2// Encryptable.hh
3//
4// Copyright (c) 2026 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19#pragma once
20
21#ifdef COUCHBASE_ENTERPRISE
22
23#include "cbl++/Base.hh"
24#include "cbl/CBLEncryptable.h"
25#include "fleece/Fleece.hh"
26#include <string_view>
27
28
30
31namespace cbl {
32
39 class Encryptable : protected RefCounted {
40 public:
44
48
52 return {CBLEncryptable_CreateWithNull(), adopt};
53 }
54
59 return {CBLEncryptable_CreateWithBool(value), adopt};
60 }
61
66 return {CBLEncryptable_CreateWithInt(value), adopt};
67 }
68
72 static Encryptable createWithUInt(uint64_t value) {
73 return {CBLEncryptable_CreateWithUInt(value), adopt};
74 }
75
81 }
82
88 }
89
91 fleece::Value value() const {return CBLEncryptable_Value(ref());}
92
94 fleece::Dict properties() const {return CBLEncryptable_Properties(ref());}
95
98 void setInto(fleece::MutableDict dict, fleece::slice key) const {
99 fleece::Dict props = properties();
100 fleece::MutableDict mProps = props.asMutable();
101 if (!mProps)
102 mProps = props.mutableCopy();
103 dict[key] = mProps;
104 }
105
108 static bool isEncryptableValue(fleece::Dict dict) {
109 return FLDict_IsEncryptableValue(dict);
110 }
111
115 static Encryptable getEncryptableValue(fleece::Value value) {
117 }
118
119 protected:
121
122 private:
123 struct adopt_t {};
124 inline static constexpr adopt_t adopt{};
125
126 Encryptable(CBLEncryptable* cObj, adopt_t) {_ref = (CBLRefCounted*)cObj;}
127 };
128
129}
130
132
133#endif // COUCHBASE_ENTERPRISE
#define CBL_REFCOUNTED_BOILERPLATE(CLASS, SUPER, C_TYPE)
Definition Base.hh:160
#define CBL_ASSUME_NONNULL_END
#define CBL_ASSUME_NONNULL_BEGIN
static Encryptable getEncryptableValue(fleece::Value value)
Returns the Encryptable that the given value represents, if any.
Definition Encryptable.hh:115
CBLEncryptable *_Nullable ref() const
Returns a pointer to the underlying C object (CBLEncryptable), or NULL if this is a null reference.
Definition Encryptable.hh:120
static bool isEncryptableValue(fleece::Dict dict)
Returns true if the given dictionary is the persistent form of an Encryptable.
Definition Encryptable.hh:108
static Encryptable createWithInt(int64_t value)
Creates an Encryptable wrapping a signed integer value.
Definition Encryptable.hh:65
fleece::Value value() const
Returns the value to be encrypted by the push replicator.
Definition Encryptable.hh:91
Encryptable(fleece::Value value)
Creates an Encryptable wrapping an arbitrary Fleece value.
Definition Encryptable.hh:43
static Encryptable createWithBool(bool value)
Creates an Encryptable wrapping a boolean value.
Definition Encryptable.hh:58
static Encryptable createWithFloat(float value)
Creates an Encryptable wrapping a float value.
Definition Encryptable.hh:79
Encryptable(std::string_view value)
Creates an Encryptable wrapping a string value.
Definition Encryptable.hh:47
static Encryptable createWithNull()
Creates an Encryptable wrapping a null value.
Definition Encryptable.hh:51
Encryptable() noexcept
Constructs a null reference (one that points to no object).
Definition Encryptable.hh:120
void setInto(fleece::MutableDict dict, fleece::slice key) const
Sets this encryptable value into dict under key.
Definition Encryptable.hh:98
static Encryptable createWithDouble(double value)
Creates an Encryptable wrapping a double value.
Definition Encryptable.hh:86
fleece::Dict properties() const
Returns the Encryptable's underlying dictionary representation (its persistent form).
Definition Encryptable.hh:94
static Encryptable createWithUInt(uint64_t value)
Creates an Encryptable wrapping an unsigned integer value.
Definition Encryptable.hh:72
CBLEncryptable * CBLEncryptable_CreateWithValue(FLValue value)
CBLEncryptable * CBLEncryptable_CreateWithUInt(uint64_t value)
CBLEncryptable * CBLEncryptable_CreateWithInt(int64_t value)
CBLEncryptable * CBLEncryptable_CreateWithBool(bool value)
CBLEncryptable * CBLEncryptable_CreateWithNull(void)
CBLEncryptable * CBLEncryptable_CreateWithString(FLString value)
CBLINLINE const CBLEncryptable *_cbl_nullable FLValue_GetEncryptableValue(FLValue _cbl_nullable value)
FLDict CBLEncryptable_Properties(const CBLEncryptable *encryptable)
struct CBLEncryptable CBLEncryptable
bool FLDict_IsEncryptableValue(FLDict _cbl_nullable)
CBLEncryptable * CBLEncryptable_CreateWithFloat(float value)
CBLEncryptable * CBLEncryptable_CreateWithDouble(double value)
FLValue CBLEncryptable_Value(const CBLEncryptable *encryptable)
struct CBLRefCounted CBLRefCounted
Definition Base.hh:46
fleece::slice slice
Convenience alias for fleece::slice, a non-owning view of a byte range.
Definition Base.hh:49