kryptonita 0.0.8 → 0.0.9

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: 4a422b0c719217d808a03db0999df77ead10e62b
4
- data.tar.gz: 60676305f2cf1428599a7a36f5a6fa51ffa11d8c
3
+ metadata.gz: 06cce4dc171629a2427c5dab26dde30a03867a06
4
+ data.tar.gz: 2677cd295a304fc9b6dda4927c2c60aeb671f019
5
5
  SHA512:
6
- metadata.gz: 91e3d6bdefff60954c3648b86063045d7ecb2ab84afe074d2dcb05dcc1d0445dccaaff133b038f5dfb515655f431fbda6062580a3c3c1587b03604a2ca357d84
7
- data.tar.gz: eac79d9d2bd10aaafc9774192efd0a2b0dc4c64873e090393bef85f9cb277725626f13ea2e0752e5c060b7ecf7239fa6a42d15ed589216fb7f7de7beb72e725b
6
+ metadata.gz: d3c14ae4c865810f1db4f8039f950a455d233188acb55e914c9a7c84611bb6a81433cab947d59834b85de30bbecbb4db6c89cfb93d8acba715f43850ea2c4aa9
7
+ data.tar.gz: d8799219473c5898283d4e0b257014f349b0c900c43702d68766769a7fe6902602d7785f49e5428ceedbd792d6c502f2a66a045a86066276aac83867bde6e2fd
data/README.md CHANGED
@@ -1,11 +1,7 @@
1
- # Kryptonita [![Gem Version](https://badge.fury.io/rb/kryptonita.svg)](http://badge.fury.io/rb/kryptonita) [![Code Climate](https://codeclimate.com/github/AngoDev/kryptonita/badges/gpa.svg)](https://codeclimate.com/github/AngoDev/kryptonita) [![Test Coverage](https://codeclimate.com/github/psantos10/Validation/badges/coverage.svg)](https://codeclimate.com/github/psantos10/Validation) [![Build Status](https://travis-ci.org/AngoDev/kryptonita.svg)](https://travis-ci.org/AngoDev/kryptonita)
1
+ # Kryptonita [![Gem Version](https://badge.fury.io/rb/kryptonita.svg)](http://badge.fury.io/rb/kryptonita) [![Code Climate](https://codeclimate.com/github/AngoDev/kryptonita/badges/gpa.svg)](https://codeclimate.com/github/AngoDev/kryptonita) [![Test Coverage](https://codeclimate.com/github/psantos10/Validation/badges/coverage.svg)](https://codeclimate.com/github/psantos10/Validation)
2
2
 
3
3
  Kryptonita is a Ruby gem that provides a lot of functions for hashing, encrypt and decrypt
4
4
 
5
- ## Available Hash Functions
6
-
7
- - Whirlpool (Return a String with 128 length)
8
-
9
5
  ## Installation
10
6
 
11
7
  Add this line to your application's Gemfile:
@@ -35,8 +31,11 @@ puts Kryptonita::Hash.whirlpool("ruby")
35
31
 
36
32
 
37
33
  ```ruby
38
- Kryptonita::Hash.whirlpool(str)
34
+ Kryptonita::Hash.md5(str)
35
+ Kryptonita::Hash.md5(str, salt: 'mysalt')
36
+ Kryptonita::Hash.sha1(str)
39
37
  Kryptonita::Hash.sha512(str)
38
+ Kryptonita::Hash.whirlpool(str)
40
39
  ```
41
40
 
42
41
  ## Contributing
@@ -1,6 +1,6 @@
1
1
  require "kryptonita/version"
2
2
  #require "./whirlpool/whirlpool"
3
- require "digest/sha2"
3
+ require "digest"
4
4
 
5
5
  # Support multiple ruby versions, fat binaries under Windows.
6
6
  begin
@@ -13,14 +13,26 @@ end
13
13
  module Kryptonita
14
14
  class Hash
15
15
 
