commit a0602badd4c0e3ac8a5ef0b03f1ab48ad3abc40d
Author: David Friesecký <frieseck@students.zcu.cz>
Date:   Thu Apr 1 00:12:37 2021 +0200

    Re #8471 - Added comments for CRUD functions

diff --git a/src/constants.py b/src/constants.py
index 70f4ba1..ee8522e 100644
--- a/src/constants.py
+++ b/src/constants.py
@@ -1,9 +1,11 @@
 DATABASE_FILE = "../../../../db/database_sqlite.db"
 
+# Types of certificates
 ROOT_CA_ID = 1
 INTERMEDIATE_CA_ID = 2
 CERTIFICATE_ID = 3
 
+# Usage types of certificates
 CA_ID = 1
 SSL_ID = 2
 SIGNATURE_ID = 3
diff --git a/src/impl/certificate_repository_impl.py b/src/impl/certificate_repository_impl.py
index f140349..8735be7 100644
--- a/src/impl/certificate_repository_impl.py
+++ b/src/impl/certificate_repository_impl.py
@@ -10,6 +10,25 @@ class CertificateRepositoryImpl(IRepository):
 
     def create(self, common_name: str, valid_from: str, valid_to: str, pem_data: str,
                private_key_id: int, type_id: int, parent_id: int, usages: Dict[int, bool]) -> bool:
+        """
+        Creates a certificate
+
+        :param common_name: private key of the certificate
+        :param valid_from: string of date (time) of validation after (from)
+        :param valid_to: string of date (time) of validation before (to)
+        :param pem_data: data of certificate in a PEM format
+        :param private_key_id: ID from PrivateKeys table for specific private key
+        :param type_id: ID from CertificateTypes table (ROOT_CA_ID=1, INTERMEDIATE_CA_ID=2, CERTIFICATE_ID=3)
+        :param parent_id: ID from Certificates table for specific parent certificate
+            for root CA use e.g. -1 (ID will be changed after created certificate)
+        :param usages: dictionary of usages IDs which certificate use
+            Dictionary[Integer, Boolean]
+                - Key = ID (CA_ID=1, SSL_ID=2, SIGNATURE_ID=3, AUTHENTICATION_ID=4)
+                - Value = used=True/unused=False
+
+        :return: the result of whether the creation was successful
+        """
+
         sql = (f"INSERT INTO {TAB_CERTIFICATES} ({COL_COMMON_NAME},{COL_VALID_FROM},{COL_VALID_TO},{COL_PEM_DATA},"
                f"{COL_PRIVATE_KEY_ID},{COL_TYPE_ID},{COL_PARENT_ID})"
                f"VALUES(?,?,?,?,?,?,?)")
@@ -18,6 +37,14 @@ class CertificateRepositoryImpl(IRepository):
         return result
 
     def read(self, certificate_id: int = None):
+        """
+        Reads (selects) a certificate or certificates
+
+        :param certificate_id: ID of specific certificate
+
+        :return: instance of Certificate class if ID was used otherwise list of this instances
+        """
+
         sql_extend = ""
 
         if certificate_id is not None:
@@ -54,6 +81,26 @@ class CertificateRepositoryImpl(IRepository):
     def update(self, certificate_id: int, common_name: str = None, valid_from: str = None, valid_to: str = None,
                pem_data: str = None, private_key_id: int = None, type_id: int = None, parent_id: int = None,
                usages: Dict[int, bool] = None) -> bool:
+        """
+        Updates a certificate
+
+        :param certificate_id: ID of specific certificate
+        :param common_name: private key of the certificate
+        :param valid_from: string of date (time) of validation after (from)
+        :param valid_to: string of date (time) of validation before (to)
+        :param pem_data: data of certificate in a PEM format
+        :param private_key_id: ID from PrivateKeys table for specific private key
+        :param type_id: ID from CertificateTypes table (ROOT_CA_ID=1, INTERMEDIATE_CA_ID=2, CERTIFICATE_ID=3)
+        :param parent_id: ID from Certificates table for specific parent certificate
+            for root CA use e.g. -1 (ID will be changed after created certificate)
+        :param usages: dictionary of usages IDs which certificate use
+            Dictionary[Integer, Boolean]
+                - Key = ID (CA_ID=1, SSL_ID=2, SIGNATURE_ID=3, AUTHENTICATION_ID=4)
+                - Value = used=True/unused=False
+
+        :return: the result of whether the updation was successful
+        """
+
         updated_list = []
         values = []
         if common_name is not None:
@@ -84,6 +131,14 @@ class CertificateRepositoryImpl(IRepository):
         return result
 
     def delete(self, certificate_id: int) -> bool:
+        """
+        Deletes a certificate
+
+        :param certificate_id: ID of specific certificate
+
+        :return: the result of whether the deletion was successful
+        """
+
         sql = f"DELETE FROM {TAB_CERTIFICATES} WHERE {COL_ID} = ?"
         result = DBManager.delete(sql, certificate_id, True)
         return result
