encrypto 0.0.1 → 0.0.2

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.
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- encrypto (0.0.1)
4
+ encrypto (0.0.2)
5
5
  attr_encrypted (~> 1.3.0)
6
- rbnacl (~> 1.1.0)
6
+ rbnacl (~> 2.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -23,7 +23,7 @@ GEM
23
23
  slop (~> 3.4)
24
24
  pry-nav (0.2.3)
25
25
  pry (~> 0.9.10)
26
- rbnacl (1.1.0)
26
+ rbnacl (2.0.0)
27
27
  ffi
28
28
  rspec (2.14.1)
29
29
  rspec-core (~> 2.14.0)
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.homepage = 'http://github.com/finalist/encrypto'
16
16
 
17
- gem.add_dependency "rbnacl", "~> 1.1.0"
17
+ gem.add_dependency "rbnacl", "~> 2.0.0"
18
18
  gem.add_dependency "attr_encrypted", "~> 1.3.0"
19
19
 
20
20
  gem.add_development_dependency "pry-nav", "~> 0.2.3"
@@ -6,24 +6,24 @@ module Encrypto
6
6
  end
7
7
 
8
8
  def box(value)
9
- @nacl_box.box(value, :hex)
9
+ @nacl_box.box(value)
10
10
  end
11
11
 
12
12
  def open(cipher_text)
13
- @nacl_box.open(cipher_text, :hex)
13
+ @nacl_box.open(cipher_text.clone)
14
14
  end
15
15
 
16
16
  def self.from_passphrase(passphrase)
17
- passphrase_sha = Crypto::Hash.sha256(passphrase)
17
+ passphrase_sha = RbNaCl::Hash.sha256(passphrase)
18
18
  from_secret_key(passphrase_sha)
19
19
  end
20
20
 
21
21
  def self.from_secret_key(secret_key)
22
- new(Crypto::RandomNonceBox.from_secret_key(secret_key))
22
+ new(RbNaCl::RandomNonceBox.from_secret_key(secret_key))
23
23
  end
24
24
 
25
25
  def self.from_keypair(public_key, private_key)
26
- new(Crypto::RandomNonceBox.from_keypair(public_key, private_key))
26
+ new(RbNaCl::RandomNonceBox.from_keypair(public_key, private_key))
27
27
  end
28
28
 
29
29
  end
@@ -17,14 +17,11 @@ module Encrypto
17
17
  end
18
18
 
19
19
  def self.encrypt_with_keypair(value, public_key, signing_private_key)
20
- hex_public_key = Keys.hex_public_key(public_key)
21
- keypair_box(hex_public_key, signing_private_key).box(value)
20
+ keypair_box(public_key, signing_private_key).box(value)
22
21
  end
23
22
 
24
- def self.decrypt_with_keypair(cipher_text, hex_public_key, private_key)
25
- public_key = Keys.hex_public_key(hex_public_key)
26
- box = Box.from_keypair(public_key, private_key)
27
- box.open(cipher_text)
23
+ def self.decrypt_with_keypair(cipher_text, signing_public_key, private_key)
24
+ keypair_box(signing_public_key, private_key).open(cipher_text)
28
25
  end
29
26
 
30
27
  private
@@ -2,12 +2,16 @@ module Encrypto
2
2
  module Keys
3
3
 
4
4
  def self.generate_keypair
5
- private_key = Crypto::PrivateKey.generate
6
- [private_key.public_key.to_s(:hex), private_key]
5
+ private_key = RbNaCl::PrivateKey.generate
6
+ [private_key.public_key, private_key]
7
7
  end
8
8
 
9
- def self.hex_public_key(value)
10
- Crypto::PublicKey.new(value, :hex)
9
+ def self.to_bytes(key)
10
+ key.to_s
11
+ end
12
+
13
+ def self.public_key_from_bytes(bytes)
14
+ RbNaCl::PublicKey.new(bytes)
11
15
  end
12
16
 
13
17
  end
@@ -2,7 +2,7 @@ module Encrypto
2
2
  module Random
3
3
 
4
4
  def self.bytes
5
- Crypto::Random.random_bytes
5
+ RbNaCl::Random.random_bytes
6
6
  end
7
7
 
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Encrypto
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -7,21 +7,21 @@ module Encrypto
7
7
  let(:passphrase) { 'password' }
8
8
 
9
9
  it 'hashes the secret key' do
10
- Crypto::Hash.should_receive(:sha256).with(passphrase)
11
- Crypto::RandomNonceBox.stub(:from_secret_key)
10
+ RbNaCl::Hash.should_receive(:sha256).with(passphrase)
11
+ RbNaCl::RandomNonceBox.stub(:from_secret_key)
12
12
  Encrypto::Box.from_passphrase(passphrase)
13
13
  end
14
14
 
15
15
  it 'creates a random nonce box based on the hashed secret key' do
16
- Crypto::Hash.stub(:sha256 => "sha")
17
- Crypto::RandomNonceBox.should_receive(:from_secret_key).with("sha")
16
+ RbNaCl::Hash.stub(:sha256 => "sha")
17
+ RbNaCl::RandomNonceBox.should_receive(:from_secret_key).with("sha")
18
18
  Encrypto::Box.from_passphrase(passphrase)
19
19
  end
20
20
 
21
21
  it 'initializes with a random nonce box' do
22
22
  box = double("box")
23
- Crypto::Hash.stub(:sha256 => "sha")
24
- Crypto::RandomNonceBox.stub(:from_secret_key => box)
23
+ RbNaCl::Hash.stub(:sha256 => "sha")
24
+ RbNaCl::RandomNonceBox.stub(:from_secret_key => box)
25
25
  Encrypto::Box.should_receive(:new).with(box)
26
26
  Encrypto::Box.from_passphrase(passphrase)
27
27
  end
@@ -32,13 +32,13 @@ module Encrypto
32
32
  let(:private_key) { double("private key") }
33
33
 
34
34
  it "creates a random nonce box based on the keypair" do
35
- Crypto::RandomNonceBox.should_receive(:from_keypair).with(public_key, private_key)
35
+ RbNaCl::RandomNonceBox.should_receive(:from_keypair).with(public_key, private_key)
36
36
  Encrypto::Box.from_keypair(public_key, private_key)
37
37
  end
38
38
 
39
39
  it "initializes with a random nonce box" do
40
40
  box = double("box")
41
- Crypto::RandomNonceBox.stub(:from_keypair => box)
41
+ RbNaCl::RandomNonceBox.stub(:from_keypair => box)
42
42
  Encrypto::Box.should_receive(:new).with(box)
43
43
  Encrypto::Box.from_keypair(public_key, private_key)
44
44
  end
@@ -49,7 +49,7 @@ module Encrypto
49
49
  value = double("value")
50
50
 
51
51
  some_box = double("box")
52
- some_box.should_receive(:box).with(value, :hex)
52
+ some_box.should_receive(:box).with(value)
53
53
 
54
54
  box = Encrypto::Box.new(some_box)
55
55
  box.box(value)
@@ -59,9 +59,10 @@ module Encrypto
59
59
  describe "#open" do
60
60
  it "opens the cipher text" do
61
61
  cipher_text = double("cipher text")
62
+ cipher_text.stub(:clone => cipher_text)
62
63
 
63
64
  some_box = double("box")
64
- some_box.should_receive(:open).with(cipher_text, :hex)
65
+ some_box.should_receive(:open).with(cipher_text)
65
66
 
66
67
  box = Encrypto::Box.new(some_box)
67
68
  box.open(cipher_text)
@@ -54,17 +54,12 @@ module Encrypto
54
54
  describe '.encrypt_with_keypair' do
55
55
  it 'boxes the value in a keypair box' do
56
56
  value = double("value")
57
- public_key = double("public")
58
- hex_public_key = double("hex_public_key")
57
+ public_key = double("public_key")
59
58
  signing_private_key = double("signing_private_key")
60
59
  box = double("box")
61
60
 
62
- Encrypto::Keys.should_receive(:hex_public_key).
63
- with(public_key).
64
- and_return(hex_public_key)
65
-
66
61
  Encrypto::Box.should_receive(:from_keypair).
67
- with(hex_public_key, signing_private_key).
62
+ with(public_key, signing_private_key).
68
63
  and_return(box)
69
64
 
70
65
  box.should_receive(:box).
@@ -76,33 +71,23 @@ module Encrypto
76
71
 
77
72
  describe ".decrypt_with_keypair" do
78
73
  let(:cipher_text) { double("cipher text") }
79
- let(:hex_public_key) { double("hex public key") }
80
74
  let(:public_key) { double("public key") }
81
75
  let(:private_key) { double("private key") }
82
76
 
83
- it "creates a public key" do
84
- Encrypto::Keys.should_receive(:hex_public_key).with(hex_public_key)
85
- Encrypto::Box.stub(from_keypair: double(open: nil))
86
-
87
- subject.decrypt_with_keypair(cipher_text, hex_public_key, private_key)
88
- end
89
-
90
77
  it "decrypts the cipher text with the keypair" do
91
78
  box = double
92
79
 
93
- Encrypto::Keys.stub(hex_public_key: public_key)
94
80
  Encrypto::Box.should_receive(:from_keypair).with(public_key, private_key).and_return(box)
95
81
  box.should_receive(:open).with(cipher_text)
96
82
 
97
- subject.decrypt_with_keypair(cipher_text, hex_public_key, private_key)
83
+ subject.decrypt_with_keypair(cipher_text, public_key, private_key)
98
84
  end
99
85
 
100
86
  it "returns the decrypted cipher text" do
101
87
  box = double(open: "decrypted value")
102
- Encrypto::Keys.stub(hex_public_key: public_key)
103
88
  Encrypto::Box.stub(from_keypair: box)
104
89
 
105
- subject.decrypt_with_keypair(cipher_text, hex_public_key, private_key).should eql "decrypted value"
90
+ subject.decrypt_with_keypair(cipher_text, public_key, private_key).should eql "decrypted value"
106
91
  end
107
92
  end
108
93
  end
@@ -5,10 +5,10 @@ module Encrypto
5
5
 
6
6
  describe ".generate_keypair" do
7
7
  it "generates a keypair" do
8
- public_key = double("public_key", :to_s => "hex public key")
8
+ public_key = double("public_key")
9
9
  private_key = double("private key", :public_key => public_key)
10
- Crypto::PrivateKey.should_receive(:generate).and_return(private_key)
11
- Encrypto::Keys.generate_keypair.should eql ["hex public key", private_key]
10
+ RbNaCl::PrivateKey.should_receive(:generate).and_return(private_key)
11
+ Encrypto::Keys.generate_keypair.should eql [public_key, private_key]
12
12
  end
13
13
  end
14
14
 
@@ -6,7 +6,7 @@ module Encrypto
6
6
  describe ".bytes" do
7
7
  it "creates a random byte sequence" do
8
8
  random_bytes = "asf2020fasd"
9
- Crypto::Random.should_receive(:random_bytes).and_return(random_bytes)
9
+ RbNaCl::Random.should_receive(:random_bytes).and_return(random_bytes)
10
10
  Encrypto::Random.bytes.should eql random_bytes
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encrypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,18 +14,18 @@ date: 2013-12-04 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rbnacl
17
- requirement: &70128989961020 !ruby/object:Gem::Requirement
17
+ requirement: &70098716360120 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: 1.1.0
22
+ version: 2.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70128989961020
25
+ version_requirements: *70098716360120
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: attr_encrypted
28
- requirement: &70128989960500 !ruby/object:Gem::Requirement
28
+ requirement: &70098716359360 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70128989960500
36
+ version_requirements: *70098716359360
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: pry-nav
39
- requirement: &70128989959820 !ruby/object:Gem::Requirement
39
+ requirement: &70098716358900 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.2.3
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70128989959820
47
+ version_requirements: *70098716358900
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &70128989959120 !ruby/object:Gem::Requirement
50
+ requirement: &70098716358440 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.14.1
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70128989959120
58
+ version_requirements: *70098716358440
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: spec_coverage
61
- requirement: &70128989958440 !ruby/object:Gem::Requirement
61
+ requirement: &70098716357960 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: 0.0.5
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70128989958440
69
+ version_requirements: *70098716357960
70
70
  description: A gem that supports encrypting personal data by using rbnacl and attr_encrypted
71
71
  email: service@finalist.nl
72
72
  executables: []
@@ -89,7 +89,6 @@ files:
89
89
  - lib/encrypto/version.rb
90
90
  - script/bundler
91
91
  - script/ci
92
- - script/install_libsodium
93
92
  - spec/encrypto/box_spec.rb
94
93
  - spec/encrypto/database/encryptor_spec.rb
95
94
  - spec/encrypto/encrypto_spec.rb
@@ -1,10 +0,0 @@
1
- #!/bin/sh
2
- if [ ! -f /usr/local/lib/libsodium.a ];
3
- then
4
- curl -o /tmp/sodium.tar.gz https://download.libsodium.org/libsodium/releases/old/libsodium-0.2.tar.gz
5
- cd /tmp
6
- tar vfzx sodium.tar.gz
7
- cd libsodium-0.2
8
- ./configure
9
- make && make check && make install
10
- fi