parsel 0.1.1 → 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: df92c45b60b8051c992490f2289b2511a5643226
4
+ data.tar.gz: a6dcb4e514c4ab76ac754416b43c01f3ea254582
5
+ SHA512:
6
+ metadata.gz: 2df8d1021815040d88521e5549d2e1cc87f3429f31e751784816d23ada0dcb96f231b734b48cfe92fee4ad2ef534bc4b5924a0bfaaca8b395283a1a0a2e32488
7
+ data.tar.gz: 196722bab46f11745db385cf8c6977a7a9bbbbb65e099c6cbddf46e8fb01d8eba36dab6d5edb556fe906c47d0e89cdd04e3a42f409f902f491bfa3aee951c253
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color --format documentation
1
+ --color
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -1,21 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parsel (0.1.1)
4
+ parsel (0.2.0)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.3)
10
- rake (0.9.2.2)
11
- rspec (2.10.0)
12
- rspec-core (~> 2.10.0)
13
- rspec-expectations (~> 2.10.0)
14
- rspec-mocks (~> 2.10.0)
15
- rspec-core (2.10.0)
16
- rspec-expectations (2.10.0)
17
- diff-lcs (~> 1.1.3)
18
- rspec-mocks (2.10.1)
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.2)
11
+ rspec (3.0.0)
12
+ rspec-core (~> 3.0.0)
13
+ rspec-expectations (~> 3.0.0)
14
+ rspec-mocks (~> 3.0.0)
15
+ rspec-core (3.0.2)
16
+ rspec-support (~> 3.0.0)
17
+ rspec-expectations (3.0.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.0.0)
20
+ rspec-mocks (3.0.2)
21
+ rspec-support (~> 3.0.0)
22
+ rspec-support (3.0.2)
19
23
 
20
24
  PLATFORMS
21
25
  ruby
data/README.md CHANGED
@@ -13,11 +13,41 @@ Check it out the Node.js counter-part: <http://github.com/fnando/parsel-js>.
13
13
 
14
14
  ## Usage
15
15
 
16
- require "parsel"
16
+ ```ruby
17
+ require 'parsel'
17
18
 
18
- secret_key = "mysupersecretkeythatnobodyknowsabout"
19
- encrypted = Parsel.encrypt(secret_key, "hello from ruby!")
20
- decrypted = Parsel.decrypt(secret_key, encrypted)
19
+ secret_key = 'mysupersecretkeythatnobodyknowsabout'
20
+ encrypted = Parsel.encrypt(secret_key, 'hello from ruby!')
21
+ decrypted = Parsel.decrypt(secret_key, encrypted)
22
+ ```
23
+
24
+ You can also use Marshal for encrypting/decrypting objects. Notice that this isn't supported by Node.js.
25
+
26
+ ```ruby
27
+ require 'parsel'
28
+
29
+ data = {user_id: 1234}
30
+
31
+ secret_key = 'mysupersecretkeythatnobodyknowsabout'
32
+ encrypted = Parsel::Marshal.encrypt(secret_key, data)
33
+
34
+ decrypted = Parsel::Marshal.decrypt(secret_key, encrypted)
35
+ #=> {user_id: 1234}
36
+ ```
37
+
38
+ Alternatively you can use `JSON` as your serializer.
39
+
40
+ ```ruby
41
+ require 'parsel'
42
+
43
+ data = {user_id: 1234}
44
+
45
+ secret_key = 'mysupersecretkeythatnobodyknowsabout'
46
+ encrypted = Parsel::JSON.encrypt(secret_key, data)
47
+
48
+ decrypted = Parsel::JSON.decrypt(secret_key, encrypted)
49
+ #=> {"user_id" => 1234}
50
+ ```
21
51
 
22
52
  ## Maintainer
23
53
 
@@ -1,9 +1,11 @@
1
- require "openssl"
2
- require "base64"
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'json'
4
+ require 'parsel/marshal'
5
+ require 'parsel/json'
6
+ require 'parsel/version'
3
7
 
