Class: R509::CRL::SQLiteReaderWriter
- Inherits:
-
ReaderWriter
- Object
- ReaderWriter
- R509::CRL::SQLiteReaderWriter
- Defined in:
- lib/r509/crl/sqlite_reader_writer.rb
Overview
SQLite-based reader/writer for CRL data.
Instance Method Summary collapse
-
#initialize(filename_or_db) ⇒ SQLiteReaderWriter
constructor
Create an SQLite based persistence.
-
#read_list {|serial, reason, revoke_time| ... } ⇒ Object
Reads a CRL list file from the SQLite database.
-
#read_number ⇒ Object
read the CRL number from SQLite.
-
#remove_list_entry(serial) ⇒ Object
Remove a CRL list entry from SQLite.
-
#write_list_entry(serial, revoke_time, reason) ⇒ Object
Appends a CRL list entry to the SQLite database.
-
#write_number(crl_number) ⇒ Object
write the CRL number to SQLite.
Constructor Details
#initialize(filename_or_db) ⇒ SQLiteReaderWriter
Create an SQLite based persistence
8 9 10 11 12 13 14 15 16 |
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 8 def initialize(filename_or_db) if filename_or_db.is_a? SQLite3::Database @db = filename_or_db else @db = SQLite3::Database.new(file) end # create tables if missing ensure_schema end |
Instance Method Details
#read_list {|serial, reason, revoke_time| ... } ⇒ Object
Reads a CRL list file from the SQLite database
23 24 25 26 27 28 29 30 31 |
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 23 def read_list @db.execute('SELECT serial,reason,revoked_at from revoked_serials') do |row| serial = row[0].to_i reason = row[1] revoke_time = row[2] yield serial, reason, revoke_time end nil end |
#read_number ⇒ Object
read the CRL number from SQLite
48 49 50 |
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 48 def read_number @db.get_first_value 'SELECT number from crl_number' end |
#remove_list_entry(serial) ⇒ Object
Remove a CRL list entry from SQLite
43 44 45 |
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 43 def remove_list_entry(serial) @db.execute('DELETE FROM revoked_serials WHERE serial=?', serial.to_s) end |
#write_list_entry(serial, revoke_time, reason) ⇒ Object
Appends a CRL list entry to the SQLite database
37 38 39 |
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 37 def write_list_entry(serial, revoke_time, reason) @db.execute('INSERT INTO revoked_serials (serial, revoked_at, reason) VALUES (?,?,?)', serial.to_s, revoke_time, reason) end |
#write_number(crl_number) ⇒ Object
write the CRL number to SQLite
53 54 55 |
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 53 def write_number(crl_number) @db.execute('UPDATE crl_number SET number=?', crl_number) end |