Repository: randombit/botan
Pull request #2449 (2020-11-04 14:29:08)

Merge psk_db_sql.h into psk_db.h


Patch:
diff --git a/doc/api_ref/psk_db.rst b/doc/api_ref/psk_db.rst
index 2668c6bad..d9f8bf79b 100644
--- a/doc/api_ref/psk_db.rst
+++ b/doc/api_ref/psk_db.rst
@@ -6,7 +6,8 @@ PSK Database
 Many applications need to store pre-shared keys (hereafter PSKs) for
 authentication purposes.
 
-An abstract interface to PSK stores is provided in ``psk_db.h``
+An abstract interface to PSK stores, along with some implementations
+of same, are provided in ``psk_db.h``
 
 .. cpp:class:: PSK_Database
 
@@ -75,7 +76,8 @@ encrypts both names and PSKs. It must be subclassed to provide the storage.
       multiple different master keys with the same underlying storage. Each
       master key will be responsible for a subset of the keys. An attacker who
       knows one of the keys will be able to tell there are other values
-      encrypted under another key.
+      encrypted under another key, but will not be able to tell how many other
+      master keys are in use.
 
    .. cpp:function:: virtual void kv_set(const std::string& index, const std::string& value) = 0
 
@@ -96,7 +98,7 @@ encrypts both names and PSKs. It must be subclassed to provide the storage.
       non-empty string).
 
 A subclass of ``Encrypted_PSK_Database`` which stores data in a SQL database
-is also available. This class is declared in ``psk_db_sql.h``:
+is also available.
 
 .. cpp:class:: Encrypted_PSK_Database_SQL : public Encrypted_PSK_Database
 
diff --git a/src/cli/psk.cpp b/src/cli/psk.cpp
index 83b60225d..35e38292d 100644
--- a/src/cli/psk.cpp
+++ b/src/cli/psk.cpp
@@ -8,7 +8,7 @@
 
 #if defined(BOTAN_HAS_PSK_DB) && defined(BOTAN_HAS_SQLITE3)
 
-#include <botan/psk_db_sql.h>
+#include <botan/psk_db.h>
 #include <botan/sqlite3.h>
 #include <botan/hex.h>
 
diff --git a/src/lib/psk_db/psk_db.h b/src/lib/psk_db/psk_db.h
index 39686a995..06358935c 100644
--- a/src/lib/psk_db/psk_db.h
+++ b/src/lib/psk_db/psk_db.h
@@ -141,6 +141,26 @@ class BOTAN_PUBLIC_API(2,4) Encrypted_PSK_Database : public PSK_Database
       secure_vector<uint8_t> m_wrap_key;
    };
 
+class SQL_Database;
+
+class BOTAN_PUBLIC_API(2,4) Encrypted_PSK_Database_SQL : public Encrypted_PSK_Database
+   {
+   public:
+      Encrypted_PSK_Database_SQL(const secure_vector<uint8_t>& master_key,
+                                 std::shared_ptr<SQL_Database> db,
+                                 const std::string& table_name);
+
+      ~Encrypted_PSK_Database_SQL();
+   private:
+      void kv_set(const std::string& index, const std::string& value) override;
+      std::string kv_get(const std::string& index) const override;
+      void kv_del(const std::string& index) override;
+      std::set<std::string> kv_get_all() const override;
+
+      std::shared_ptr<SQL_Database> m_db;
+      const std::string m_table_name;
+   };
+
 }
 
 #endif
diff --git a/src/lib/psk_db/psk_db_sql.cpp b/src/lib/psk_db/psk_db_sql.cpp
index 3a43e7380..92dcb5f1d 100644
--- a/src/lib/psk_db/psk_db_sql.cpp
+++ b/src/lib/psk_db/psk_db_sql.cpp
@@ -4,7 +4,8 @@
 * Botan is released under the Simplified BSD License (see license.txt)
 */
 
-#include <botan/psk_db_sql.h>
+#include <botan/psk_db.h>
+#include <botan/database.h>
 
 namespace Botan {
 
@@ -20,6 +21,11 @@ Encrypted_PSK_Database_SQL::Encrypted_PSK_Database_SQL(const secure_vector<uint8
       "(psk_name TEXT PRIMARY KEY, psk_value TEXT)");
    }
 
+Encrypted_PSK_Database_SQL::~Encrypted_PSK_Database_SQL()
+   {
+   /* for ~unique_ptr */
+   }
+
 void Encrypted_PSK_Database_SQL::kv_del(const std::string& name)
    {
    auto stmt = m_db->new_statement("delete from " + m_table_name + " where psk_name=?1");
diff --git a/src/lib/psk_db/psk_db_sql.h b/src/lib/psk_db/psk_db_sql.h
index fddadfc30..170ca674c 100644
--- a/src/lib/psk_db/psk_db_sql.h
+++ b/src/lib/psk_db/psk_db_sql.h
@@ -8,27 +8,6 @@
 #define BOTAN_PSK_DB_SQL_H_
 
 #include <botan/psk_db.h>
-#include <botan/database.h>
-
-namespace Botan {
-
-class BOTAN_PUBLIC_API(2,4) Encrypted_PSK_Database_SQL : public Encrypted_PSK_Database
-   {
-   public:
-      Encrypted_PSK_Database_SQL(const secure_vector<uint8_t>& master_key,
-                                 std::shared_ptr<SQL_Database> db,
-                                 const std::string& table_name);
-
-   private:
-      void kv_set(const std::string& index, const std::string& value) override;
-      std::string kv_get(const std::string& index) const override;
-      void kv_del(const std::string& index) override;
-      std::set<std::string> kv_get_all() const override;
-
-      std::shared_ptr<SQL_Database> m_db;
-      const std::string m_table_name;
-   };
-
-}
+BOTAN_DEPRECATED_HEADER(psk_db_sql.h)
 
 #endif


Test patch:
diff --git a/src/tests/test_psk_db.cpp b/src/tests/test_psk_db.cpp
index f81753541..fc2501fa3 100644
--- a/src/tests/test_psk_db.cpp
+++ b/src/tests/test_psk_db.cpp
@@ -11,7 +11,6 @@
 #include <botan/psk_db.h>
 
 #if defined(BOTAN_HAS_SQLITE3)
-  #include <botan/psk_db_sql.h>
   #include <botan/sqlite3.h>
 #endif