4
8
  module Parsel
5
- autoload :Version, "parsel/version"
6
-
7
9
  def self.encrypt(key, data)
8
10
  encode cipher(:encrypt, key, data)
9
11
  end
@@ -16,14 +18,14 @@ module Parsel
16
18
 
17
19
  private
18
20
  def self.cipher(mode, key, data)
19
- cipher = OpenSSL::Cipher.new("AES-256-CBC").public_send(mode)
21
+ cipher = OpenSSL::Cipher.new('AES-256-CBC').public_send(mode)
20
22
  cipher.key = Digest::SHA256.digest(key)
21
- cipher.iv = "f89209ffcdd1a225"
23
+ cipher.iv = 'f89209ffcdd1a225'
22
24
  cipher.update(data) + cipher.final
23
25
  end
24
26
 
25
27
  def self.encode(data)
26
- Base64.encode64(data).gsub(/\n/, "")
28
+ Base64.encode64(data).gsub(/\n/, '')
27
29
  end
28
30
 
29
31
  def self.decode(data)
@@ -0,0 +1,13 @@
1
+ module Parsel
2
+ module JSON
3
+ def self.encrypt(key, data)
4
+ Parsel.encrypt(key, ::JSON.dump(data))
5
+ end
6
+
7
+ def self.decrypt(key, data)
8
+ ::JSON.load Parsel.decrypt(key, data)
9
+ rescue Exception
10
+ false
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Parsel
2
+ module Marshal
3
+ def self.encrypt(key, data)
4
+ Parsel.encrypt(key, ::Marshal.dump(data))
5
+ end
6
+
7
+ def self.decrypt(key, data)
8
+ ::Marshal.load Parsel.decrypt(key, data)
9
+ rescue Exception
10
+ false
11
+ end
12
+ end
13
+ end
@@ -1,8 +1,8 @@
1
1
  module Parsel
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 1
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -1,22 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "parsel/version"
2
+ require './lib/parsel/version'
4
3
 
5
4
  Gem::Specification.new do |s|
6
- s.name = "parsel"
5
+ s.name = 'parsel'
7
6
  s.version = Parsel::Version::STRING
8
7
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Nando Vieira"]
10
- s.email = ["fnando.vieira@gmail.com"]
11
- s.homepage = "http://rubygems.org/gems/parsel"
12
- s.summary = "Encrypt and decrypt data with a given key."
8
+ s.authors = ['Nando Vieira']
9
+ s.email = ['fnando.vieira@gmail.com']
10
+ s.homepage = 'http://rubygems.org/gems/parsel'
11
+ s.summary = 'Encrypt and decrypt data with a given key.'
13
12
  s.description = s.summary
14
13
 
15
14
  s.files = `git ls-files`.split("\n")
16
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
- s.require_paths = ["lib"]
17
+ s.require_paths = ['lib']
19
18
 
20
- s.add_development_dependency "rake"
21
- s.add_development_dependency "rspec"
19
+ s.add_development_dependency 'rake'
20
+ s.add_development_dependency 'rspec'
22
21
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Parsel::JSON do
4
+ let(:key) { 'my secret key' }
5
+
6
+ it 'encrypts data' do
7
+ expect(Parsel::JSON.encrypt(key, ['hello'])).not_to eq(JSON.dump(['hello']))
8
+ end
9
+
10
+ it 'decrypts data' do
11
+ encrypted = Parsel::JSON.encrypt(key, ['hello'])
12
+ expect(Parsel::JSON.decrypt(key, encrypted)).to eq(['hello'])
13
+ end
14
+
15
+ it 'returns false when decryption fails' do
16
+ expect(Parsel::JSON.decrypt('abc', '123')).to be_falsy
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Parsel::Marshal do
4
+ let(:key) { 'my secret key' }
5
+
6
+ it 'encrypts data' do
7
+ expect(Parsel::Marshal.encrypt(key, 'hello')).not_to eq(Marshal.dump('hello'))
8
+ end
9
+
10
+ it 'decrypts data' do
11
+ encrypted = Parsel::Marshal.encrypt(key, 'hello')
12
+ expect(Parsel::Marshal.decrypt(key, encrypted)).to eq('hello')
13
+ end
14
+
15
+ it 'returns false when decryption fails' do
16
+ expect(Parsel::Marshal.decrypt('abc', '123')).to be_falsy
17
+ end
18
+ end
@@ -1,18 +1,18 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Parsel do
4
- let(:key) { "my secret key" }
4
+ let(:key) { 'my secret key' }
5
5
 
6
- it "encrypts data" do
7
- Parsel.encrypt(key, "hello").should_not eql("hello")
6
+ it 'encrypts data' do
7
+ expect(Parsel.encrypt(key, 'hello')).not_to eq('hello')
8
8
  end
9
9
 
10
- it "decrypts data" do
11
- encrypted = Parsel.encrypt(key, "hello")
12
- Parsel.decrypt(key, encrypted).should eql("hello")
10
+ it 'decrypts data' do
11
+ encrypted = Parsel.encrypt(key, 'hello')
12
+ expect(Parsel.decrypt(key, encrypted)).to eq('hello')
13
13
  end
14
14
 
15
- it "returns false when decryption fails" do
16
- Parsel.decrypt("abc", "123").should be_false
15
+ it 'returns false when decryption fails' do
16
+ expect(Parsel.decrypt('abc', '123')).to be_falsy
17
17
  end
18
18
  end
@@ -1,6 +1,3 @@
1
- require "bundler"
2
- Bundler.setup(:default, :development)
3
- Bundler.require
4
-
5
- require "parsel"
1
+ require 'bundler/setup'
2
+ require 'parsel'
6
3
 
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nando Vieira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-15 00:00:00.000000000 Z
11
+ date: 2014-06-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Encrypt and decrypt data with a given key.
@@ -50,47 +45,47 @@ executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
53
- - .gitignore
54
- - .rspec
48
+ - ".gitignore"
49
+ - ".rspec"
55
50
  - Gemfile
56
51
  - Gemfile.lock
57
52
  - README.md
58
53
  - Rakefile
59
54
  - lib/parsel.rb
55
+ - lib/parsel/json.rb
56
+ - lib/parsel/marshal.rb
60
57
  - lib/parsel/version.rb
61
58
  - parsel.gemspec
59
+ - spec/parsel/json_spec.rb
60
+ - spec/parsel/marshal_spec.rb
62
61
  - spec/parsel_spec.rb
63
62
  - spec/spec_helper.rb
64
63
  homepage: http://rubygems.org/gems/parsel
65
64
  licenses: []
65
+ metadata: {}
66
66
  post_install_message:
67
67
  rdoc_options: []
68
68
  require_paths:
69
69
  - lib
70
70
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
71
  requirements:
73
- - - ! '>='
72
+ - - ">="
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
- segments:
77
- - 0
78
- hash: 2250561470774246864
79
75
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
76
  requirements:
82
- - - ! '>='
77
+ - - ">="
83
78
  - !ruby/object:Gem::Version
84
79
  version: '0'
85
- segments:
86
- - 0
87
- hash: 2250561470774246864
88
80
  requirements: []
89
81
  rubyforge_project:
90
- rubygems_version: 1.8.23
82
+ rubygems_version: 2.2.2
91
83
  signing_key:
92
- specification_version: 3
84
+ specification_version: 4
93
85
  summary: Encrypt and decrypt data with a given key.
94
86
  test_files:
87
+ - spec/parsel/json_spec.rb
88
+ - spec/parsel/marshal_spec.rb
95
89
  - spec/parsel_spec.rb
96
90
  - spec/spec_helper.rb
91
+ has_rdoc: