rickshaw 0.1.0 → 0.5.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: a38dc506e80cb438e33b33e1c598e5bca41c120a
4
- data.tar.gz: 4dc19977ef4121a41ad5ded8f75e155f30fd5c8d
2
+ SHA256:
3
+ metadata.gz: cd6c78efbf32e090c8e00c4b019c379de3315a68bc686cfefe6e6f30f67a632d
4
+ data.tar.gz: 6fa5a5e6c7bc7fbaf6d09a8ffb1515c95fede324ee2e80892bfb530cb8c3820f
5
5
  SHA512:
6
- metadata.gz: c855f39a4a5f81af81eb3ad4246df01e0c83838012cbf26ce22de11903f611e5c4bccaa2fbd186a7acc8367bfaaf612eb554b127e95c58ad9b6b5986f5ed6e68
7
- data.tar.gz: 1e5862c9f732860924281639708df572c988d2e48404eacac0ded5ba30ddd3440c8b01785567947f436cd688a18a1d0a7f184a0b6d36a90b0597aa7c368ba936
6
+ metadata.gz: 01d1c39ff54ac6233b339b521595a5744108d8abcab1d71f13ebe9d3091f9418d779462ee14a0e158b051facc63edb74914c130bbf85c41aa0f066cc122980d4
7
+ data.tar.gz: 7ee5e1b6f37ceffe48e12706bc7d3eaf0f311bdc07f5e2b031d6c5df1b5e94b5f935378491889cec9dbbf979842fa67ba4de0d61da52f6dcfe523b076ea68347
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Gregory Ostermayr
1
+ Copyright (c) 2016 Gregory Ostermayr
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -25,6 +25,31 @@ Or install it yourself as:
25
25
  > "hello world".to_sha1
26
26
  => "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"
27
27
 
28
+ > Rickshaw::SHA256.hash("LICENSE.txt")
29
+ => "34c15a6c0d68a79f320f7c0d11ab50f2cb9b0cb9f8bd791ce06340f7448df289"
30
+
31
+ > "hello world".to_sha256
32
+ => "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
33
+
34
+ > "hello world".to_md5
35
+ => "5eb63bbbe01eeed093cb22bb8f5acdc3"
36
+
37
+ We can also pack/unpack our hashes to/from binary strings
38
+
39
+ > "hello world".to_sha1.packed_bytes
40
+ => "*\xAEl5\xC9O\xCF\xB4\x15\xDB\xE9_@\x8B\x9C\xE9\x1E\xE8F\xED"
41
+
42
+ > "*\xAEl5\xC9O\xCF\xB4\x15\xDB\xE9_@\x8B\x9C\xE9\x1E\xE8F\xED".unpacked_bytes
43
+ => "2aae6c35c94fcfb415dbe95f408b9ce91ee846ed"
44
+
45
+ We can also pack/unpack to base64
46
+
47
+ > "hello world".to_base64
48
+ => "aGVsbG8gd29ybGQ="
49
+
50
+ > "aGVsbG8gd29ybGQ=".unpack_base64
51
+ => "hello world"
52
+
28
53
  ## Contributing
29
54
 
30
55
  1. Fork it
@@ -0,0 +1,9 @@
1
+ class String
2
+ def packed_bytes
3
+ [self].pack('H*')
4
+ end
5
+
6
+ def unpacked_bytes
7
+ self.unpack('H*').first
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ require 'base64'
2
+
3
+ class String
4
+ def to_base64
5
+ Base64.strict_encode64 self
6
+ end
7
+
8
+ def unpack_base64
9
+ Base64.decode64 self
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def to_md5
3
+ Digest::MD5.hexdigest self
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def to_sha512
3
+ Digest::SHA512.hexdigest self
4
+ end
5
+ end
@@ -1,32 +1,52 @@
1
+ require 'digest/md5'
1
2
  require 'digest/sha1'
2
3
  require 'digest/sha2'
3
4
  require 'rickshaw/version'
5
+ require 'core_ext/string/to_md5'
4
6
  require 'core_ext/string/to_sha1'
5
7
  require 'core_ext/string/to_sha256'
8
+ require 'core_ext/string/to_sha512'
9
+ require 'core_ext/string/to_base64'
10
+ require 'core_ext/string/byte_packing'
6
11
 
7
12
  module Rickshaw
13
+ module MD5
14
+ def self.hash(file_path)
15
+ hash = Digest::MD5.new
16
+ Rickshaw::Helper.hash_file(hash, file_path)
17
+ end
18
+ end
19
+
8
20
  module SHA1
