ndn::security::pib::PibSqlite3 Class Reference

Pib backend implementation based on SQLite3 database. More...

#include <pib-sqlite3.hpp>

+ Inheritance diagram for ndn::security::pib::PibSqlite3:
+ Collaboration diagram for ndn::security::pib::PibSqlite3:

Public Member Functions

 PibSqlite3 (const std::string &location="")
 Create sqlite3-based PIB backed. More...
 
 ~PibSqlite3 ()
 Destruct and cleanup internal state. More...
 
void addCertificate (const v2::Certificate &certificate) final
 Add a certificate. More...
 
void addIdentity (const Name &identity) final
 Add an identity. More...
 
void addKey (const Name &identity, const Name &keyName, const uint8_t *key, size_t keyLen) final
 Add a key. More...
 
void clearIdentities () final
 Erasing all certificates, keys, and identities. More...
 
v2::Certificate getCertificate (const Name &certName) const final
 Get a certificate with name certName. More...
 
std::set< NamegetCertificatesOfKey (const Name &keyName) const final
 Get a list of certificate names of a key with id keyName. More...
 
v2::Certificate getDefaultCertificateOfKey (const Name &keyName) const final
 
Name getDefaultIdentity () const final
 Get the default identity. More...
 
Name getDefaultKeyOfIdentity (const Name &identity) const final
 
std::set< NamegetIdentities () const final
 Get the name of all the identities. More...
 
Buffer getKeyBits (const Name &keyName) const final
 Get the key bits of a key with name keyName. More...
 
std::set< NamegetKeysOfIdentity (const Name &identity) const final
 Get all the key names of an identity with name identity. More...
 
std::string getTpmLocator () const final
 Get TPM Locator. More...
 
bool hasCertificate (const Name &certName) const final
 Check the existence of a certificate with name certName. More...
 
bool hasIdentity (const Name &identity) const final
 Check the existence of an identity. More...
 
bool hasKey (const Name &keyName) const final
 Check the existence of a key with keyName. More...
 
void removeCertificate (const Name &certName) final
 Remove a certificate with name certName. More...
 
void removeIdentity (const Name &identity) final
 Remove an identity and related keys and certificates. More...
 
void removeKey (const Name &keyName) final
 Remove a key with keyName and related certificates. 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...
 
void setDefaultIdentity (const Name &identityName) final
 Set an identity with name identityName as the default 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...
 
void setTpmLocator (const std::string &tpmLocator) final
 Set the corresponding TPM information to tpmLocator. More...
 

Static Public Member Functions

static const std::string & getScheme ()
 

Detailed Description

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.

Constructor & Destructor Documentation

ndn::security::pib::PibSqlite3::PibSqlite3 ( const std::string &  location = "")
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.

Parameters
locationThe directory where the database file is located. By default, it points to the $HOME/.ndn directory.
Exceptions
PibImpl::Errorwhen initialization fails.

Definition at line 194 of file pib-sqlite3.cpp.

ndn::security::pib::PibSqlite3::~PibSqlite3 ( )

Destruct and cleanup internal state.

Definition at line 240 of file pib-sqlite3.cpp.

Member Function Documentation

void ndn::security::pib::PibSqlite3::addCertificate ( const v2::Certificate certificate)
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.

Parameters
certificateThe certificate to add.

Implements ndn::security::pib::PibImpl.

Definition at line 482 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::addIdentity ( const Name identity)
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.

Parameters
identityThe name of the identity to add.

Implements ndn::security::pib::PibImpl.

Definition at line 287 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::addKey ( const Name identity,
const Name keyName,
const uint8_t *  key,
size_t  keyLen 
)
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.

Parameters
identityThe name of the belonged identity.
keyNameThe key name.
keyThe public key bits.
keyLenThe length of the public key.

Implements ndn::security::pib::PibImpl.

Definition at line 363 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::clearIdentities ( )
finalvirtual

Erasing all certificates, keys, and identities.

Implements ndn::security::pib::PibImpl.

Definition at line 309 of file pib-sqlite3.cpp.

v2::Certificate ndn::security::pib::PibSqlite3::getCertificate ( const Name certName) const
finalvirtual

Get a certificate with name certName.

Parameters
certNameThe name of the certificate.
Returns
the certificate.
Exceptions
Pib::Errorthe certificate does not exist.

Implements ndn::security::pib::PibImpl.

Definition at line 520 of file pib-sqlite3.cpp.

std::set< Name > ndn::security::pib::PibSqlite3::getCertificatesOfKey ( const Name keyName) const
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.

Returns
The certificate name set. If the key does not exist, return an empty set.

Implements ndn::security::pib::PibImpl.

Definition at line 533 of file pib-sqlite3.cpp.

