Pib backend implementation based on SQLite3 database. More...
#include <pib-sqlite3.hpp>
Public Member Functions | |
PibSqlite3 (const std::string &location="") | |
Create sqlite3-based PIB backed. More... | |
~PibSqlite3 () final | |
Destruct and cleanup internal state. More... | |
void | setTpmLocator (const std::string &tpmLocator) final |
Set the corresponding TPM information to tpmLocator . More... | |
std::string | getTpmLocator () const final |
Get TPM Locator. More... | |
bool | hasIdentity (const Name &identity) const final |
Check the existence of an identity. More... | |
void | addIdentity (const Name &identity) final |
Add an identity. More... | |
void | removeIdentity (const Name &identity) final |
Remove an identity and related keys and certificates. More... | |
void | clearIdentities () final |
Erasing all certificates, keys, and identities. More... | |
std::set< Name > | getIdentities () const final |
Get the name of all the identities. More... | |
void | setDefaultIdentity (const Name &identityName) final |
Set an identity with name identityName as the default identity. More... | |
Name | getDefaultIdentity () const final |
Get the default identity. More... | |
bool | hasKey (const Name &keyName) const final |
Check the existence of a key with keyName . More... | |
void | addKey (const Name &identity, const Name &keyName, span< const uint8_t > key) final |
Add a key. More... | |
void | removeKey (const Name &keyName) final |
Remove a key with keyName and related certificates. More... | |
Buffer | getKeyBits (const Name &keyName) const final |
Get the key bits of a key with name keyName . More... | |
std::set< Name > | getKeysOfIdentity (const Name &identity) const final |
Get all the key names of an identity with name identity . More... | |
void | setDefaultKeyOfIdentity (const Name &identity, const Name &keyName) final |
Set an key with keyName as the default key of an identity with name identity . More... | |
Name | getDefaultKeyOfIdentity (const Name &identity) const final |
bool | hasCertificate (const Name &certName) const final |
Check the existence of a certificate with name certName . More... | |
void | addCertificate (const Certificate &certificate) final |
Add a certificate. More... | |
void | removeCertificate (const Name &certName) final |
Remove a certificate with name certName . More... | |
Certificate | getCertificate (const Name &certName) const final |
Get a certificate with name certName . More... | |
std::set< Name > | getCertificatesOfKey (const Name &keyName) const final |
Get a list of certificate names of a key with id keyName . More... | |
void | setDefaultCertificateOfKey (const Name &keyName, const Name &certName) final |
Set a cert with name certName as the default of a key with keyName . More... | |
Certificate | getDefaultCertificateOfKey (const Name &keyName) const final |
Public Member Functions inherited from ndn::security::pib::PibImpl | |
virtual | ~PibImpl ()=default |
Static Public Member Functions | |
static const std::string & | getScheme () |
Pib backend implementation based on SQLite3 database.
All the contents in Pib are stored in a SQLite3 database file. This backend provides more persistent storage than PibMemory.
Definition at line 39 of file pib-sqlite3.hpp.
|
explicit |
Create sqlite3-based PIB backed.
This method will create a SQLite3 database file under the directory location
. If the directory does not exist, it will be created automatically. It assumes that the directory does not contain a PIB database of an older version, It is user's responsibility to update the older version database or remove the database.
location | The directory where the database file is located. By default, it points to the $HOME/.ndn directory. |
PibImpl::Error | when initialization fails. |
Definition at line 194 of file pib-sqlite3.cpp.
References NDN_THROW.
|
final |
Destruct and cleanup internal state.
Definition at line 241 of file pib-sqlite3.cpp.
|
static |
Definition at line 247 of file pib-sqlite3.cpp.
|
finalvirtual |
Set the corresponding TPM information to tpmLocator
.
This method does not reset contents of the PIB
Implements ndn::security::pib::PibImpl.
Definition at line 254 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), and ndn::util::Sqlite3Statement::step().
|
finalvirtual |
Get TPM Locator.
Implements ndn::security::pib::PibImpl.
Definition at line 269 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::getString(), and ndn::util::Sqlite3Statement::step().
|
finalvirtual |
Check the existence of an identity.
identity | The name of the identity. |
Implements ndn::security::pib::PibImpl.
Definition at line 280 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
Referenced by addIdentity(), getDefaultKeyOfIdentity(), and setDefaultIdentity().
|
finalvirtual |
Add an identity.
If the identity already exists, do nothing. If no default identity has been set, set the added one as default identity.
identity | The name of the identity to add. |
Implements ndn::security::pib::PibImpl.
Definition at line 288 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), hasIdentity(), setDefaultIdentity(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
Referenced by addKey().
|
finalvirtual |
Remove an identity and related keys and certificates.
If the default identity is being removed, no default identity will be selected. If the identity does not exist, do nothing.
identity | The name of the identity to remove. |
Implements ndn::security::pib::PibImpl.
Definition at line 302 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
|
finalvirtual |
Erasing all certificates, keys, and identities.
Implements ndn::security::pib::PibImpl.
Definition at line 310 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::step().
|
finalvirtual |
Get the name of all the identities.
Implements ndn::security::pib::PibImpl.
Definition at line 317 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::getBlock(), and ndn::util::Sqlite3Statement::step().
|
finalvirtual |
Set an identity with name identityName
as the default identity.
identityName | The name for the default identity. |
Error | If identityName identity does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 329 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), hasIdentity(), NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().
Referenced by addIdentity().
|
finalvirtual |
Get the default identity.
Pib::Error | no default identity. |
Implements ndn::security::pib::PibImpl.
Definition at line 340 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::getBlock(), ns3::ndn::Name, NDN_THROW, and ndn::util::Sqlite3Statement::step().
|
finalvirtual |
Check the existence of a key with keyName
.
Implements ndn::security::pib::PibImpl.
Definition at line 358 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
Referenced by addKey(), and setDefaultKeyOfIdentity().
|
finalvirtual |
Add a key.
If a key with the same name already exists, overwrite the key. If the identity does not exist, it will be created. If no default key of the identity has been set, set the added one as default key of the identity. If no default identity has been set, identity
becomes the default.
identity | The name of the identity that will own the added key. |
keyName | The key name. |
key | The public key bits. |
Implements ndn::security::pib::PibImpl.
Definition at line 367 of file pib-sqlite3.cpp.
References addIdentity(), ndn::util::Sqlite3Statement::bind(), hasKey(), setDefaultKeyOfIdentity(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
Referenced by addCertificate().
|
finalvirtual |
Remove a key with keyName
and related certificates.
If the key does not exist, do nothing.
Implements ndn::security::pib::PibImpl.
Definition at line 395 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
Get the key bits of a key with name keyName
.
Pib::Error | the key does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 403 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::getBlob(), ndn::util::Sqlite3Statement::getSize(), NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().
|
finalvirtual |
Get all the key names of an identity with name identity
.
The returned key names can be used to create a KeyContainer. With key name and backend implementation, one can create a Key frontend instance.
Implements ndn::security::pib::PibImpl.
Definition at line 415 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::getBlock(), ns3::ndn::Name, ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
|
finalvirtual |
Set an key with keyName
as the default key of an identity with name identity
.
Pib::Error | the key does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 433 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), hasKey(), NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().
Referenced by addKey().
|
finalvirtual |
identity
.Pib::Error | no default key or the identity does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 445 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::getBlock(), hasIdentity(), ns3::ndn::Name, NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().
|
finalvirtual |
Check the existence of a certificate with name certName
.
certName | The name of the certificate. |
Implements ndn::security::pib::PibImpl.
Definition at line 477 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
Referenced by addCertificate(), and setDefaultCertificateOfKey().
|
finalvirtual |
Add a certificate.
If a certificate with the same name (without implicit digest) already exists, overwrite the certificate. If the key or identity does not exist, they will be created. If no default certificate of the key has been set, set the added one as default certificate of the key. If no default key was set for the identity, it will be set as default key for the identity. If no default identity was selected, the certificate's identity becomes default.
certificate | The certificate to add. |
Implements ndn::security::pib::PibImpl.
Definition at line 485 of file pib-sqlite3.cpp.
References addKey(), ndn::util::Sqlite3Statement::bind(), hasCertificate(), setDefaultCertificateOfKey(), and ndn::util::Sqlite3Statement::step().
|
finalvirtual |
Remove a certificate with name certName
.
If the certificate does not exist, do nothing.
certName | The name of the certificate. |
Implements ndn::security::pib::PibImpl.
Definition at line 514 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
|
finalvirtual |
Get a certificate with name certName
.
certName | The name of the certificate. |
Pib::Error | the certificate does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 522 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::getBlock(), NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().
|
finalvirtual |
Get a list of certificate names of a key with id keyName
.
The returned certificate names can be used to create a CertificateContainer. With certificate name and backend implementation, one can obtain the certificate.
Implements ndn::security::pib::PibImpl.
Definition at line 535 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::getBlock(), ndn::util::Sqlite3Statement::step(), and ndn::Name::wireEncode().
|
finalvirtual |
Set a cert with name certName
as the default of a key with keyName
.
Pib::Error | the certificate with name certName does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 552 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), hasCertificate(), NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().
Referenced by addCertificate().
|
finalvirtual |
keyName
.Pib::Error | the default certificate does not exist. |
Implements ndn::security::pib::PibImpl.
Definition at line 565 of file pib-sqlite3.cpp.
References ndn::util::Sqlite3Statement::bind(), ndn::util::Sqlite3Statement::getBlock(), NDN_THROW, ndn::util::Sqlite3Statement::step(), ndn::Name::toUri(), and ndn::Name::wireEncode().