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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e7a3d4927ceae8e72ece8df8749391e2620d683
4
- data.tar.gz: d3f5c4b1c24e2d73cde70f136f3a64c6ed0abb18
3
+ metadata.gz: d196aa010f463d032df01e73e296fee007ab032d
4
+ data.tar.gz: 22256d7a3eb5779e059f94f6d709a78dff3f2aba
5
5
  SHA512:
6
- metadata.gz: 8925b554189010a94fe8760c184c92ab3ab72771ef3cd217192f9a04067f4a650e086d3d3e9ed77c83e21f20ceb34fc63ef52d05965982e747706e3c72c7f490
7
- data.tar.gz: 7b14d361b4e9b0398208205de262d9c360aeb82a6828e8e324ec0322258b18a2a3cb1a05544425c70d13f758c5ac421f2e3f6561e5903b95615efbc19339b391
6
+ metadata.gz: 0145e7b10b201d63dad67d8ead58debf9c294364070721ab9c0fb481bd5aa4bc96ab0e279945315bb54481cd6806bfec440c8a105768aa3065b286cac66d72e6
7
+ data.tar.gz: ffc080d94d6fb9bcd353c0195ff83de2c92d75a544ff774aac1fddaa0859e6d989e362d1192cbfdc16db2764ddc1d54f06a758931f2f19a95805381c41f9572f
@@ -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, :[]=
@@ -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 :inplace, type: :boolean, default: false, aliases: "-i", desc: "Overwrite input file rather than dumping to stdout"
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[:inplace]
21
- File.open(file, "w") { |f| f.puts output }
22
- puts "Wrote #{output.size} bytes to #{file}"
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
@@ -1,3 +1,3 @@
1
1
  class EJSON
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -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", "-i", "-p", pubkey, "-k", privkey, f.path
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.3.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-14 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor