parsel 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 80d50c158df4722786b31e9f644699453e4f8dfb
4
- data.tar.gz: 12e6dac5ec2e15b3a8970235fc806d1e996c9a5a
2
+ SHA256:
3
+ metadata.gz: ab6c3def75bb0d360e2e50ba25ad94625801dcb7fdbb9ad5040e8030d0a58ee5
4
+ data.tar.gz: aa17d8b8c3ea92c7357c23a6637cacaaa977c5295c9f36a79fbf1deb7742098d
5
5
  SHA512:
6
- metadata.gz: 6c6cf7a7cc8bb1e1373fe45d6a0473c16b31492d319363210b7206585feead5ec9db5cb163401e4ef6cc203a525e03e0b92be5e921beceaf2190f53166162237
7
- data.tar.gz: b0df1372c7a6682191f1ad4fea0c779720b86b571228fd07d97af3c626b7b3cc61139ef64c3a980baf4ab17f575af687b291f52b57f79241c2f834ac5a2ffdb8
6
+ metadata.gz: 50fa30534889c969e533319572a1dcdc3cacbe9e7acf9fba92965e65b4be09350963e135ff29e3a4ff16be4b581db38b88de05fbe71162f205bec796229a76eb
7
+ data.tar.gz: 47cd6019ff5155c646ac1e669d145815c7e997cd48bccf8d718516190f1a8ab611b1a5542ba680d6145830866f590903bd23dea00e538019120bb325a5a2b026
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 'ruby-head'
6
+ - '2.3.0'
7
+ - '2.2'
8
+ - '2.1'
9
+ notifications:
10
+ email: false
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # parsel
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/fnando/parsel-rb.png)](https://codeclimate.com/github/fnando/parsel-rb)
4
+ [![Build Status](https://travis-ci.org/fnando/parsel-rb.svg)](https://travis-ci.org/fnando/parsel-rb)
5
+ [![Gem](https://img.shields.io/gem/v/parsel.svg)](https://rubygems.org/gems/parsel)
6
+ [![Gem](https://img.shields.io/gem/dt/parsel.svg)](https://rubygems.org/gems/parsel)
7
+
3
8
  Encrypt and decrypt data with a given key.
4
9
 
5
10
  This library was created to allow an easy data
@@ -14,21 +19,21 @@ Check it out the Node.js counter-part: <http://github.com/fnando/parsel-js>.
14
19
  ## Usage
15
20
 
16
21
  ```ruby
17
- require 'parsel'
22
+ require "parsel"
18
23
 
19
- secret_key = 'mysupersecretkeythatnobodyknowsabout'
20
- encrypted = Parsel.encrypt(secret_key, 'hello from ruby!')
24
+ secret_key = "mysupersecretkeythatnobodyknowsabout"
25
+ encrypted = Parsel.encrypt(secret_key, "hello from ruby!")
21
26
  decrypted = Parsel.decrypt(secret_key, encrypted)
22
27
  ```
23
28
 
24
29
  You can also use Marshal for encrypting/decrypting objects. Notice that this isn't supported by Node.js.
25
30
 
26
31
  ```ruby
27
- require 'parsel'
32
+ require "parsel"
28
33
 
29
34
  data = {user_id: 1234}
30
35
 
31
- secret_key = 'mysupersecretkeythatnobodyknowsabout'
36
+ secret_key = "mysupersecretkeythatnobodyknowsabout"
32
37
  encrypted = Parsel::Marshal.encrypt(secret_key, data)
33
38
 
34
39
  decrypted = Parsel::Marshal.decrypt(secret_key, encrypted)
@@ -38,11 +43,11 @@ decrypted = Parsel::Marshal.decrypt(secret_key, encrypted)
38
43
  Alternatively you can use `JSON` as your serializer.
39
44
 
40
45
  ```ruby
41
- require 'parsel'
46
+ require "parsel"
42
47
 
43
48
  data = {user_id: 1234}
44
49
 
45
- secret_key = 'mysupersecretkeythatnobodyknowsabout'
50
+ secret_key = "mysupersecretkeythatnobodyknowsabout"
46
51
  encrypted = Parsel::JSON.encrypt(secret_key, data)
47
52
 
48
53
  decrypted = Parsel::JSON.decrypt(secret_key, encrypted)
@@ -51,6 +56,8 @@ decrypted = Parsel::JSON.decrypt(secret_key, encrypted)
51
56
 
52
57
  ### Custom Cipher IV
53
58
 
59
+ ![Make sure you use a 16-chars long if you're going to exchange data with parsel-js.](http://messages.hellobits.com/warning.svg?message=Make%20sure%20you%20use%20a%2016-chars%20long%20if%20you're%20going%20to%20exchange%20data%20with%20parsel-js.)
60
+
54
61
  By default, this library uses a built-in IV. You may want to change that.
55
62
 
56
63
  You can globally change the IV like the following:
@@ -66,6 +73,8 @@ Parsel.encrypt(secret_key, iv, data)
66
73
  Parsel.decrypt(secret_key, iv, data)
67
74
  ```
68
75
 
76
+ **NOTE:** If you're going to use <http://github.com/fnando/parsel-js> to exchange data, you have to use a 16-chars long IV. Node.js will fail with different lengths.
77
+
69
78
  ## Maintainer
70
79
 
71
80
  - Nando Vieira (<http://nandovieira.com.br>)
data/Rakefile CHANGED
@@ -1,5 +1,10 @@
1
- require "bundler"
2
- Bundler::GemHelper.install_tasks
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
3
 
4
- require "rspec/core/rake_task"
5
- RSpec::Core::RakeTask.new
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ t.warning = false
8
+ end
9
+
10
+ task default: :test
@@ -1,13 +1,22 @@
1
- require 'openssl'
2
- require 'base64'
3
- require 'json'
4
- require 'parsel/marshal'
5
- require 'parsel/json'
6
- require 'parsel/version'
1
+ require "securerandom"
2
+ require "openssl"
3
+ require "base64"
4
+ require "json"
5
+ require "parsel/marshal"
6
+ require "parsel/json"
7
+ require "parsel/version"
7
8
 
8
9
  module Parsel
9
- DEFAULT_IV = 'f89209ffcdd1a225'.freeze
10
- CIPHER = 'AES-256-CBC'.freeze
10
+ DEFAULT_IV = "f89209ffcdd1a225".freeze
11
+ CIPHER = "AES-256-CBC".freeze
12
+
13
+ def self.print_deprecation_message
14
+ warn <<~TEXT
15
+ `parsel` is no longer supported. Use at your own risk.
16
+ Called from #{caller[1]}
17
+
18
+ TEXT
19
+ end
11
20
 
12
21
  def self.default_iv=(iv)
13
22
  @default_iv = iv
@@ -20,10 +29,12 @@ module Parsel
20
29
  self.default_iv = DEFAULT_IV
21
30
 
22
31
  def self.encrypt(*args)
32
+ Parsel.print_deprecation_message
23
33
  encode cipher(:encrypt, *expand_args(args))
24
34
  end
25
35
 
26
36
  def self.decrypt(*args)
37
+ Parsel.print_deprecation_message
27
38
  key, iv, data = expand_args(args)
28
39
  cipher(:decrypt, key, iv, decode(data))
29
40
  rescue Exception
@@ -45,15 +56,17 @@ module Parsel
45
56
  def self.cipher(mode, key, iv, data)
46
57
  cipher = OpenSSL::Cipher.new(CIPHER).public_send(mode)
47
58
  cipher.key = Digest::SHA256.digest(key)
48
- cipher.iv = iv
59
+ cipher.iv = iv[0...cipher.iv_len]
49
60
  cipher.update(data) + cipher.final
50
61
  end
51
62
 
52
63
  def self.encode(data)
53
- Base64.encode64(data).gsub(/\n/, '')
64
+ Base64.encode64(data).gsub(/\n/, "")
54
65
  end
55
66
 
56
67
  def self.decode(data)
57
68
  Base64.decode64(data)
58
69
  end
59
70
  end
71
+
72
+ Parsel.print_deprecation_message
@@ -1,11 +1,13 @@
1
1
  module Parsel
2
2
  module JSON
3
3
  def self.encrypt(*args)
4
+ Parsel.print_deprecation_message
4
5
  key, iv, data = Parsel.expand_args(args)
5
6
  Parsel.encrypt(key, iv, ::JSON.dump(data))
6
7
  end
7
8
 
8
9
  def self.decrypt(*args)
10
+ Parsel.print_deprecation_message
9
11
  key, iv, data = Parsel.expand_args(args)
10
12
  ::JSON.load Parsel.decrypt(key, iv, data)
11
13
  rescue Exception
@@ -1,11 +1,13 @@
1
1
  module Parsel
2
2
  module Marshal
3
3
  def self.encrypt(*args)
4
+ Parsel.print_deprecation_message
4
5
  key, iv, data = Parsel.expand_args(args)
5
6
  Parsel.encrypt(key, iv, ::Marshal.dump(data))
6
7
  end
7
8
 
8
9
  def self.decrypt(*args)
10
+ Parsel.print_deprecation_message
9
11
  key, iv, data = Parsel.expand_args(args)
10
12
  ::Marshal.load Parsel.decrypt(key, iv, data)
11
13
  rescue Exception
@@ -1,7 +1,7 @@
1
1
  module Parsel
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 3
3
+ MAJOR = 1
4
+ MINOR = 0
5
5
  PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
@@ -1,21 +1,22 @@
1
- # -*- encoding: utf-8 -*-
2
- require './lib/parsel/version'
1
+ require "./lib/parsel/version"
3
2
 
4
3
  Gem::Specification.new do |s|
5
- s.name = 'parsel'
4
+ s.name = "parsel"
6
5
  s.version = Parsel::Version::STRING
7
6
  s.platform = Gem::Platform::RUBY
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.'
7
+ s.authors = ["Nando Vieira"]
8
+ s.email = ["fnando.vieira@gmail.com"]
9
+ s.homepage = "http://rubygems.org/gems/parsel"
10
+ s.summary = "Encrypt and decrypt data with a given key."
12
11
  s.description = s.summary
12
+ s.post_install_message = "`parsel` is no longer supported. Use at your own risk."
13
13
 
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.add_development_dependency 'rake'
20
- s.add_development_dependency 'rspec'
19
+ s.add_development_dependency "rake"
20
+ s.add_development_dependency "minitest-utils"
21
+ s.add_development_dependency "pry-meta"
21
22
  end
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class JsonTest < Minitest::Test
4
+ let(:key) { "my secret key" }
5
+
6
+ test "encrypts data" do
7
+ refute_equal JSON.dump(["hello"]), Parsel::JSON.encrypt(key, ["hello"])
8
+ end
9
+
10
+ test "decrypts data" do
11
+ encrypted = Parsel::JSON.encrypt(key, ["hello"])
12
+ assert_equal ["hello"], Parsel::JSON.decrypt(key, encrypted)
13
+ end
14
+
15
+ test "returns false when decryption fails" do
16
+ refute Parsel::JSON.decrypt("abc", "123")
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class MarshalTest < Minitest::Test
4
+ let(:key) { "my secret key" }
5
+
6
+ test "encrypts data" do
7
+ refute_equal Marshal.dump("hello"), Parsel::Marshal.encrypt(key, "hello")
8
+ end
9
+
10
+ test "decrypts data" do
11
+ encrypted = Parsel::Marshal.encrypt(key, "hello")
12
+ assert_equal "hello", Parsel::Marshal.decrypt(key, encrypted)
13
+ end
14
+
15
+ test "returns false when decryption fails" do
16
+ refute Parsel::Marshal.decrypt("abc", "123")
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ require "test_helper"
2
+
3
+ class ParselTest < Minitest::Test
4
+ let(:key) { "my secret key" }
5
+
6
+ test "encrypts data" do
7
+ refute_equal "hello", Parsel.encrypt(key, "hello")
8
+ end
9
+
10
+ test "decrypts data" do
11
+ encrypted = Parsel.encrypt(key, "hello")
12
+ assert_equal "hello", Parsel.decrypt(key, encrypted)
13
+ end
14
+
15
+ test "returns false when decryption fails" do
16
+ refute Parsel.decrypt("abc", "123")
17
+ end
18
+
19
+ test "uses custom iv" do
20
+ iv = SecureRandom.hex(100)
21
+ encrypted = Parsel.encrypt(key, iv, "hello")
22
+
23
+ assert_equal "hello", Parsel.decrypt(key, iv, encrypted)
24
+ end
25
+
26
+ test "return false when decryption for custom iv fails" do
27
+ iv = SecureRandom.hex(100)
28
+ encrypted = Parsel.encrypt(key, iv, "hello")
29
+
30
+ refute Parsel.decrypt(key, encrypted)
31
+ end
32
+
33
+ test "changes global iv" do
34
+ iv = SecureRandom.hex(100)
35
+ Parsel.default_iv = iv
36
+ encrypted = Parsel.encrypt(key, "hello")
37
+
38
+ assert_equal "hello", Parsel.decrypt(key, iv, encrypted)
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ require "bundler/setup"
2
+ require "parsel"
3
+ require "minitest/utils"
4
+ require "minitest/autorun"
5
+
6
+ module Minitest
7
+ class Test
8
+ setup do
9
+ Parsel.default_iv = Parsel::DEFAULT_IV
10
+ end
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: minitest-utils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-meta
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -46,7 +60,7 @@ extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
48
62
  - ".gitignore"
49
- - ".rspec"
63
+ - ".travis.yml"
50
64
  - Gemfile
51
65
  - README.md
52
66
  - Rakefile
@@ -55,14 +69,14 @@ files:
55
69
  - lib/parsel/marshal.rb
56
70
  - lib/parsel/version.rb
57
71
  - parsel.gemspec
58
- - spec/parsel/json_spec.rb
59
- - spec/parsel/marshal_spec.rb
60
- - spec/parsel_spec.rb
61
- - spec/spec_helper.rb
72
+ - test/parsel/json_test.rb
73
+ - test/parsel/marshal_test.rb
74
+ - test/parsel/parsel_test.rb
75
+ - test/test_helper.rb
62
76
  homepage: http://rubygems.org/gems/parsel
63
77
  licenses: []
64
78
  metadata: {}
65
- post_install_message:
79
+ post_install_message: "`parsel` is no longer supported. Use at your own risk."
66
80
  rdoc_options: []
67
81
  require_paths:
68
82
  - lib
@@ -77,13 +91,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
91
  - !ruby/object:Gem::Version
78
92
  version: '0'
79
93
  requirements: []
80
- rubyforge_project:
81
- rubygems_version: 2.4.5.1
94
+ rubygems_version: 3.1.2
82
95
  signing_key:
83
96
  specification_version: 4
84
97
  summary: Encrypt and decrypt data with a given key.
85
98
  test_files:
86
- - spec/parsel/json_spec.rb
87
- - spec/parsel/marshal_spec.rb
88
- - spec/parsel_spec.rb
89
- - spec/spec_helper.rb
99
+ - test/parsel/json_test.rb
100
+ - test/parsel/marshal_test.rb
101
+ - test/parsel/parsel_test.rb
102
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,18 +0,0 @@
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
@@ -1,18 +0,0 @@
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,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Parsel do
4
- let(:key) { 'my secret key' }
5
-
6
- it 'encrypts data' do
7
- expect(Parsel.encrypt(key, 'hello')).not_to eq('hello')
8
- end
9
-
10
- it 'decrypts data' do
11
- encrypted = Parsel.encrypt(key, 'hello')
12
- expect(Parsel.decrypt(key, encrypted)).to eq('hello')
13
- end
14
-
15
- it 'returns false when decryption fails' do
16
- expect(Parsel.decrypt('abc', '123')).to be_falsy
17
- end
18
-
19
- it 'uses custom iv' do
20
- iv = SecureRandom.hex(100)
21
- encrypted = Parsel.encrypt(key, iv, 'hello')
22
-
23
- expect(Parsel.decrypt(key, iv, encrypted)).to eq('hello')
24
- end
25
-
26
- it 'return false when decryption for custom iv fails' do
27
- iv = SecureRandom.hex(100)
28
- encrypted = Parsel.encrypt(key, iv, 'hello')
29
-
30
- expect(Parsel.decrypt(key, encrypted)).to be_falsy
31
- end
32
-
33
- it 'changes global iv' do
34
- iv = SecureRandom.hex(100)
35
- Parsel.default_iv = iv
36
- encrypted = Parsel.encrypt(key, 'hello')
37
-
38
- expect(Parsel.decrypt(key, iv, encrypted)).to eq('hello')
39
- end
40
- end
@@ -1,8 +0,0 @@
1
- require 'bundler/setup'
2
- require 'parsel'
3
-
4
- RSpec.configure do |config|
5
- config.before do
6
- Parsel.default_iv = Parsel::DEFAULT_IV
7
- end
8
- end