Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 2 files changed
  • 0 comments
  • 1 contributor

Showing 2 changed files with 63 additions and 0 deletions. Show diff stats Hide diff stats

  1. +44 0 keepass.c
  2. +19 0 test/entries.rb
44 keepass.c
@@ -173,6 +173,41 @@ rb_kp_db_groups(VALUE self)
173 173 return groups;
174 174 }
175 175
  176 +VALUE
  177 +rb_kp_db_entries(VALUE self)
  178 +{
  179 + VALUE kdb_object;
  180 + kpass_db *kdb = NULL;
  181 + VALUE entries;
  182 + uint32_t i;
  183 +
  184 + kdb_object = rb_ivar_get(self, rb_intern("@kdb"));
  185 + Data_Get_Struct(kdb_object, kpass_db, kdb);
  186 +
  187 + entries = rb_ary_new();
  188 +
  189 + for(i = 0; i < kdb->entries_len; i++) {
  190 + kpass_entry *entry = kdb->entries[i];
  191 + VALUE rb_entry;
  192 +
  193 + if(! strcmp(entry->title, "Meta-Info")) {
  194 + continue;
  195 + }
  196 + rb_entry = rb_funcall(cEntry, rb_intern("new"), 0);
  197 +
  198 + rb_ivar_set(rb_entry, rb_intern("@name"), rb_str_new_cstr(entry->title));
  199 + rb_ivar_set(rb_entry, rb_intern("@password"), rb_str_new_cstr(entry->password));
  200 + _set_time(rb_entry, "@mtime", entry->mtime);
  201 + _set_time(rb_entry, "@ctime", entry->ctime);
  202 + _set_time(rb_entry, "@atime", entry->atime);
  203 + _set_time(rb_entry, "@etime", entry->etime);
  204 +
  205 + rb_ary_push(entries, rb_entry);
  206 + }
  207 +
  208 + return entries;
  209 +}
  210 +
176 211 #define gen_reader(prefix, attr_name)\
177 212 VALUE \
178 213 prefix##_##attr_name(VALUE self)\
@@ -188,6 +223,10 @@ gen_reader(rb_kp_grp, etime);
188 223
189 224 gen_reader(rb_kp_entry, name);
190 225 gen_reader(rb_kp_entry, password);
  226 +gen_reader(rb_kp_entry, mtime);
  227 +gen_reader(rb_kp_entry, ctime);
  228 +gen_reader(rb_kp_entry, atime);
  229 +gen_reader(rb_kp_entry, etime);
191 230
192 231 VALUE
193 232 rb_kp_grp_entries(VALUE self)
@@ -300,6 +339,7 @@ Init_keepass(void)
300 339 rb_define_singleton_method(cDatabase, "open", rb_kp_db_open, 2);
301 340 rb_define_method(cDatabase, "initialize", rb_kp_db_initialize, 2);
302 341 rb_define_method(cDatabase, "groups", rb_kp_db_groups, 0);
  342 + rb_define_method(cDatabase, "entries", rb_kp_db_entries, 0);
303 343
304 344 /* Group Methods */
305 345 rb_define_method(cGroup, "name", rb_kp_grp_name, 0);
@@ -312,4 +352,8 @@ Init_keepass(void)
312 352 /* Entry Methods */
313 353 rb_define_method(cEntry, "name", rb_kp_entry_name, 0);
314 354 rb_define_method(cEntry, "password", rb_kp_entry_password, 0);
  355 + rb_define_method(cEntry, "mtime", rb_kp_entry_mtime, 0);
  356 + rb_define_method(cEntry, "ctime", rb_kp_entry_ctime, 0);
  357 + rb_define_method(cEntry, "atime", rb_kp_entry_atime, 0);
  358 + rb_define_method(cEntry, "etime", rb_kp_entry_etime, 0);
315 359 }
19 test/entries.rb
... ... @@ -0,0 +1,19 @@
  1 +require 'minitest/autorun'
  2 +require 'keepass'
  3 +
  4 +KP_FILE = 'test/example.kdb'
  5 +CORRECT_PASSWORD = 'abc123'
  6 +TIME_METHODS = [ :ctime, :mtime, :atime, :etime ]
  7 +
  8 +class TestKeepass_Entries < MiniTest::Unit::TestCase
  9 + def test_time_methods
  10 + kdb = Keepass::Database.open KP_FILE, CORRECT_PASSWORD
  11 + entry = kdb.entries[0]
  12 +
  13 + times = TIME_METHODS.collect do |method|
  14 + (entry.send method).class
  15 + end
  16 +
  17 + assert_equal times, [ Time ] * TIME_METHODS.length
  18 + end
  19 +end

No commit comments for this range

Something went wrong with that request. Please try again.