ejson 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ejson.rb +21 -0
- data/lib/ejson/cli.rb +4 -4
- data/lib/ejson/version.rb +1 -1
- data/test/ejson_test.rb +13 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d196aa010f463d032df01e73e296fee007ab032d
|
4
|
+
data.tar.gz: 22256d7a3eb5779e059f94f6d709a78dff3f2aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0145e7b10b201d63dad67d8ead58debf9c294364070721ab9c0fb481bd5aa4bc96ab0e279945315bb54481cd6806bfec440c8a105768aa3065b286cac66d72e6
|
7
|
+
data.tar.gz: ffc080d94d6fb9bcd353c0195ff83de2c92d75a544ff774aac1fddaa0859e6d989e362d1192cbfdc16db2764ddc1d54f06a758931f2f19a95805381c41f9572f
|
data/lib/ejson.rb
CHANGED
@@ -14,6 +14,27 @@ class EJSON
|
|
14
14
|
Data.new(JSON.load(json_text), @encryption)
|
15
15
|
end
|
16
16
|
|
17
|
+
def serializer
|
18
|
+
@serializer ||= Serializer.new(@encryption)
|
19
|
+
end
|
20
|
+
|
21
|
+
class Serializer
|
22
|
+
|
23
|
+
def initialize(encryption)
|
24
|
+
@encryption = encryption
|
25
|
+
end
|
26
|
+
|
27
|
+
def dump(data)
|
28
|
+
data = Data.new(data, @encryption) unless data.is_a?(Data)
|
29
|
+
data.dump
|
30
|
+
end
|
31
|
+
|
32
|
+
def load(data)
|
33
|
+
Data.new(JSON.parse(data), @encryption).decrypt_all
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
17
38
|
class Data
|
18
39
|
extend Forwardable
|
19
40
|
def_delegators :@data, :[]=
|
data/lib/ejson/cli.rb
CHANGED
@@ -12,14 +12,14 @@ class EJSON
|
|
12
12
|
default_task :encrypt
|
13
13
|
|
14
14
|
desc "decrypt [file]", "decrypt some data from file to stdout"
|
15
|
-
method_option :
|
15
|
+
method_option :out, type: :string, default: false, aliases: "-o", desc: "Write to a file rather than stdout"
|
16
16
|
def decrypt(file)
|
17
17
|
ciphertext = File.read(file)
|
18
18
|
ej = EJSON.new(pubkey, options[:privkey])
|
19
19
|
output = JSON.pretty_generate(ej.load(ciphertext).decrypt_all)
|
20
|
-
if options[:
|
21
|
-
File.open(
|
22
|
-
puts "Wrote #{output.size} bytes to #{
|
20
|
+
if options[:out]
|
21
|
+
File.open(options[:out], "w") { |f| f.puts output }
|
22
|
+
puts "Wrote #{output.size} bytes to #{options[:out]}"
|
23
23
|
else
|
24
24
|
puts output
|
25
25
|
end
|
data/lib/ejson/version.rb
CHANGED
data/test/ejson_test.rb
CHANGED
@@ -43,7 +43,7 @@ class CLITest < Minitest::Unit::TestCase
|
|
43
43
|
encrypted = JSON.load(File.read(f.path))
|
44
44
|
assert_match(/\AENC\[MIIB.*\]\z/, encrypted["a"])
|
45
45
|
|
46
|
-
runcli "decrypt", "-
|
46
|
+
runcli "decrypt", "-o", f.path, "-p", pubkey, "-k", privkey, f.path
|
47
47
|
decrypted = JSON.load(File.read(f.path))
|
48
48
|
refute_match(/\AENC\[MIIB.*\]\z/, decrypted["a"])
|
49
49
|
ensure
|
@@ -87,6 +87,18 @@ class CLITest < Minitest::Unit::TestCase
|
|
87
87
|
assert_equal private_key, @enc.instance_variable_get(:@private_key_rsa).to_s
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_serializer_api
|
91
|
+
serializer = EJSON.new(pubkey, privkey).serializer
|
92
|
+
data = {'foo' => 'bar'}
|
93
|
+
|
94
|
+
assert_equal data, serializer.load(serializer.dump(data))
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_serializer_safety
|
98
|
+
serializer = EJSON.new(pubkey, privkey).serializer
|
99
|
+
refute serializer.dump('foo' => 'bar').include?('bar')
|
100
|
+
end
|
101
|
+
|
90
102
|
private
|
91
103
|
|
92
104
|
def encrypt(path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ejson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burke Libbey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|