Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

psk_db_sql.cpp
Go to the documentation of this file.
1 /*
2 * (C) 2017 Jack Lloyd
3 *
4 * Botan is released under the Simplified BSD License (see license.txt)
5 */
6
7 #include <botan/psk_db_sql.h>
8
9 namespace Botan {
10
11 Encrypted_PSK_Database_SQL::Encrypted_PSK_Database_SQL(const secure_vector<uint8_t>& master_key,
12 std::shared_ptr<SQL_Database> db,
13 const std::string& table_name) :
14 Encrypted_PSK_Database(master_key),
15 m_db(db),
16 m_table_name(table_name)
17 {
18 m_db->create_table(
19 "create table if not exists " + m_table_name +
20 "(psk_name TEXT PRIMARY KEY, psk_value TEXT)");
21 }
22
23 void Encrypted_PSK_Database_SQL::kv_del(const std::string& name)
24 {
25 auto stmt = m_db->new_statement("delete from " + m_table_name + " where psk_name=?1");
26 stmt->bind(1, name);
27 stmt->spin();
28 }
29
30 void Encrypted_PSK_Database_SQL::kv_set(const std::string& name, const std::string& value)
31 {
32 auto stmt = m_db->new_statement("insert or replace into " + m_table_name + " values(?1, ?2)");
33
34 stmt->bind(1, name);
35 stmt->bind(2, value);
36
37 stmt->spin();
38 }
39
40 std::string Encrypted_PSK_Database_SQL::kv_get(const std::string& name) const
41 {
42 auto stmt = m_db->new_statement("select psk_value from " + m_table_name +
43 " where psk_name = ?1");
44
45 stmt->bind(1, name);
46
47 while(stmt->step())
48 {
49 return stmt->get_str(0);
50 }
51 return "";
52 }
53
54 std::set<std::string> Encrypted_PSK_Database_SQL::kv_get_all() const
55 {
56 std::set<std::string> names;
57
58 auto stmt = m_db->new_statement("select psk_name from " + m_table_name);
59
60 while(stmt->step())
61 {
62 names.insert(stmt->get_str(0));
63 }
64
65 return names;
66 }
67
68 }
69
Botan::Encrypted_PSK_Database
Definition: psk_db.h:90
Botan::Encrypted_PSK_Database_SQL::Encrypted_PSK_Database_SQL
Encrypted_PSK_Database_SQL(const secure_vector< uint8_t > &master_key, std::shared_ptr< SQL_Database > db, const std::string &table_name)
Definition: psk_db_sql.cpp:11
name
std::string name
Definition: commoncrypto_hash.cpp:23
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan
Definition: alg_id.cpp:13