Class: Iostrust::Simulator
- Inherits:
-
Object
- Object
- Iostrust::Simulator
- Defined in:
- lib/iostrust/simulator.rb
Instance Method Summary collapse
- #add_cert(cert) ⇒ Object
- #add_certs(certs) ⇒ Object
- #backup ⇒ Object
- #backup_path ⇒ Object
-
#initialize(path) ⇒ Simulator
constructor
A new instance of Simulator.
- #restore ⇒ Object
Constructor Details
#initialize(path) ⇒ Simulator
Returns a new instance of Simulator.
8 9 10 |
# File 'lib/iostrust/simulator.rb', line 8 def initialize(path) @path = File.join(path, 'Keychains/TrustStore.sqlite3') end |
Instance Method Details
#add_cert(cert) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/iostrust/simulator.rb', line 26 def add_cert(cert) puts "Start adding to #{@path}:" keychain_dir = File.dirname(@path) is_new_db = !Dir.exists?(keychain_dir) if is_new_db Dir.mkdir keychain_dir else puts "Backup..." backup() end puts "Adding #{cert.cert_name}..." SQLite3::Database.new @path do |db| sha1 = SQLite3::Blob.new(cert.sha1) subj = SQLite3::Blob.new(cert.subj) tset = SQLite3::Blob.new(cert.tset) data = SQLite3::Blob.new(cert.data) begin if is_new_db db.execute "CREATE TABLE tsettings(sha1 BLOB NOT NULL DEFAULT '',subj BLOB NOT NULL DEFAULT '',tset BLOB,data BLOB,PRIMARY KEY(sha1));" end db.execute "INSERT INTO 'tsettings' (sha1, subj, tset, data) VALUES(?,?,?,?)", sha1, subj, tset, data rescue SQLite3::ConstraintException => e puts "Certificates was not added : Already presents" else puts "OK" end end end |
#add_certs(certs) ⇒ Object
59 60 61 |
# File 'lib/iostrust/simulator.rb', line 59 def add_certs(certs) certs.each { |cert| add_cert(cert) } end |
#backup ⇒ Object
15 16 17 |
# File 'lib/iostrust/simulator.rb', line 15 def backup FileUtils.cp_r(@path, backup_path) end |
#backup_path ⇒ Object
12 13 14 |
# File 'lib/iostrust/simulator.rb', line 12 def backup_path "#{@path}.iostrust.backup" end |
#restore ⇒ Object
19 20 21 22 23 |
# File 'lib/iostrust/simulator.rb', line 19 def restore return if not File.exists? backup_path FileUtils.rm_r(@path) FileUtils.mv(backup_path, @path) end |