9
21
  def self.hash(file_path)
10
22
  hash = Digest::SHA1.new
11
- open(file_path, 'r') do |io|
12
- until io.eof?
13
- buffer = io.read(1024)
14
- hash.update(buffer)
15
- end
16
- end
17
- hash.hexdigest
23
+ Rickshaw::Helper.hash_file(hash, file_path)
18
24
  end
19
25
  end
20
26
 
21
27
  module SHA256
22
28
  def self.hash(file_path)
23
29
  hash = Digest::SHA256.new
30
+ Rickshaw::Helper.hash_file(hash, file_path)
31
+ end
32
+ end
33
+
34
+ module SHA512
35
+ def self.hash(file_path)
36
+ hash = Digest::SHA512.new
37
+ Rickshaw::Helper.hash_file(hash, file_path)
38
+ end
39
+ end
40
+
41
+ module Helper
42
+ def self.hash_file(hash, file_path)
24
43
  open(file_path, 'r') do |io|
25
44
  until io.eof?
26
45
  buffer = io.read(1024)
27
46
  hash.update(buffer)
28
47
  end
29
48
  end
49
+
30
50
  hash.hexdigest
31
51
  end
32
52
  end
@@ -1,3 +1,3 @@
1
1
  module Rickshaw
2
- VERSION = "0.1.0"
2
+ VERSION = '0.5.0'
3
3
  end
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'rickshaw/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "rickshaw"
7
+ spec.name = 'rickshaw'
8
8
  spec.version = Rickshaw::VERSION
9
- spec.authors = ["Gregory Ostermayr"]
10
- spec.email = ["gregory.ostermayr@gmail.com"]
11
- spec.description = %q{Get SHA1 and other hashes easily}
12
- spec.summary = %q{Get SHA1 and other hashes easily}
13
- spec.homepage = "https://github.com/gregors/rickshaw"
14
- spec.license = "MIT"
9
+ spec.authors = ['Gregory Ostermayr']
10
+ spec.email = ['gregory.ostermayr@gmail.com']
11
+ spec.description = %q{Get MD5, SHA1, SHA256, SHA512 hashes easily}
12
+ spec.summary = %q{Get MD5, SHA1, SHA256, SHA512 hashes easily}
13
+ spec.homepage = 'https://github.com/gregors/rickshaw'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'bundler', '~> 2.1'
22
+ spec.add_development_dependency 'rake'
23
23
  end
metadata CHANGED
@@ -1,57 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rickshaw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Ostermayr
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2020-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Get SHA1 and other hashes easily
41
+ description: Get MD5, SHA1, SHA256, SHA512 hashes easily
42
42
  email:
43
43
  - gregory.ostermayr@gmail.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
51
51
  - README.md
52
52
  - Rakefile
53
+ - lib/core_ext/string/byte_packing.rb
54
+ - lib/core_ext/string/to_base64.rb
55
+ - lib/core_ext/string/to_md5.rb
53
56
  - lib/core_ext/string/to_sha1.rb
54
57
  - lib/core_ext/string/to_sha256.rb
58
+ - lib/core_ext/string/to_sha512.rb
55
59
  - lib/rickshaw.rb
56
60
  - lib/rickshaw/version.rb
57
61
  - rickshaw.gemspec
@@ -59,24 +63,23 @@ homepage: https://github.com/gregors/rickshaw
59
63
  licenses:
60
64
  - MIT
61
65
  metadata: {}
62
- post_install_message:
66
+ post_install_message:
63
67
  rdoc_options: []
64
68
  require_paths:
65
69
  - lib
66
70
  required_ruby_version: !ruby/object:Gem::Requirement
67
71
  requirements:
68
- - - '>='
72
+ - - ">="
69
73
  - !ruby/object:Gem::Version
70
74
  version: '0'
71
75
  required_rubygems_version: !ruby/object:Gem::Requirement
72
76
  requirements:
73
- - - '>='
77
+ - - ">="
74
78
  - !ruby/object:Gem::Version
75
79
  version: '0'
76
80
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.2.2
79
- signing_key:
81
+ rubygems_version: 3.0.8
82
+ signing_key:
80
83
  specification_version: 4
81
- summary: Get SHA1 and other hashes easily
84
+ summary: Get MD5, SHA1, SHA256, SHA512 hashes easily
82
85
  test_files: []