From kde-commits Fri Aug 07 19:57:13 2015 From: Valentin Rusu Date: Fri, 07 Aug 2015 19:57:13 +0000 To: kde-commits Subject: [ksecrets] src/runtime/ksecrets_backend: Some more qualifiers and constructors Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=143897744608580 Git commit a023d42c855bafb2f692c85665ab78063a2331fc by Valentin Rusu. Committed on 06/08/2015 at 18:18. Pushed by vrusu into branch 'master'. Some more qualifiers and constructors M +65 -27 src/runtime/ksecrets_backend/ksecrets_backend.h http://commits.kde.org/ksecrets/a023d42c855bafb2f692c85665ab78063a2331fc diff --git a/src/runtime/ksecrets_backend/ksecrets_backend.h b/src/runtime/= ksecrets_backend/ksecrets_backend.h index 489a842..22b2441 100644 --- a/src/runtime/ksecrets_backend/ksecrets_backend.h +++ b/src/runtime/ksecrets_backend/ksecrets_backend.h @@ -32,24 +32,37 @@ * * This class would store the secrets into an underlying custom formated f= ile. * - * Each API call is stateless. That is, the secrets file will always be le= ft in a consistent - * state between calls. So, even if your application crashes, the file won= 't get corrupted. - * FIXME is that OK? Further tests should be confirm if a background sync = should be introduced - * in order to get operations faster. However, today computing power= do not justify - * =C3=A0 priori optimizations, so this first version would modify t= he file with each API call. - * That guarantee client applications that edits are always synced t= o disk/storage. + * Each API call is stateless. That is, the secrets file will always be le= ft + *in a consistent + * state between calls. So, even if your application crashes, the file won= 't + *get corrupted. + * FIXME is that OK? Further tests should be confirm if a background sync + *should be introduced + * in order to get operations faster. However, today computing power= do + *not justify + * =C3=A0 priori optimizations, so this first version would modify t= he file + *with each API call. + * That guarantee client applications that edits are always synced to + *disk/storage. * - * The API calls are organized in classes, following the structure of data= in the backend. - * Applications will first work with a Collection, the search or insert It= ems into it. - * The Item class holds, sure enough, the secret value but also let applic= ations associate - * the secret value with metadata, such as the label or other custom prope= rties. + * The API calls are organized in classes, following the structure of data= in + *the backend. + * Applications will first work with a Collection, the search or insert It= ems + *into it. + * The Item class holds, sure enough, the secret value but also let + *applications associate + * the secret value with metadata, such as the label or other custom + *properties. * * Before using a collection, the application should open it. * Upon opening, it's possible to indicate if readonly mode is possible. * - * When opening without readonly flag, then the file is exclusively locked= . The lock is - * released when the class is destroyed. You should keep the file locked a= s shortly as - * possible, in order to avoid deadlocks between applications that also ne= ed to read the + * When opening without readonly flag, then the file is exclusively locked. + *The lock is + * released when the class is destroyed. You should keep the file locked as + *shortly as + * possible, in order to avoid deadlocks between applications that also ne= ed + *to read the * secrets. For more information @see open(). * * TODO give here a code example once the API stabilizes @@ -88,8 +101,7 @@ public: TimeStamped(const TimeStamped&) =3D default; TimeStamped& operator=3D(const TimeStamped&) =3D default; = - template - void modify(FUNC func) + template void modify(FUNC func) { func(); modifiedTime =3D std::time(nullptr); @@ -114,6 +126,9 @@ public: * @see Collection */ class Item : public TimeStamped { + Item(const Item&) =3D default; + Item& operator=3D(const Item&) =3D default; + std::string label() const noexcept; bool setLabel(std::string&&) noexcept; = @@ -123,6 +138,10 @@ public: ItemValue value() const noexcept; bool setValue(ItemValue&&) noexcept; = + protected: + Item(); + friend class KSecretsBackend; + private: std::shared_ptr d; }; @@ -131,19 +150,29 @@ public: /** * Each application organizes it's secrets in collections. * - * Typical applications will only use one collection. A collection can= store - * an arbitrary amount of Items. Each Item has a label, custom attribu= tes and + * Typical applications will only use one collection. A collection can + *store + * an arbitrary amount of Items. Each Item has a label, custom attribu= tes + *and * a secret value. * - * The custom attributes are application-defined. This API would store= these + * The custom attributes are application-defined. This API would store + *these * attributes as they are provided. * - * Search methods are provided to let application locate items by spec= ifying - * only a subset of these custom attributes. When searching, partial m= atching is - * used, so you could only provide part of the value of an attribute a= nd get all - * the items having attribute value containing that partially specifie= d value. + * Search methods are provided to let application locate items by + *specifying + * only a subset of these custom attributes. When searching, partial + *matching is + * used, so you could only provide part of the value of an attribute a= nd + *get all + * the items having attribute value containing that partially specified + *value. */ class Collection : public TimeStamped { + Collection(const Collection&) =3D default; + Collection& operator=3D(const Collection&) =3D default; + std::string label() const noexcept; bool setLabel(std::string&&) noexcept; = @@ -157,7 +186,8 @@ public: * possible. So please check if via it's operator bool() before us= ing * it. */ - ItemPtr createItem(std::string&& label, AttributesMap&&, ItemValue= &&) noexcept; + ItemPtr createItem( + std::string&& label, AttributesMap&&, ItemValue&&) noexcept; /* * Convenience method for creating items without supplemental * attributes. @@ -167,6 +197,11 @@ public: * it. */ ItemPtr createItem(std::string&& label, ItemValue&&) noexcept; + + protected: + Collection(); + friend class KSecretsBackend; + private: std::shared_ptr d; }; @@ -183,7 +218,7 @@ public: */ KSecretsBackend(); KSecretsBackend(const KSecretsBackend&) =3D delete; - virtual ~KSecretsBackend(); + virtual ~KSecretsBackend() =3D default; = enum class OpenStatus { Good, @@ -192,16 +227,19 @@ public: FileNotFound, PermissionDeniedByTheSystem }; - std::future open(std::string&&, bool readOnly =3D true) no= except; + std::future open( + std::string&&, bool readOnly =3D true) noexcept; std::vector dirCollections() noexcept; /* - * @return CollectionPtr which can empty if the call did not succeed. = Please check that with operator bool(). + * @return CollectionPtr which can empty if the call did not succeed. + *Please check that with operator bool(). * If it fails, have you already called open()? * */ CollectionPtr createCollection(std::string&&) noexcept; /* - * @return CollectionPtr which can empty if the call did not succeed, = e.g. the collection was not found. + * @return CollectionPtr which can empty if the call did not succeed, = e.g. + * the collection was not found. * Please check that with operator bool() */ CollectionPtr readCollection(std::string&&) const noexcept;