h 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -2
- data/README.md +3 -6
- data/Rakefile +11 -1
- data/VERSION.semver +1 -1
- data/bin/h +18 -10
- data/h.gemspec +10 -8
- data/lib/h.rb +36 -28
- data/test/_test_helper.rb +2 -1
- data/test/test_h.rb +7 -4
- metadata +32 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daf6350a70f380ef714bfb86e77e8a1d5f4b05ed
|
4
|
+
data.tar.gz: 9b3baceb934db36f229949fbbb765b6bbcf15d68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b86e45795c948aa6efbbcc3cc12f1b240b182f49f60564b526418b78f18457c9dd843da052998a04bc5f10a3058092f65c0cb50ecc4e406a5198be7d6d78f22
|
7
|
+
data.tar.gz: 5ee9d076127028ac24d27835df735066c405cbce1a8a807267537b2a5bb2f90b2e5ec261fe026321b21e4036e3994f4ec1052021caeb140da46fb33199313799
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -33,16 +33,13 @@ Same operation, from Ruby:
|
|
33
33
|
irb(main):002:0> H::Generator.new("塩").input "シークレット", 3
|
34
34
|
"-q0"
|
35
35
|
|
36
|
-
To prevent your log display the message as a string, do not specify it at first.
|
37
|
-
|
38
|
-
$ h
|
39
|
-
Message: ******
|
40
|
-
-q0zMnMSszj8D23a8aNJX_VYry9oSSLZ30XlHkmFt9I=
|
41
|
-
|
42
36
|
## Status
|
43
37
|
|
38
|
+
* [![Gem Version](https://badge.fury.io/rb/h.png)](http://badge.fury.io/rb/h)
|
44
39
|
* [![Build Status](https://secure.travis-ci.org/cyril/h.rb.png)](//travis-ci.org/cyril/h.rb)
|
45
40
|
* [![Dependency Status](https://gemnasium.com/cyril/h.rb.svg)](//gemnasium.com/cyril/h.rb)
|
41
|
+
* [![Inline docs](http://inch-ci.org/github/cyril/h.rb.png)](http://inch-ci.org/github/cyril/h.rb)
|
42
|
+
* ![](https://ruby-gem-downloads-badge.herokuapp.com/h?type=total)
|
46
43
|
|
47
44
|
* * *
|
48
45
|
|
data/Rakefile
CHANGED
@@ -2,6 +2,16 @@ require 'bundler/gem_tasks'
|
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
4
|
Rake::TestTask.new do |t|
|
5
|
+
t.verbose = true
|
6
|
+
t.warning = true
|
5
7
|
end
|
6
8
|
|
7
|
-
|
9
|
+
namespace :test do
|
10
|
+
task :coverage do
|
11
|
+
ENV['COVERAGE'] = 'true'
|
12
|
+
Rake::Task['test'].invoke
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task(:doc_stats) { ruby '-S yard stats' }
|
17
|
+
task default: [:test, :doc_stats]
|
data/VERSION.semver
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/bin/h
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
require_relative File.join '..', 'lib', 'h'
|
4
4
|
|
5
|
-
|
5
|
+
CONF_PATH = File.join(File.expand_path('~'), '.h')
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
unless File.exist?(CONF_PATH)
|
8
|
+
print "Creating #{CONF_PATH} file... "
|
9
|
+
|
10
|
+
File.open(CONF_PATH, 'w') do |f|
|
11
|
+
f.write('secret')
|
12
12
|
end
|
13
|
-
|
14
|
-
|
13
|
+
|
14
|
+
File.chmod(0600, CONF_PATH)
|
15
|
+
|
16
|
+
puts 'Done.'
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
h = H::Generator.new(File.open(CONF_PATH).readlines.first.chomp)
|
20
|
+
|
21
|
+
puts h.input ARGV[0].to_s, if ARGV[1].nil?
|
22
|
+
44
|
23
|
+
else
|
24
|
+
ARGV[1].to_i
|
25
|
+
end
|
data/h.gemspec
CHANGED
@@ -2,20 +2,22 @@ Gem::Specification.new do |spec|
|
|
2
2
|
spec.name = 'h'
|
3
3
|
spec.version = File.read('VERSION.semver')
|
4
4
|
spec.authors = ['Cyril Wack']
|
5
|
-
spec.email = ['contact@cyril.
|
5
|
+
spec.email = ['contact@cyril.email']
|
6
6
|
spec.homepage = 'https://github.com/cyril/h.rb'
|
7
|
-
spec.summary =
|
8
|
-
spec.description =
|
7
|
+
spec.summary = 'Salted hashes tool'
|
8
|
+
spec.description = 'Small tool that generates salted hashes, scented ' \
|
9
|
+
'with the SHA2 function, for those who prefer to put ' \
|
10
|
+
'makeup on passwords rather than yield them to Manager™.'
|
9
11
|
spec.license = 'ISC'
|
10
12
|
|
11
13
|
spec.files = `git ls-files -z`.split("\x0")
|
12
|
-
spec.executables = spec.files.grep(
|
13
|
-
spec.test_files = spec.files.grep(
|
14
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(/^test\//)
|
14
16
|
spec.require_paths = ['lib']
|
15
17
|
|
16
|
-
spec.
|
17
|
-
|
18
|
-
spec.add_development_dependency 'bundler', '~> 1.6'
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
19
19
|
spec.add_development_dependency 'minitest', '~> 5'
|
20
20
|
spec.add_development_dependency 'rake', '~> 10'
|
21
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
22
|
+
spec.add_development_dependency 'coveralls', '~> 0.7'
|
21
23
|
end
|
data/lib/h.rb
CHANGED
@@ -1,46 +1,54 @@
|
|
1
|
-
require 'highline/import'
|
2
1
|
require 'digest'
|
3
2
|
|
3
|
+
# Namespace and main entry point for the H library.
|
4
4
|
module H
|
5
|
+
# Class that generates cryptographic hash
|
5
6
|
class Generator
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
File.open(CONF_PATH, 'w') do |f|
|
16
|
-
f.write('secret')
|
17
|
-
end
|
18
|
-
|
19
|
-
File.chmod(0600, CONF_PATH)
|
20
|
-
|
21
|
-
puts "Done."
|
22
|
-
end
|
23
|
-
|
24
|
-
File.open(CONF_PATH).readlines.first.chomp
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def prompt
|
29
|
-
input ask('Message: ') {|q| q.echo = '*' }
|
7
|
+
# Initialize a H instance.
|
8
|
+
#
|
9
|
+
# @param static_key [String] a random data
|
10
|
+
#
|
11
|
+
# @return [H::Generator] instance
|
12
|
+
#
|
13
|
+
def initialize(static_key)
|
14
|
+
@static_key = static_key
|
30
15
|
end
|
31
16
|
|
32
|
-
|
33
|
-
|
17
|
+
# Return a hash of +l+ length.
|
18
|
+
#
|
19
|
+
# @param m [String] a message
|
20
|
+
# @param l [Fixnum] the length of the returned string
|
21
|
+
#
|
22
|
+
# @return [String] salted cryptographic hash.
|
23
|
+
#
|
24
|
+
# @api public
|
25
|
+
def input(m, l)
|
26
|
+
m += @static_key
|
34
27
|
d = cryptographic_hash(m)
|
35
28
|
truncate d, l
|
36
29
|
end
|
37
30
|
|
38
31
|
protected
|
39
32
|
|
33
|
+
# Build a hash from +m+ message.
|
34
|
+
#
|
35
|
+
# @param m [String] a message
|
36
|
+
#
|
37
|
+
# @return [String] cryptographic hash.
|
38
|
+
#
|
39
|
+
# @api private
|
40
40
|
def cryptographic_hash(m)
|
41
|
-
Digest::
|
41
|
+
::Digest::SHA256.base64digest(m).tr('+/', '-_')
|
42
42
|
end
|
43
43
|
|
44
|
+
# Truncate the given string from +lng+ param.
|
45
|
+
#
|
46
|
+
# @param str [String] a string to truncate
|
47
|
+
# @param lng [Fixnum] the length of the truncated string
|
48
|
+
#
|
49
|
+
# @return [String] truncated string.
|
50
|
+
#
|
51
|
+
# @api private
|
44
52
|
def truncate(str, lng)
|
45
53
|
str[0, lng]
|
46
54
|
end
|
data/test/_test_helper.rb
CHANGED
data/test/test_h.rb
CHANGED
@@ -7,11 +7,12 @@ describe H::Generator do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'returns a salted hash' do
|
10
|
-
@h.input('').must_equal 'rdOQxxmSfOy-3-HA7OrnqT2Pl2Y_I7Ojqsc1NwVP4sg='
|
10
|
+
@h.input('', 44).must_equal 'rdOQxxmSfOy-3-HA7OrnqT2Pl2Y_I7Ojqsc1NwVP4sg='
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'returns another salted hash' do
|
14
|
-
@h.input('p@ssw0rd').must_equal 'LCoF25LqK6yFMRs6OoQoZEI4GV4-
|
14
|
+
@h.input('p@ssw0rd', 44).must_equal 'LCoF25LqK6yFMRs6OoQoZEI4GV4-gR7vd1' \
|
15
|
+
'JZtbi8swA='
|
15
16
|
end
|
16
17
|
|
17
18
|
it 'returns a salted hash of 8 chars' do
|
@@ -25,11 +26,13 @@ describe H::Generator do
|
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'returns a different salted hash' do
|
28
|
-
@h.input('p@ssw0rd').wont_equal 'LCoF25LqK6yFMRs6OoQoZEI4GV4-
|
29
|
+
@h.input('p@ssw0rd', 44).wont_equal 'LCoF25LqK6yFMRs6OoQoZEI4GV4-gR7vd1' \
|
30
|
+
'JZtbi8swA='
|
29
31
|
end
|
30
32
|
|
31
33
|
it 'returns a salted hash' do
|
32
|
-
@h.input('シークレット').must_equal '-
|
34
|
+
@h.input('シークレット', 44).must_equal '-q0zMnMSszj8D23a8aNJX_VYry9oSSLZ30Xl' \
|
35
|
+
'HkmFt9I='
|
33
36
|
end
|
34
37
|
|
35
38
|
it 'returns a salted hash of 3 chars' do
|
metadata
CHANGED
@@ -1,75 +1,89 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: h
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cyril Wack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
20
|
-
type: :
|
19
|
+
version: '1.7'
|
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'
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5'
|
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
|
-
version: '
|
40
|
+
version: '5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.8'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
69
83
|
description: Small tool that generates salted hashes, scented with the SHA2 function,
|
70
84
|
for those who prefer to put makeup on passwords rather than yield them to Manager™.
|
71
85
|
email:
|
72
|
-
- contact@cyril.
|
86
|
+
- contact@cyril.email
|
73
87
|
executables:
|
74
88
|
- h
|
75
89
|
extensions: []
|
@@ -108,10 +122,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
122
|
version: '0'
|
109
123
|
requirements: []
|
110
124
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.4.5
|
112
126
|
signing_key:
|
113
127
|
specification_version: 4
|
114
128
|
summary: Salted hashes tool
|
115
129
|
test_files:
|
116
130
|
- test/_test_helper.rb
|
117
131
|
- test/test_h.rb
|
132
|
+
has_rdoc:
|