Skip to content

Commit

Permalink
New Keyring API (#43)
Browse files Browse the repository at this point in the history
* Keyring - Rewrite API

* Tests - New Keyring Tests

* Update Changelog
  • Loading branch information
nlogozzo authored Aug 18, 2024
1 parent 13d1550 commit 2505b11
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 755 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 2024.8.3 (next)
### Breaking Changes
#### Keyring
- The `Nickvision::Keyring::Keyring` class has been rewritten for better performance and a cleaner API. Keyrings created with previous versions of libnick are no longer compatible.
- Removed `Nickvision::Keyring::KeyringDialogController`
- Removed `Nickvision::Keyring::Store`
### New APIs
None
### Fixes
None

## 2024.8.2
### Breaking Changes
None
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ add_library (${PROJECT_NAME}
"src/helpers/stringhelpers.cpp"
"src/keyring/credential.cpp"
"src/keyring/keyring.cpp"
"src/keyring/keyringdialogcontroller.cpp"
"src/keyring/passwordgenerator.cpp"
"src/keyring/passwordstrength.cpp"
"src/keyring/store.cpp"
"src/keyring/systemcredentials.cpp"
"src/localization/documentation.cpp"
"src/localization/gettext.cpp"
Expand Down Expand Up @@ -153,7 +151,6 @@ if (BUILD_TESTING)
"tests/notificationtests.cpp"
"tests/passwordtests.cpp"
"tests/processtests.cpp"
"tests/storetests.cpp"
"tests/stringtests.cpp"
"tests/systemcredentialstests.cpp"
"tests/systemtests.cpp"
Expand Down
15 changes: 0 additions & 15 deletions include/keyring/credential.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ namespace Nickvision::Keyring
class Credential
{
public:
/**
* @brief Constructs a credential.
* @param id The id of the credential
* @param name The name of the credential
* @param uri The uri of the credential (can also be used as a comment for the Credential)
* @param username The username of the credential
* @param password The password of the credential
*/
Credential(int id, const std::string& name, const std::string& uri, const std::string& username, const std::string& password);
/**
* @brief Constructs a credential.
* @param name The name of the credential
Expand All @@ -51,11 +42,6 @@ namespace Nickvision::Keyring
* @param password The password of the credential
*/
Credential(const std::string& name, const std::string& uri, const std::string& username, const std::string& password);
/**
* @brief Gets the id of the credential
* @return The id of the credential
*/
int getId() const;
/**
* @brief Gets the name of the credential
* @return The name of the credential
Expand Down Expand Up @@ -126,7 +112,6 @@ namespace Nickvision::Keyring
friend std::ostream& operator<<(std::ostream& os, const Credential& credential);

private:
int m_id;
std::string m_name;
std::string m_uri;
std::string m_username;
Expand Down
74 changes: 29 additions & 45 deletions include/keyring/keyring.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,94 +23,78 @@
#ifndef KEYRING_H
#define KEYRING_H

#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "credential.h"
#include "store.h"
#include "database/sqldatabase.h"

namespace Nickvision::Keyring
{
/**
* @brief A model of a keyring object for managing credentials.
* @brief The keyring is encrypted with a password stored in the system's credential manager.
*/
class Keyring
{
public:
/**
* @brief Constructs a Keyring.
* @brief If the system credential manager is not available, the object will be functional but will not save any data to disk.
* @param name The name of the keyring
*/
Keyring(const std::string& name);
/**
* @brief Gets the name of the keyring.
* @return The name of the keyring
* @return The name of the keyring.
*/
const std::string& getName() const;
/**
* @brief Gets all credentials in the keyring.
* @return The list of all credentials
* @brief Gets whether the keyring is saving data to disk.
* @return True if saving data to disk, else false
*/
std::vector<Credential> getAllCredentials() const;
bool isSavingToDisk() const;
/**
* @brief Gets the credential matching the provided id.
* @param id The id of the credential
* @return The credential matching the id, std::nullopt if no matching credential
* @brief Gets all credentials in the keyring.
* @return The list of all credentials
*/
std::optional<Credential> getCredential(int id) const;
const std::vector<Credential>& getCredentials() const;
/**
* @brief Gets the credentials containing the provided name.
* @param name The name
* @return The list of credentials matching the name
* @brief Gets the credential matching the provided name.
* @param name The name of the credential
* @return The credential matching the name, std::nullopt if no matching credential found
*/
std::vector<Credential> getCredentials(const std::string& name) const;
std::optional<Credential> getCredential(const std::string& name);
/**
* @brief Adds a credential to the keyring.
* @param credential The Credential to add
* @param credential The credential to add
* @return True if successful, else false
*/
bool addCredential(const Credential& credential);
/**
* @brief Updates a credential in the keyring.
* @param credential The Credential to update
* @param credential The credential to update
* @return True if successful, else false
*/
bool updateCredential(const Credential& credential);
/**
* @brief Deletes a credential from the keyring.
* @param id The id of the credential to delete
* @param name The name of the credential to delete
* @return True if successful, else false
*/
bool deleteCredential(int id);
bool deleteCredential(const std::string& name);
/**
* @brief Destroys the keyring and all of its data from disk. Once this method is called, the object should no longer be referenced, with or without success.
* @brief Destroys the keyring.
* @brief This will delete all data in the keyring and put the object in a state where no data can be saved to disk.
* @return True if successful, else false
*/
bool destroy();

private:
/**
* @brief Constructs a Keyring.
* @param store The Store database for the Keyring
*/
Keyring(const Store& store);
Store m_store;

public:
/**
* @brief Accesses a Keyring. The Keyring will first attempt to load an existing Store. If the Store doesn't exist, it will create a new Store.
* @param name The name of the store
* @param password The password to use for the store. If empty, the password will be fetched/created from the system's credential store
* @return The newly accessed keyring, std::nullopt if accessing failed
*/
static std::optional<Keyring> access(const std::string& name, std::string password = "");
/**
* @brief Gets whether or not a keyring exists with the provided name.
* @param name The name of the keyring to check
* @return True if a keyring with the provided name exists, else false
*/
static bool exists(const std::string& name);
/**
* @brief Destroys a keyring and all of its data from disk.
* @param name name of the keyring to destroy
* @return True if successful, else false
*/
static bool destroy(const std::string& name);
std::string m_name;
std::shared_ptr<Database::SqlDatabase> m_database;
std::vector<Credential> m_credentials;
};
}

Expand Down
114 changes: 0 additions & 114 deletions include/keyring/keyringdialogcontroller.h

This file was deleted.

Loading

0 comments on commit 2505b11

Please sign in to comment.