16
- def self.whirlpool(str)
17
- w = Whirlpool::Class.new
18
- w.print_string(str).downcase
16
+ def self.md5(str, salt: nil)
17
+ if salt.nil?
18
+ Digest::MD5.hexdigest(str)
19
+ else
20
+ Digest::MD5.hexdigest(Digest::MD5.digest(str) + salt)
21
+ end
22
+ end
23
+
24
+ def self.sha1(str)
25
+ Digest::SHA1.hexdigest(str)
19
26
  end
20
27
 
21
28
  def self.sha512(str)
22
29
  Digest::SHA512.hexdigest(str)
23
30
  end
24
31
 
32
+ def self.whirlpool(str)
33
+ w = Whirlpool::Class.new
34
+ w.print_string(str).downcase
35
+ end
36
+
25
37
  end
26
38
  end
@@ -1,3 +1,3 @@
1
1
  module Kryptonita
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -3,22 +3,41 @@ require "spec_helper"
3
3
  module Kryptonita
4
4
  describe Hash do
5
5
 
6
- describe "#whirlpool" do
7
- let(:hashed) { Kryptonita::Hash.whirlpool("ruby") }
6
+ describe "md5" do
7
+ let(:hashed) { Kryptonita::Hash.md5("ruby") }
8
+ let(:hashed_with_salt) { Kryptonita::Hash.md5("ruby", salt: 'salt') }
8
9
 
9
10
  it "returns a string" do
10
11
  expect(hashed).to be_a(String)
12
+ expect(hashed_with_salt).to be_a(String)
11
13
  end
12
14
 
13
- it "returns a string with a size 128" do
14
- expect(hashed.size).to eq(128)
15
+ it "returns a string with size 32" do
16
+ expect(hashed.size).to eq(32)
17
+ expect(hashed_with_salt.size).to eq(32)
15
18
  end
16
19
 
17
20
  it "returns a correct hash" do
18
- expect(hashed).to eql("95fc6a05b1edd849a202d9cdb1158930cf1e101900357a8816b743520710be2487c890c3bfb2b70f2308f7e8737473a477bb44950516c23e53a2993091faa9d2")
21
+ expect(hashed).to eql("58e53d1324eef6265fdb97b08ed9aadf")
22
+ expect(hashed_with_salt).to eql("cb2dfb8002036f039bd61a1c1fbbbd3c")
19
23
  end
20
24
  end
21
25
 
26
+ describe "sha1" do
27
+ let(:hashed) { Kryptonita::Hash.sha1("ruby") }
28
+
29
+ it "returns a string" do
30
+ expect(hashed).to be_a(String)
31
+ end
32
+
33
+ it "returns a string with a size 40" do
34
+ expect(hashed.size).to eq(40)
35
+ end
36
+
37
+ it "returns a correct hash" do
38
+ expect(hashed).to eql("18e40e1401eef67e1ae69efab09afb71f87ffb81")
39
+ end
40
+ end
22
41
 
23
42
  describe "#sha512" do
24
43
  let(:hashed) { Kryptonita::Hash.sha512("ruby") }
@@ -36,5 +55,22 @@ module Kryptonita
36
55
  end
37
56
  end
38
57
 
58
+ describe "#whirlpool" do
59
+ let(:hashed) { Kryptonita::Hash.whirlpool("ruby") }
60
+
61
+ it "returns a string" do
62
+ expect(hashed).to be_a(String)
63
+ end
64
+
65
+ it "returns a string with a size 128" do
66
+ expect(hashed.size).to eq(128)
67
+ end
68
+
69
+ it "returns a correct hash" do
70
+ expect(hashed).to eql("95fc6a05b1edd849a202d9cdb1158930cf1e101900357a8816b743520710be2487c890c3bfb2b70f2308f7e8737473a477bb44950516c23e53a2993091faa9d2")
71
+ end
72
+ end
73
+
74
+
39
75
  end
40
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kryptonita
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrício dos Santos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler