Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions C/Cpp_include/c4Base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct C4Base {
using alloc_slice = fleece::alloc_slice;
template <class T>
using Retained = fleece::Retained<T>;
template <class T>
using Ref = fleece::Ref<T>;
};

// Forward references to internal LiteCore classes named in the public headers
Expand Down
30 changes: 15 additions & 15 deletions C/Cpp_include/c4Certificate.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct C4Cert final
, public fleece::InstanceCountedIn<C4Cert>
, C4Base {
#ifdef COUCHBASE_ENTERPRISE
static Retained<C4Cert> fromData(slice certData);
static Ref<C4Cert> fromData(slice certData);

alloc_slice getData(bool pemEncoded);

Expand Down Expand Up @@ -67,19 +67,19 @@ struct C4Cert final

// Certificate signing requests:

static Retained<C4Cert> createRequest(const std::vector<C4CertNameComponent>& nameComponents,
C4CertUsage certUsages, C4KeyPair* subjectKey);
static Ref<C4Cert> createRequest(const std::vector<C4CertNameComponent>& nameComponents, C4CertUsage certUsages,
C4KeyPair* subjectKey);

static Retained<C4Cert> requestFromData(slice certRequestData);
static Ref<C4Cert> requestFromData(slice certRequestData);

bool isSigned();

using SigningCallback = std::function<void(C4Cert*, C4Error)>;

void sendSigningRequest(const C4Address& address, slice optionsDictFleece, const SigningCallback& callback);

Retained<C4Cert> signRequest(const C4CertIssuerParameters& params, C4KeyPair* issuerPrivateKey,
C4Cert* C4NULLABLE issuerCert);
Ref<C4Cert> signRequest(const C4CertIssuerParameters& params, C4KeyPair* issuerPrivateKey,
C4Cert* C4NULLABLE issuerCert);

// Persistence:

Expand All @@ -101,8 +101,8 @@ struct C4Cert final
litecore::crypto::CertSigningRequest* assertUnsignedCert();

#endif // COUCHBASE_ENTERPRISE
litecore::crypto::Cert* C4NULLABLE asSignedCert();
Retained<litecore::crypto::CertBase> _impl;
litecore::crypto::Cert* C4NULLABLE asSignedCert();
Ref<litecore::crypto::CertBase> _impl;
};

#ifdef COUCHBASE_ENTERPRISE
Expand All @@ -112,11 +112,11 @@ struct C4Cert final
struct C4KeyPair final
: public fleece::RefCounted
, C4Base {
static Retained<C4KeyPair> generate(C4KeyPairAlgorithm algorithm, unsigned sizeInBits, bool persistent);
static Ref<C4KeyPair> generate(C4KeyPairAlgorithm algorithm, unsigned sizeInBits, bool persistent);

static Retained<C4KeyPair> fromPublicKeyData(slice publicKeyData);
static Ref<C4KeyPair> fromPublicKeyData(slice publicKeyData);

static Retained<C4KeyPair> fromPrivateKeyData(slice privateKeyData, slice passwordOrNull);
static Ref<C4KeyPair> fromPrivateKeyData(slice privateKeyData, slice passwordOrNull);

bool hasPrivateKey();

Expand All @@ -136,8 +136,8 @@ struct C4KeyPair final

// Externally-Implemented Key-Pairs:

static Retained<C4KeyPair> fromExternal(C4KeyPairAlgorithm algorithm, size_t keySizeInBits, void* externalKey,
const C4ExternalKeyCallbacks& callbacks);
static Ref<C4KeyPair> fromExternal(C4KeyPairAlgorithm algorithm, size_t keySizeInBits, void* externalKey,
const C4ExternalKeyCallbacks& callbacks);

// Internal:
litecore::crypto::PrivateKey* C4NULLABLE getPrivateKey();
Expand All @@ -147,10 +147,10 @@ struct C4KeyPair final

explicit C4KeyPair(litecore::crypto::Key*);
~C4KeyPair() override;
Retained<litecore::crypto::PublicKey> getPublicKey();
Ref<litecore::crypto::PublicKey> getPublicKey();
litecore::crypto::PersistentPrivateKey* getPersistentPrivateKey();

Retained<litecore::crypto::Key> _impl;
Ref<litecore::crypto::Key> _impl;
};

#endif // COUCHBASE_ENTERPRISE
Expand Down
2 changes: 1 addition & 1 deletion C/Cpp_include/c4Collection.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct C4Collection
// Queries & Indexes:

/// Same as the C4Database method, but the query will refer to this collection by default.
Retained<C4Query> newQuery(C4QueryLanguage language, slice queryExpr, int* outErrorPos) const;
Ref<C4Query> newQuery(C4QueryLanguage language, slice queryExpr, int* outErrorPos) const;

/// Returns true if it created or replaced the index, false if it already exists.
virtual bool createIndex(slice name, slice indexSpec, C4QueryLanguage indexLanguage, C4IndexType indexType,
Expand Down
25 changes: 12 additions & 13 deletions C/Cpp_include/c4Database.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ struct C4Database
[[nodiscard]] static bool deleteNamed(slice name, slice inDirectory);
[[nodiscard]] static bool deleteAtPath(slice path);

static Retained<C4Database> openNamed(slice name, const Config&);
static Ref<C4Database> openNamed(slice name, const Config&);

static Retained<C4Database> openAtPath(slice path, C4DatabaseFlags, const C4EncryptionKey* C4NULLABLE = nullptr);
static Ref<C4Database> openAtPath(slice path, C4DatabaseFlags, const C4EncryptionKey* C4NULLABLE = nullptr);

static void shutdownLiteCore();

Retained<C4Database> openAgain() const;
Ref<C4Database> openAgain() const;

virtual void close() = 0;
virtual void closeAndDeleteFile() = 0;
Expand Down Expand Up @@ -216,22 +216,21 @@ struct C4Database

// Queries & Indexes:

Retained<C4Query> newQuery(C4QueryLanguage language, slice queryExpression,
int* C4NULLABLE outErrorPos = nullptr) const;
Ref<C4Query> newQuery(C4QueryLanguage language, slice queryExpression, int* C4NULLABLE outErrorPos = nullptr) const;

// Replicator:

Retained<C4Replicator> newReplicator(C4Address serverAddress, slice remoteDatabaseName,
const C4ReplicatorParameters& params, slice logPrefix = {});
Ref<C4Replicator> newReplicator(C4Address serverAddress, slice remoteDatabaseName,
const C4ReplicatorParameters& params, slice logPrefix = {});

Retained<C4Replicator> newIncomingReplicator(C4Socket* openSocket, const C4ReplicatorParameters& params,
slice logPrefix = {});
Retained<C4Replicator> newIncomingReplicator(litecore::websocket::WebSocket* openSocket,
const C4ReplicatorParameters& params, slice logPrefix = {});
Ref<C4Replicator> newIncomingReplicator(C4Socket* openSocket, const C4ReplicatorParameters& params,
slice logPrefix = {});
Ref<C4Replicator> newIncomingReplicator(litecore::websocket::WebSocket* openSocket,
const C4ReplicatorParameters& params, slice logPrefix = {});

#ifdef COUCHBASE_ENTERPRISE
Retained<C4Replicator> newLocalReplicator(C4Database* otherLocalDB, const C4ReplicatorParameters& params,
slice logPrefix = {});
Ref<C4Replicator> newLocalReplicator(C4Database* otherLocalDB, const C4ReplicatorParameters& params,
slice logPrefix = {});
#endif

alloc_slice getCookies(const C4Address&);
Expand Down
2 changes: 1 addition & 1 deletion C/Cpp_include/c4Document.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct C4Document
// NOTE: Instances are created with database->getDocument or database->putDocument.

/// Creates a new instance identical to this one, except its `extraInfo` is unset.
virtual Retained<C4Document> copy() const = 0;
virtual Ref<C4Document> copy() const = 0;

// Accessors:

Expand Down
12 changes: 6 additions & 6 deletions C/Cpp_include/c4Index.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ struct C4Index

C4Index(C4Collection* coll, std::string name) : _collection(coll), _name(std::move(name)) {}

Retained<C4Collection> _collection;
std::string _name;
Ref<C4Collection> _collection;
std::string _name;
};

#ifdef COUCHBASE_ENTERPRISE
Expand Down Expand Up @@ -102,14 +102,14 @@ struct C4IndexUpdater final

private:
friend struct C4IndexImpl;
C4IndexUpdater(Retained<litecore::LazyIndexUpdate>, C4Collection*);
C4IndexUpdater(Ref<litecore::LazyIndexUpdate>, C4Collection*);
~C4IndexUpdater();

// Invariants: _update != nullptr || (finish() has been called)
bool hasFinished() const { return !_update; }
bool hasFinished() const { return !_update.isValid(); }

Retained<litecore::LazyIndexUpdate> _update;
Retained<C4Collection> _collection;
Ref<litecore::LazyIndexUpdate> _update;
Ref<C4Collection> _collection;
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion C/Cpp_include/c4Listener.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct C4Listener final
C4Listener(const C4Listener&) = delete;

// internal use only
C4Listener(C4ListenerConfig const& config, Retained<litecore::REST::HTTPListener> impl);
C4Listener(C4ListenerConfig const& config, Ref<litecore::REST::HTTPListener> impl);

private:
C4Listener(C4Listener&&) noexcept;
Expand Down
37 changes: 17 additions & 20 deletions C/Cpp_include/c4Query.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ struct C4Query final
, C4Base {
public:
/// Creates a new query on a database.
static Retained<C4Query> newQuery(C4Database*, C4QueryLanguage, slice queryExpression, int* C4NULLABLE outErrorPos);
static Ref<C4Query> newQuery(C4Database*, C4QueryLanguage, slice queryExpression, int* C4NULLABLE outErrorPos);

/// Creates a new query on the collection's database.
/// If the query does not refer to a collection by name (e.g. "FROM airlines"),
/// it will use the given collection instead of the default one.
static Retained<C4Query> newQuery(C4Collection*, C4QueryLanguage, slice queryExpression,
int* C4NULLABLE outErrorPos);
static Ref<C4Query> newQuery(C4Collection*, C4QueryLanguage, slice queryExpression, int* C4NULLABLE outErrorPos);

unsigned columnCount() const noexcept;
slice columnTitle(unsigned col) const LIFETIMEBOUND;
Expand Down Expand Up @@ -80,10 +79,10 @@ struct C4Query final
friend struct C4Query;
friend class litecore::C4QueryObserverImpl;
explicit Enumerator(C4Query*, slice encodedParameters = fleece::nullslice);
explicit Enumerator(Retained<litecore::QueryEnumerator> e);
explicit Enumerator(C4Query*, Ref<litecore::QueryEnumerator>);

Retained<litecore::QueryEnumerator> _enum;
Retained<litecore::Query> _query;
Ref<litecore::QueryEnumerator> _enum;
Ref<litecore::Query> _query;
};

/// Runs the query, returning an enumerator. Use it like this:
Expand All @@ -100,7 +99,7 @@ struct C4Query final

using ObserverCallback = std::function<void(C4QueryObserver*)>;

Retained<C4QueryObserver> observe(ObserverCallback);
Ref<C4QueryObserver> observe(ObserverCallback);

protected:
friend class litecore::C4QueryObserverImpl;
Expand All @@ -115,32 +114,30 @@ struct C4Query final
struct KeyCmp {
using is_transparent = void;

bool operator()(const Retained<litecore::C4QueryObserverImpl>& r1,
const Retained<litecore::C4QueryObserverImpl>& r2) const {
bool operator()(const Ref<litecore::C4QueryObserverImpl>& r1,
const Ref<litecore::C4QueryObserverImpl>& r2) const {
return r1.get() < r2.get();
}

bool operator()(const Retained<litecore::C4QueryObserverImpl>& r1,
const litecore::C4QueryObserverImpl* p2) const {
bool operator()(const Ref<litecore::C4QueryObserverImpl>& r1, const litecore::C4QueryObserverImpl* p2) const {
return r1.get() < p2;
}

bool operator()(const litecore::C4QueryObserverImpl* p1,
const Retained<litecore::C4QueryObserverImpl>& r2) const {
bool operator()(const litecore::C4QueryObserverImpl* p1, const Ref<litecore::C4QueryObserverImpl>& r2) const {
return p1 < r2.get();
}
};

using ObserverSet = std::set<Retained<litecore::C4QueryObserverImpl>, KeyCmp>;
using ObserverSet = std::set<Ref<litecore::C4QueryObserverImpl>, KeyCmp>;

Retained<litecore::QueryEnumerator> _createEnumerator(slice params);
Ref<litecore::QueryEnumerator> _createEnumerator(slice params);
Retained<litecore::C4QueryEnumeratorImpl> wrapEnumerator(litecore::QueryEnumerator* C4NULLABLE);
void liveQuerierUpdated(litecore::QueryEnumerator* C4NULLABLE, C4Error err);
void liveQuerierStopped();
void notifyObservers(const ObserverSet& observers, litecore::QueryEnumerator* C4NULLABLE, C4Error err);

Retained<litecore::DatabaseImpl> _database;
Retained<litecore::Query> _query;
Ref<litecore::DatabaseImpl> _database;
Ref<litecore::Query> _query;
alloc_slice _parameters;
Retained<litecore::LiveQuerier> _bgQuerier;
std::unique_ptr<LiveQuerierDelegate> _bgQuerierDelegate;
Expand All @@ -158,7 +155,7 @@ struct C4QueryObserver
, C4Base {
public:
/// Creates a new query on a database.
static Retained<C4QueryObserver> newQueryObserver(C4Query* query, C4Query::ObserverCallback cb, void* ctx);
static Ref<C4QueryObserver> newQueryObserver(C4Query* query, C4Query::ObserverCallback cb, void* ctx);

virtual ~C4QueryObserver() = default;

Expand All @@ -177,8 +174,8 @@ struct C4QueryObserver
protected:
explicit C4QueryObserver(C4Query* query) : _query(query) {}

Retained<C4Query> _query;
C4Error _currentError{};
Ref<C4Query> _query;
C4Error _currentError{};
};

C4_ASSUME_NONNULL_END
30 changes: 14 additions & 16 deletions C/c4Certificate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ CertSigningRequest* C4Cert::assertUnsignedCert() {
return (CertSigningRequest*)_impl.get();
}

Retained<C4Cert> C4Cert::fromData(slice certData) { return new C4Cert(new Cert(certData)); }
Ref<C4Cert> C4Cert::fromData(slice certData) { return new C4Cert(new Cert(certData)); }

alloc_slice C4Cert::getData(bool pemEncoded) { return _impl->data(pemEncoded ? KeyFormat::PEM : KeyFormat::DER); }

Expand Down Expand Up @@ -162,8 +162,8 @@ Retained<C4Cert> C4Cert::getNextInChain() {
// Certificate signing requests:


Retained<C4Cert> C4Cert::createRequest(const std::vector<C4CertNameComponent>& nameComponents, C4CertUsage certUsages,
C4KeyPair* subjectKey) {
Ref<C4Cert> C4Cert::createRequest(const std::vector<C4CertNameComponent>& nameComponents, C4CertUsage certUsages,
C4KeyPair* subjectKey) {
vector<DistinguishedName::Entry> name;
SubjectAltNames altNames;
for ( auto& component : nameComponents ) {
Expand All @@ -178,7 +178,7 @@ Retained<C4Cert> C4Cert::createRequest(const std::vector<C4CertNameComponent>& n
return new C4Cert(new CertSigningRequest(params, subjectKey->getPrivateKey()));
}

Retained<C4Cert> C4Cert::requestFromData(slice certRequestData) {
Ref<C4Cert> C4Cert::requestFromData(slice certRequestData) {
# ifdef ENABLE_CERT_REQUEST
return new C4Cert(new CertSigningRequest(certRequestData));
# else
Expand All @@ -205,8 +205,8 @@ void C4Cert::sendSigningRequest(const C4Address& address, slice optionsDictFleec

// NOLINTEND(readability-convert-member-functions-to-static)

Retained<C4Cert> C4Cert::signRequest(const C4CertIssuerParameters& c4Params, C4KeyPair* issuerPrivateKey,
C4Cert* C4NULLABLE issuerC4Cert) {
Ref<C4Cert> C4Cert::signRequest(const C4CertIssuerParameters& c4Params, C4KeyPair* issuerPrivateKey,
C4Cert* C4NULLABLE issuerC4Cert) {
auto csr = assertUnsignedCert();
auto privateKey = issuerPrivateKey->getPrivateKey();
AssertParam(privateKey != nullptr, "No private key");
Expand Down Expand Up @@ -275,7 +275,7 @@ C4KeyPair::C4KeyPair(Key* key) : _impl(key) { Assert(key); }

C4KeyPair::~C4KeyPair() = default;

Retained<PublicKey> C4KeyPair::getPublicKey() {
Ref<PublicKey> C4KeyPair::getPublicKey() {
if ( PrivateKey* priv = getPrivateKey(); priv ) return priv->publicKey();
else
return (PublicKey*)_impl.get();
Expand All @@ -288,7 +288,7 @@ PersistentPrivateKey* C4KeyPair::getPersistentPrivateKey() {
return nullptr;
}

Retained<C4KeyPair> C4KeyPair::generate(C4KeyPairAlgorithm algorithm, unsigned sizeInBits, bool persistent) {
Ref<C4KeyPair> C4KeyPair::generate(C4KeyPairAlgorithm algorithm, unsigned sizeInBits, bool persistent) {
AssertParam(algorithm == kC4RSA, "Invalid algorithm");
Retained<PrivateKey> privateKey;
if ( persistent ) {
Expand All @@ -303,11 +303,9 @@ Retained<C4KeyPair> C4KeyPair::generate(C4KeyPairAlgorithm algorithm, unsigned s
return new C4KeyPair(privateKey);
}

Retained<C4KeyPair> C4KeyPair::fromPublicKeyData(slice publicKeyData) {
return new C4KeyPair(new PublicKey(publicKeyData));
}
Ref<C4KeyPair> C4KeyPair::fromPublicKeyData(slice publicKeyData) { return new C4KeyPair(new PublicKey(publicKeyData)); }

Retained<C4KeyPair> C4KeyPair::fromPrivateKeyData(slice privateKeyData, slice passwordOrNull) {
Ref<C4KeyPair> C4KeyPair::fromPrivateKeyData(slice privateKeyData, slice passwordOrNull) {
return new C4KeyPair(new PrivateKey(privateKeyData, passwordOrNull));
}

Expand Down Expand Up @@ -380,8 +378,8 @@ namespace litecore {
}

fleece::alloc_slice publicKeyRawData() override {
alloc_slice data(publicKeyDERData());
Retained<PublicKey> publicKey = new PublicKey(data);
alloc_slice data(publicKeyDERData());
Ref<PublicKey> publicKey = new PublicKey(data);
return publicKey->data(KeyFormat::Raw);
}

Expand Down Expand Up @@ -410,8 +408,8 @@ namespace litecore {

} // namespace litecore

Retained<C4KeyPair> C4KeyPair::fromExternal(C4KeyPairAlgorithm algorithm, size_t keySizeInBits, void* externalKey,
const C4ExternalKeyCallbacks& callbacks) {
Ref<C4KeyPair> C4KeyPair::fromExternal(C4KeyPairAlgorithm algorithm, size_t keySizeInBits, void* externalKey,
const C4ExternalKeyCallbacks& callbacks) {
AssertParam(algorithm == kC4RSA, "Invalid algorithm");
return new C4KeyPair(new ExternalKeyPair(keySizeInBits, externalKey, callbacks));
}
Expand Down
Loading
Loading