v2::Certificate ndn::security::pib::PibSqlite3::getDefaultCertificateOfKey ( const Name keyName) const
finalvirtual
Returns
Get the default certificate of a key with keyName.
Exceptions
Pib::Errorthe default certificate does not exist.

Implements ndn::security::pib::PibImpl.

Definition at line 563 of file pib-sqlite3.cpp.

Name ndn::security::pib::PibSqlite3::getDefaultIdentity ( ) const
finalvirtual

Get the default identity.

Returns
The name for the default identity.
Exceptions
Pib::Errorno default identity.

Implements ndn::security::pib::PibImpl.

Definition at line 336 of file pib-sqlite3.cpp.

Name ndn::security::pib::PibSqlite3::getDefaultKeyOfIdentity ( const Name identity) const
finalvirtual
Returns
The name of the default key of an identity with name identity.
Exceptions
Pib::Errorno default key or the identity does not exist.

Implements ndn::security::pib::PibImpl.

Definition at line 442 of file pib-sqlite3.cpp.

std::set< Name > ndn::security::pib::PibSqlite3::getIdentities ( ) const
finalvirtual

Get the name of all the identities.

Implements ndn::security::pib::PibImpl.

Definition at line 316 of file pib-sqlite3.cpp.

Buffer ndn::security::pib::PibSqlite3::getKeyBits ( const Name keyName) const
finalvirtual

Get the key bits of a key with name keyName.

Returns
key bits
Exceptions
Pib::Errorthe key does not exist.

Implements ndn::security::pib::PibImpl.

Definition at line 400 of file pib-sqlite3.cpp.

std::set< Name > ndn::security::pib::PibSqlite3::getKeysOfIdentity ( const Name identity) const
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.

Returns
the key name component set. If the identity does not exist, return an empty set.

Implements ndn::security::pib::PibImpl.

Definition at line 412 of file pib-sqlite3.cpp.

const std::string & ndn::security::pib::PibSqlite3::getScheme ( )
static

Definition at line 246 of file pib-sqlite3.cpp.

std::string ndn::security::pib::PibSqlite3::getTpmLocator ( ) const
finalvirtual

Get TPM Locator.

Implements ndn::security::pib::PibImpl.

Definition at line 268 of file pib-sqlite3.cpp.

bool ndn::security::pib::PibSqlite3::hasCertificate ( const Name certName) const
finalvirtual

Check the existence of a certificate with name certName.

Parameters
certNameThe name of the certificate.
Returns
true if the certificate exists, otherwise false.

Implements ndn::security::pib::PibImpl.

Definition at line 474 of file pib-sqlite3.cpp.

bool ndn::security::pib::PibSqlite3::hasIdentity ( const Name identity) const
finalvirtual

Check the existence of an identity.

Parameters
identityThe name of the identity.
Returns
true if the identity exists, otherwise false.

Implements ndn::security::pib::PibImpl.

Definition at line 279 of file pib-sqlite3.cpp.

bool ndn::security::pib::PibSqlite3::hasKey ( const Name keyName) const
finalvirtual

Check the existence of a key with keyName.

Returns
true if the key exists, otherwise false. Return false if the identity does not exist

Implements ndn::security::pib::PibImpl.

Definition at line 354 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::removeCertificate ( const Name certName)
finalvirtual

Remove a certificate with name certName.

If the certificate does not exist, do nothing.

Parameters
certNameThe name of the certificate.

Implements ndn::security::pib::PibImpl.

Definition at line 512 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::removeIdentity ( const Name identity)
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.

Parameters
identityThe name of the identity to remove.

Implements ndn::security::pib::PibImpl.

Definition at line 301 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::removeKey ( const Name keyName)
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 392 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::setDefaultCertificateOfKey ( const Name keyName,
const Name certName 
)
finalvirtual

Set a cert with name certName as the default of a key with keyName.

Exceptions
Pib::Errorthe certificate with name certName does not exist.

Implements ndn::security::pib::PibImpl.

Definition at line 550 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::setDefaultIdentity ( const Name identityName)
finalvirtual

Set an identity with name identityName as the default identity.

If identityName identity does not exist, it will be created.

Parameters
identityNameThe name for the default identity.

Implements ndn::security::pib::PibImpl.

Definition at line 328 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::setDefaultKeyOfIdentity ( const Name identity,
const Name keyName 
)
finalvirtual

Set an key with keyName as the default key of an identity with name identity.

Exceptions
Pib::Errorthe key does not exist.

Implements ndn::security::pib::PibImpl.

Definition at line 430 of file pib-sqlite3.cpp.

void ndn::security::pib::PibSqlite3::setTpmLocator ( const std::string &  tpmLocator)
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 253 of file pib-sqlite3.cpp.