diff --git a/src/impl/db_manager.py b/src/impl/db_manager.py
index 565c20a..33ef60c 100644
--- a/src/impl/db_manager.py
+++ b/src/impl/db_manager.py
@@ -10,6 +10,19 @@ class DBManager(IRepository):
 
     @staticmethod
     def create(sql: str, values: List, usages: Dict[int, bool] = None) -> bool:
+        """
+        Creates an item in database
+
+        :param sql: SQL query for creation (parameter values are replaced by question mark)
+        :param values: list of parameter values
+        :param usages: dictionary of usages IDs which certificate use
+            Dictionary[Integer, Boolean]
+                - Key = ID (CA_ID=1, SSL_ID=2, SIGNATURE_ID=3, AUTHENTICATION_ID=4)
+                - Value = used=True/unused=False
+
+        :return: the result of whether the creation was successful
+        """
+
         conn = None
         try:
             conn = sqlite3.connect(DATABASE_FILE)
@@ -35,6 +48,15 @@ class DBManager(IRepository):
 
     @staticmethod
     def read(sql: str, item_id: int = None):
+        """
+        Reads (selecs) an item or items from database
+
+        :param sql: SQL query for selection (parameter values are replaced by question mark)
+        :param item_id: ID of specific item
+
+        :return: list of rows selected from database
+        """
+
         conn = None
         try:
             conn = sqlite3.connect(DATABASE_FILE)
@@ -57,6 +79,20 @@ class DBManager(IRepository):
 
     @staticmethod
     def update(sql: str, item_id: int, values: List, usages: Dict[int, bool] = None) -> bool:
+        """
+        Updates an item in database
+
+        :param sql: SQL query for creation (parameter values are replaced by question mark)
+        :param item_id: ID of specific item
+        :param values: list of parameter values
+        :param usages: dictionary of usages IDs which certificate use
+            Dictionary[Integer, Boolean]
+                - Key = ID (CA_ID=1, SSL_ID=2, SIGNATURE_ID=3, AUTHENTICATION_ID=4)
+                - Value = used=True/unused=False
+
+        :return: the result of whether the updation was successful
+        """
+
         conn = None
         try:
             values.append(item_id)
@@ -88,6 +124,17 @@ class DBManager(IRepository):
 
     @staticmethod
     def delete(sql: str, item_id: int, delete_usages: bool) -> bool:
+        """
+        Deletes an item from database
+
+        :param sql: SQL query for selection (parameter values are replaced by question mark)
+        :param item_id: ID of specific item
+        :param delete_usages: flag specifying whether to erase rows with specific id
+            from the table of usages (CertificateUsages)
+
+        :return: the result of whether the deletion was successful
+        """
+
         conn = None
         try:
             conn = sqlite3.connect(DATABASE_FILE)
diff --git a/src/impl/private_key_repository_impl.py b/src/impl/private_key_repository_impl.py
index 9082ac6..f95f100 100644
--- a/src/impl/private_key_repository_impl.py
+++ b/src/impl/private_key_repository_impl.py
@@ -7,11 +7,28 @@ from ..constants import *
 class PrivateKeyRepositoryImpl(IRepository):
 
     def create(self, private_key: str, password: str) -> bool:
+        """
+        Creates a private key
+
+        :param private_key: private key
+        :param password: passphrase for encode private key
+
+        :return: the result of whether the creation was successful
+        """
+
         sql = f"INSERT INTO {TAB_PRIVATE_KEYS} ({COL_PRIVATE_KEY},{COL_PASSWORD}) VALUES(?,?)"
         result = DBManager.create(sql, [private_key, password])
         return result
 
     def read(self, private_key_id: int = None):
+        """
+        Reads (selects) a private key
+
+        :param private_key_id: ID of specific private
+
+        :return: instance of PrivateKey class if ID was used otherwise list of this instances
+        """
+
         sql_extend = ""
 
         if private_key_id is not None:
@@ -31,6 +48,16 @@ class PrivateKeyRepositoryImpl(IRepository):
         return private_keys
 
     def update(self, private_key_id: int, private_key: str = None, password: str = None) -> bool:
+        """
+        Updates a private key
+
+        :param private_key_id: ID of specific private key
+        :param private_key: private key
+        :param password: passphrase for encode private key
+
+        :return: the result of whether the updation was successful
+        """
+
         updated_list = []
         values = []
         if private_key is not None:
@@ -46,6 +73,14 @@ class PrivateKeyRepositoryImpl(IRepository):
         return result
 
     def delete(self, private_key_id: int) -> bool:
+        """
+        Deletes a private key
+
+        :param private_key_id: ID of specific private key
+
+        :return: the result of whether the deletion was successful
+        """
+
         sql = f"DELETE FROM {TAB_PRIVATE_KEYS} WHERE {COL_ID} = ?"
         result = DBManager.delete(sql, private_key_id, False)
         return result
