def getCertificatesOfKey(self, keyName): """ Get a list of certificate names of the key with id keyName. The returned certificate names can be used to create a PibCertificateContainer. With a certificate name and a backend implementation, one can obtain the certificate. :param Name keyName: The name of the key. :return: The set of certificate names. The Name objects are fresh copies. If the key does not exist, return an empty set. :rtype: set of Name """ certNames = set() try: cursor = self._database.cursor() cursor.execute( "SELECT certificate_name " + "FROM certificates JOIN keys ON certificates.key_id=keys.id " + "WHERE keys.key_name=?", (sqlite3.Binary(bytearray(keyName.wireEncode().buf())), )) rows = cursor.fetchall() for (encoding, ) in rows: name = Name() name.wireDecode(bytearray(encoding)) certNames.add(name) cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) return certNames
def getKeysOfIdentity(self, identityName): """ Get all the key names of the identity with the name identityName. The returned key names can be used to create a KeyContainer. With a key name and a backend implementation, one can create a Key front end instance. :param Name identityName: The name of the identity. :return: The set of key names. The Name objects are fresh copies. If the identity does not exist, return an empty set. :rtype: set of Name """ keyNames = set() try: cursor = self._database.cursor() cursor.execute( "SELECT key_name " + "FROM keys JOIN identities ON keys.identity_id=identities.id " + "WHERE identities.identity=?", (sqlite3.Binary(bytearray(identityName.wireEncode().buf())), )) rows = cursor.fetchall() for (encoding, ) in rows: name = Name() name.wireDecode(bytearray(encoding)) keyNames.add(name) cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) return keyNames
def getScheduleMembers(self, name): """ For each member using the given schedule, get the name and public key DER of the member's key. :param str name: The name of the schedule. :return: a new dictionary where the dictionary's key is the Name of the public key and the value is the Blob of the public key DER. Note that the member's identity name is keyName.getPrefix(-1). If the schedule name is not found, the dictionary is empty. :rtype: dictionary<Name, Blob> :raises GroupManagerDb.Error: For a database error. """ dictionary = {} try: cursor = self._database.cursor() cursor.execute( "SELECT key_name, pubkey " + "FROM members JOIN schedules ON members.schedule_id=schedules.schedule_id " + "WHERE schedule_name=?", (name,), ) results = cursor.fetchall() for (keyNameEncoding, keyEncoding) in results: keyName = Name() keyName.wireDecode(bytearray(keyNameEncoding), TlvWireFormat.get()) dictionary[keyName] = Blob(bytearray(keyEncoding), False) cursor.close() return dictionary except Exception as ex: raise GroupManagerDb.Error("Sqlite3GroupManagerDb.getScheduleMembers: SQLite error: " + str(ex))
def getDefaultIdentity(self): """ Get the default identity. :return: The name of the default identity, as a fresh copy. :rtype: Name :raises Pib.Error: For no default identity. """ encoding = None try: cursor = self._database.cursor() cursor.execute("SELECT identity FROM identities WHERE is_default=1") row = cursor.fetchone() if row != None: (encoding,) = row cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) if encoding != None: name = Name() name.wireDecode(bytearray(encoding)) return name else: raise Pib.Error("No default identity")
def getDefaultIdentity(self): """ Get the default identity. :return: The name of the default identity, as a fresh copy. :rtype: Name :raises Pib.Error: For no default identity. """ encoding = None try: cursor = self._database.cursor() cursor.execute( "SELECT identity FROM identities WHERE is_default=1") row = cursor.fetchone() if row != None: (encoding, ) = row cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) if encoding != None: name = Name() name.wireDecode(bytearray(encoding)) return name else: raise Pib.Error("No default identity")
def getScheduleMembers(self, name): """ For each member using the given schedule, get the name and public key DER of the member's key. :param str name: The name of the schedule. :return: a new dictionary where the dictionary's key is the Name of the public key and the value is the Blob of the public key DER. Note that the member's identity name is keyName.getPrefix(-1). If the schedule name is not found, the dictionary is empty. :rtype: dictionary<Name, Blob> :raises GroupManagerDb.Error: For a database error. """ dictionary = {} try: cursor = self._database.cursor() cursor.execute( "SELECT key_name, pubkey " + "FROM members JOIN schedules ON members.schedule_id=schedules.schedule_id " + "WHERE schedule_name=?", (name, )) results = cursor.fetchall() for (keyNameEncoding, keyEncoding) in results: keyName = Name() keyName.wireDecode(bytearray(keyNameEncoding), TlvWireFormat.get()) dictionary[keyName] = Blob(bytearray(keyEncoding), False) cursor.close() return dictionary except Exception as ex: raise GroupManagerDb.Error( "Sqlite3GroupManagerDb.getScheduleMembers: SQLite error: " + str(ex))
def listAllMembers(self): """ List all the members. :return: A new List of Name with the names of all members. :rtype: Array<Name> :raises GroupManagerDb.Error: For a database error. """ list = [] try: cursor = self._database.cursor() cursor.execute("SELECT member_name FROM members", ()) results = cursor.fetchall() for (nameEncoding, ) in results: identity = Name() identity.wireDecode(bytearray(nameEncoding), TlvWireFormat.get()) list.append(identity) cursor.close() return list except Exception as ex: raise GroupManagerDb.Error( "Sqlite3GroupManagerDb.listAllMembers: SQLite error: " + str(ex))
def getIdentities(self): """ Get the names of all the identities. :return: The a fresh set of identity names. The Name objects are fresh copies. :rtype: set of Name """ identities = set() try: cursor = self._database.cursor() cursor.execute("SELECT identity FROM identities") rows = cursor.fetchall() for (encoding, ) in rows: name = Name() name.wireDecode(bytearray(encoding)) identities.add(name) cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) return identities
def listAllMembers(self): """ List all the members. :return: A new List of Name with the names of all members. :rtype: Array<Name> :raises GroupManagerDb.Error: For a database error. """ list = [] try: cursor = self._database.cursor() cursor.execute("SELECT member_name FROM members", ()) results = cursor.fetchall() for (nameEncoding,) in results: identity = Name() identity.wireDecode(bytearray(nameEncoding), TlvWireFormat.get()) list.append(identity) cursor.close() return list except Exception as ex: raise GroupManagerDb.Error("Sqlite3GroupManagerDb.listAllMembers: SQLite error: " + str(ex))
def getDefaultKeyOfIdentity(self, identityName): """ Get the name of the default key for the identity with name identityName. :param Name identityName: The name of the identity. :return: The name of the default key, as a fresh copy. :rtype: Name :raises Pib.Error: If there is no default key or if the identity does not exist. """ if not self.hasIdentity(identityName): raise Pib.Error( "Identity `" + identityName.toUri() + "` does not exist") encoding = None try: cursor = self._database.cursor() cursor.execute( "SELECT key_name " + "FROM keys JOIN identities ON keys.identity_id=identities.id " + "WHERE identities.identity=? AND keys.is_default=1", (sqlite3.Binary(bytearray(identityName.wireEncode().buf())), )) row = cursor.fetchone() if row != None: (encoding,) = row cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) if encoding != None: name = Name() name.wireDecode(bytearray(encoding)) return name else: raise Pib.Error( "No default key for identity `" + identityName.toUri() + "`")
def getDefaultKeyOfIdentity(self, identityName): """ Get the name of the default key for the identity with name identityName. :param Name identityName: The name of the identity. :return: The name of the default key, as a fresh copy. :rtype: Name :raises Pib.Error: If there is no default key or if the identity does not exist. """ if not self.hasIdentity(identityName): raise Pib.Error("Identity `" + identityName.toUri() + "` does not exist") encoding = None try: cursor = self._database.cursor() cursor.execute( "SELECT key_name " + "FROM keys JOIN identities ON keys.identity_id=identities.id " + "WHERE identities.identity=? AND keys.is_default=1", (sqlite3.Binary(bytearray(identityName.wireEncode().buf())), )) row = cursor.fetchone() if row != None: (encoding, ) = row cursor.close() except Exception as ex: raise PibImpl.Error("PibSqlite3: SQLite error: " + str(ex)) if encoding != None: name = Name() name.wireDecode(bytearray(encoding)) return name else: raise Pib.Error("No default key for identity `" + identityName.toUri() + "`")