keystorage 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/keystorage.gemspec +1 -1
- data/lib/keystorage.rb +1 -1
- data/lib/keystorage/manager.rb +29 -5
- data/test/test_keystorage.rb +31 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
data/keystorage.gemspec
CHANGED
data/lib/keystorage.rb
CHANGED
data/lib/keystorage/manager.rb
CHANGED
@@ -12,8 +12,13 @@ module Keystorage
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def get(group,name,file=nil)
|
15
|
-
|
15
|
+
Manager.new(file).get(group,name)
|
16
16
|
end
|
17
|
+
|
18
|
+
def delete(group,name=nil,file=nil)
|
19
|
+
Manager.new(file).delete(group,name)
|
20
|
+
end
|
21
|
+
|
17
22
|
end
|
18
23
|
|
19
24
|
class Manager
|
@@ -39,10 +44,16 @@ module Keystorage
|
|
39
44
|
raise "missing group" unless group
|
40
45
|
raise "missing name" unless name
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
begin
|
48
|
+
File.open(@file,'r') do |f|
|
49
|
+
data=YAML.load(f)
|
50
|
+
raise "missing keystorage" unless data
|
51
|
+
raise "missing group "+group unless data.has_key?(group)
|
52
|
+
raise "missing group "+group+" name "+name unless data[group].has_key?(name)
|
53
|
+
|
54
|
+
return decode(data[group][name])
|
55
|
+
end
|
56
|
+
rescue =>e
|
46
57
|
end
|
47
58
|
false
|
48
59
|
end
|
@@ -57,12 +68,25 @@ module Keystorage
|
|
57
68
|
data = Hash.new unless data
|
58
69
|
data[group] = Hash.new unless data.has_key?(group)
|
59
70
|
data[group][key] = encode(value)
|
71
|
+
write(data)
|
72
|
+
end
|
60
73
|
|
74
|
+
def write(data)
|
61
75
|
File.open(@file,'w',0600) do |f|
|
62
76
|
YAML.dump(data,f)
|
63
77
|
end
|
64
78
|
end
|
65
79
|
|
80
|
+
def delete(group,name = nil)
|
81
|
+
data = all
|
82
|
+
if name
|
83
|
+
data[group].delete(name)
|
84
|
+
else
|
85
|
+
data.delete(group)
|
86
|
+
end
|
87
|
+
write(data)
|
88
|
+
end
|
89
|
+
|
66
90
|
def encode(str,salt="3Qw9EtWE")
|
67
91
|
enc = OpenSSL::Cipher::Cipher.new('aes256')
|
68
92
|
enc.encrypt.pkcs5_keyivgen(salt)
|
data/test/test_keystorage.rb
CHANGED
@@ -1,7 +1,36 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
class TestKeystorage < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
5
|
+
@@file = ".testkey"
|
6
|
+
context "set / delete" do
|
7
|
+
setup do
|
8
|
+
Keystorage.set("abc","def","ghi",@@file)
|
9
|
+
Keystorage.set("abc","123","456",@@file)
|
10
|
+
end
|
11
|
+
teardown do
|
12
|
+
FileUtils.rm(@@file)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "file exists" do
|
16
|
+
assert File.exists?(@@file)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "exist def and 123" do
|
20
|
+
assert_equal "ghi",Keystorage.get("abc","def",@@file)
|
21
|
+
assert_equal "456",Keystorage.get("abc","123",@@file)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "delete only def" do
|
25
|
+
Keystorage.delete("abc","def",@@file)
|
26
|
+
assert_equal "456",Keystorage.get("abc","123",@@file)
|
27
|
+
assert_equal false,Keystorage.get("abc","def",@@file)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "delete abc group" do
|
31
|
+
Keystorage.delete("abc",nil,@@file)
|
32
|
+
assert_equal false,Keystorage.get("abc","123",@@file)
|
33
|
+
assert_equal false,Keystorage.get("abc","def",@@file)
|
34
|
+
end
|
6
35
|
end
|
7
36
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keystorage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yoshihiro TAKAHARA
|