h 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -2
- data/{ISC-LICENSE → ISC-LICENSE.md} +1 -1
- data/README.md +79 -0
- data/Rakefile +2 -7
- data/VERSION.yml +3 -3
- data/bin/h +9 -3
- data/h.gemspec +11 -9
- data/lib/h.rb +16 -33
- data/test/{test_helper.rb → _test_helper.rb} +2 -0
- data/test/test_h.rb +12 -0
- metadata +46 -47
- data/.rvmrc +0 -1
- data/README.rdoc +0 -67
- data/test/h_test.rb +0 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c2252b8ef1fd60b325187cc109d55b7877a737de
|
4
|
+
data.tar.gz: 86ec92d920c7ee56b6b810b38a36d3e9af5c4e59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60086b1404f5b51e36f2007f044780614693545a736990d826dfb03ae8f92498a8f741eb4f87eda8d0430868ed11a71d0e7ec3b1f81dac444887bf9bc3122737
|
7
|
+
data.tar.gz: 5ac7b4848c58bb7b4f4c2a110bd25974ee57661c2db0325cae63023712fd273bae49d3a3663a24408083c7913b282014896adb59a330397e45337eb2ac15a344
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
STATIC_KEY=secret
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
H
|
2
|
+
=
|
3
|
+
|
4
|
+
Overview
|
5
|
+
--------
|
6
|
+
|
7
|
+
Very small cryptographic tool that generates on-the-fly custom message digests,
|
8
|
+
according to some parameters.
|
9
|
+
|
10
|
+
Why?
|
11
|
+
----
|
12
|
+
|
13
|
+
Because I prefer to put makeup on passwords rather than yield them to Manager™.
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
$ gem install h
|
19
|
+
|
20
|
+
Configuration
|
21
|
+
-------------
|
22
|
+
|
23
|
+
H reads its configuration from the YAML `~/.h` file at initialization.
|
24
|
+
This file, which should be readable by its owner only, has four parameters:
|
25
|
+
|
26
|
+
* Max length: The maximum length of returned message digests.
|
27
|
+
* Radix: The number of unique digits that compose message digests.
|
28
|
+
* Encryption: A cryptographic hash function in Ruby's Digest module.
|
29
|
+
* Static key: Provides salted messages through concatenation.
|
30
|
+
|
31
|
+
Examples
|
32
|
+
--------
|
33
|
+
|
34
|
+
Generate a digest from the system:
|
35
|
+
|
36
|
+
$ h secret
|
37
|
+
t3dpe24xie3y74t
|
38
|
+
|
39
|
+
Because no configuration has been detected, this default file was created:
|
40
|
+
|
41
|
+
$ cat ~/.h
|
42
|
+
---
|
43
|
+
max_length: 15
|
44
|
+
radix: 36
|
45
|
+
encryption: SHA1
|
46
|
+
static_key: foobar
|
47
|
+
|
48
|
+
Same operation, from Ruby:
|
49
|
+
|
50
|
+
irb(main):001:0> require "h"
|
51
|
+
true
|
52
|
+
irb(main):002:0> H::Generator.new.input "secret"
|
53
|
+
"t3dpe24xie3y74t"
|
54
|
+
|
55
|
+
To prevent your log display the message as a string, do not specify it at first.
|
56
|
+
|
57
|
+
$ h
|
58
|
+
Message: ******
|
59
|
+
t3dpe24xie3y74t
|
60
|
+
|
61
|
+
Example with the SHA2 cryptographic hash instead of SHA1, and a custom key:
|
62
|
+
|
63
|
+
$ echo "{max_length: 15, radix: 36, encryption: SHA2, static_key: sun}" > ~/.h
|
64
|
+
$ h secret
|
65
|
+
5gumh4smv1iit23
|
66
|
+
|
67
|
+
And now a useless test, with conventional parameters. You can Google the result.
|
68
|
+
|
69
|
+
$ echo "{max_length: 40, radix: 16, encryption: SHA1, static_key: ''}" > ~/.h
|
70
|
+
$ h "The quick brown fox jumps over the lazy dog"
|
71
|
+
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
|
72
|
+
|
73
|
+
Code Status
|
74
|
+
-----------
|
75
|
+
|
76
|
+
* [![Build Status](https://secure.travis-ci.org/cyril/h.png)](http://travis-ci.org/cyril/h)
|
77
|
+
* [![Dependencies Status](https://gemnasium.com/cyril/h.png?travis)](https://gemnasium.com/cyril/h)
|
78
|
+
|
79
|
+
Copyright (c) 2011 Cyril Wack, released under the ISC license
|
data/Rakefile
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
4
2
|
require 'rake/testtask'
|
5
3
|
|
6
4
|
Rake::TestTask.new do |t|
|
7
|
-
t.libs << 'lib'
|
8
|
-
t.libs << 'test'
|
9
|
-
t.test_files = FileList["test/**/*_{helper,test}.rb"]
|
10
5
|
end
|
11
6
|
|
12
|
-
task :
|
7
|
+
task default: :test
|
data/VERSION.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
---
|
2
|
-
:major:
|
3
|
-
:minor:
|
4
|
-
:patch:
|
2
|
+
:major: 2
|
3
|
+
:minor: 0
|
4
|
+
:patch: 0
|
data/bin/h
CHANGED
@@ -4,8 +4,14 @@ require 'h'
|
|
4
4
|
|
5
5
|
h = H::Generator.new
|
6
6
|
|
7
|
-
if ARGV.first
|
8
|
-
|
7
|
+
result = if ARGV.first
|
8
|
+
if ARGV[1]
|
9
|
+
h.input ARGV[0], ARGV[1].to_i
|
10
|
+
else
|
11
|
+
h.input ARGV[0]
|
12
|
+
end
|
9
13
|
else
|
10
|
-
|
14
|
+
h.prompt
|
11
15
|
end
|
16
|
+
|
17
|
+
puts result
|
data/h.gemspec
CHANGED
@@ -1,24 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'yaml'
|
4
|
+
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = YAML.load_file(
|
6
|
+
s.name = 'h'
|
7
|
+
s.version = YAML.load_file('VERSION.yml').values.join('.')
|
6
8
|
s.platform = Gem::Platform::RUBY
|
7
|
-
s.authors = [
|
8
|
-
s.email = [
|
9
|
-
s.homepage =
|
9
|
+
s.authors = ['Cyril Wack']
|
10
|
+
s.email = ['contact@cyril.io']
|
11
|
+
s.homepage = 'https://github.com/cyril/h'
|
10
12
|
s.summary = %q{Custom hash generator}
|
11
13
|
s.description = %q{A quick tool for those who prefer to put makeup on passwords rather than yield them to Manager™}
|
12
14
|
|
13
15
|
s.rubyforge_project = 'h'
|
14
16
|
|
15
|
-
s.bindir
|
16
|
-
s.executables
|
17
|
+
s.bindir = 'bin'
|
18
|
+
s.executables = ['h']
|
17
19
|
|
18
20
|
s.add_dependency 'highline'
|
19
21
|
|
20
22
|
s.files = `git ls-files`.split("\n")
|
21
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{
|
23
|
-
s.require_paths = [
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
|
25
|
+
s.require_paths = ['lib']
|
24
26
|
end
|
data/lib/h.rb
CHANGED
@@ -1,50 +1,33 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler.require
|
5
|
+
|
2
6
|
require 'highline/import'
|
3
|
-
require '
|
7
|
+
require 'digest'
|
8
|
+
require 'dotenv'
|
9
|
+
Dotenv.load
|
4
10
|
|
5
11
|
module H
|
6
12
|
class Generator
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(options = {})
|
10
|
-
unless File.exists?(CONF_PATH)
|
11
|
-
File.open(CONF_PATH, 'w') do |f|
|
12
|
-
YAML.dump({ 'encryption' => 'SHA1',
|
13
|
-
'static_key' => 'foobar',
|
14
|
-
'max_length' => 15,
|
15
|
-
'radix' => 36 }, f)
|
16
|
-
end
|
17
|
-
|
18
|
-
File.chmod(0600, CONF_PATH)
|
19
|
-
end
|
20
|
-
|
21
|
-
@params = YAML.load_file(CONF_PATH)
|
22
|
-
@params.update(options)
|
23
|
-
@params.freeze
|
13
|
+
def prompt
|
14
|
+
input ask('Message: ') {|q| q.echo = '*' }
|
24
15
|
end
|
25
16
|
|
26
|
-
def input(
|
27
|
-
m =
|
17
|
+
def input(m, l = 44)
|
18
|
+
m = m + ENV.fetch('STATIC_KEY')
|
28
19
|
d = cryptographic_hash(m)
|
29
|
-
truncate
|
30
|
-
end
|
31
|
-
|
32
|
-
def prompt
|
33
|
-
input ask('Message: ') {|q| q.echo = '*' }
|
20
|
+
truncate d, l
|
34
21
|
end
|
35
22
|
|
36
23
|
protected
|
37
24
|
|
38
|
-
def codage(hexdigest)
|
39
|
-
hexdigest.to_i(16).to_s(@params['radix'])
|
40
|
-
end
|
41
|
-
|
42
25
|
def cryptographic_hash(message)
|
43
|
-
Digest.
|
26
|
+
Digest::SHA2.base64digest(message).tr('+/', '-_')
|
44
27
|
end
|
45
28
|
|
46
|
-
def truncate(string)
|
47
|
-
string[0,
|
29
|
+
def truncate(string, length)
|
30
|
+
string[0, length]
|
48
31
|
end
|
49
32
|
end
|
50
33
|
end
|
data/test/test_h.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative '_test_helper'
|
2
|
+
|
3
|
+
class HTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@h = H::Generator.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_h
|
9
|
+
assert_equal @h.input('p@ssw0rd'), 'SdsRrcHHSpJvfhkPM8Np047CocaWRQ2nzPYEw9qWYIo='
|
10
|
+
assert_equal @h.input('p@ssw0rd', 8), 'SdsRrcHH'
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,76 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: h
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Cyril Wack
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: highline
|
17
|
-
|
18
|
-
|
19
|
-
none: false
|
20
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
21
17
|
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
24
20
|
type: :runtime
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A quick tool for those who prefer to put makeup on passwords rather than
|
28
|
+
yield them to Manager™
|
29
|
+
email:
|
28
30
|
- contact@cyril.io
|
29
|
-
executables:
|
31
|
+
executables:
|
30
32
|
- h
|
31
33
|
extensions: []
|
32
|
-
|
33
34
|
extra_rdoc_files: []
|
34
|
-
|
35
|
-
|
36
|
-
- .gitignore
|
37
|
-
- .
|
35
|
+
files:
|
36
|
+
- ".env.example"
|
37
|
+
- ".gitignore"
|
38
|
+
- ".ruby-version"
|
39
|
+
- ".travis.yml"
|
38
40
|
- Gemfile
|
39
|
-
- ISC-LICENSE
|
40
|
-
- README.
|
41
|
+
- ISC-LICENSE.md
|
42
|
+
- README.md
|
41
43
|
- Rakefile
|
42
44
|
- VERSION.yml
|
43
45
|
- bin/h
|
44
46
|
- h.gemspec
|
45
47
|
- lib/h.rb
|
46
|
-
- test/
|
47
|
-
- test/
|
48
|
-
homepage:
|
48
|
+
- test/_test_helper.rb
|
49
|
+
- test/test_h.rb
|
50
|
+
homepage: https://github.com/cyril/h
|
49
51
|
licenses: []
|
50
|
-
|
52
|
+
metadata: {}
|
51
53
|
post_install_message:
|
52
54
|
rdoc_options: []
|
53
|
-
|
54
|
-
require_paths:
|
55
|
+
require_paths:
|
55
56
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
|
58
|
-
requirements:
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
59
|
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
|
64
|
-
requirements:
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
65
64
|
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version:
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
68
67
|
requirements: []
|
69
|
-
|
70
68
|
rubyforge_project: h
|
71
|
-
rubygems_version:
|
69
|
+
rubygems_version: 2.2.2
|
72
70
|
signing_key:
|
73
|
-
specification_version:
|
71
|
+
specification_version: 4
|
74
72
|
summary: Custom hash generator
|
75
|
-
test_files:
|
76
|
-
|
73
|
+
test_files:
|
74
|
+
- test/_test_helper.rb
|
75
|
+
- test/test_h.rb
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm ruby-1.9.2@h
|
data/README.rdoc
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
= H
|
2
|
-
|
3
|
-
== Overview
|
4
|
-
|
5
|
-
Very small cryptographic tool that generates on-the-fly custom message digests,
|
6
|
-
according to some parameters.
|
7
|
-
|
8
|
-
== Why?
|
9
|
-
|
10
|
-
Because I prefer to put makeup on passwords rather than yield them to Manager™.
|
11
|
-
|
12
|
-
== Installation
|
13
|
-
|
14
|
-
gem install h
|
15
|
-
|
16
|
-
== Configuration
|
17
|
-
|
18
|
-
H reads its configuration from the YAML <tt>~/.h</tt> file at initialization.
|
19
|
-
This file, which should be readable by its owner only, has four parameters:
|
20
|
-
|
21
|
-
* Max length: The maximum length of returned message digests.
|
22
|
-
* Radix: The number of unique digits that compose message digests.
|
23
|
-
* Encryption: A cryptographic hash function in Ruby's Digest module.
|
24
|
-
* Static key: Provides salted messages through concatenation.
|
25
|
-
|
26
|
-
== Examples
|
27
|
-
|
28
|
-
Generate a digest from the system:
|
29
|
-
|
30
|
-
$ h secret
|
31
|
-
t3dpe24xie3y74t
|
32
|
-
|
33
|
-
Because no configuration has been detected, this default file was created:
|
34
|
-
|
35
|
-
$ cat ~/.h
|
36
|
-
---
|
37
|
-
max_length: 15
|
38
|
-
radix: 36
|
39
|
-
encryption: SHA1
|
40
|
-
static_key: foobar
|
41
|
-
|
42
|
-
Same operation, from Ruby:
|
43
|
-
|
44
|
-
irb(main):001:0> require "h"
|
45
|
-
true
|
46
|
-
irb(main):002:0> H::Generator.new.input "secret"
|
47
|
-
"t3dpe24xie3y74t"
|
48
|
-
|
49
|
-
To prevent your log display the message as a string, do not specify it at first.
|
50
|
-
|
51
|
-
$ h
|
52
|
-
Message: ******
|
53
|
-
t3dpe24xie3y74t
|
54
|
-
|
55
|
-
Example with the SHA2 cryptographic hash instead of SHA1, and a custom key:
|
56
|
-
|
57
|
-
$ echo "{max_length: 15, radix: 36, encryption: SHA2, static_key: sun}" > ~/.h
|
58
|
-
$ h secret
|
59
|
-
5gumh4smv1iit23
|
60
|
-
|
61
|
-
And now a useless test, with conventional parameters. You can Google the result.
|
62
|
-
|
63
|
-
$ echo "{max_length: 40, radix: 16, encryption: SHA1, static_key: ''}" > ~/.h
|
64
|
-
$ h "The quick brown fox jumps over the lazy dog"
|
65
|
-
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
|
66
|
-
|
67
|
-
Copyright (c) 2011 Cyril Wack, released under the ISC license
|
data/test/h_test.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class HTest < MiniTest::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@h = H::Generator.new({ 'encryption' => 'SHA1',
|
6
|
-
'static_key' => 'foobar',
|
7
|
-
'max_length' => 15,
|
8
|
-
'radix' => 36 })
|
9
|
-
@my_h = H::Generator.new({ 'encryption' => 'SHA2',
|
10
|
-
'static_key' => 'sun',
|
11
|
-
'max_length' => 15,
|
12
|
-
'radix' => 36 })
|
13
|
-
@sha1 = H::Generator.new({ 'encryption' => 'SHA1',
|
14
|
-
'static_key' => '',
|
15
|
-
'max_length' => 40,
|
16
|
-
'radix' => 16 })
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_h
|
20
|
-
assert_equal @h.input('secret'), 't3dpe24xie3y74t'
|
21
|
-
assert_equal @my_h.input('secret'), '5gumh4smv1iit23'
|
22
|
-
assert_equal @sha1.input('The quick brown fox jumps over the lazy dog'),
|
23
|
-
'2fd4e1c67a2d28fced849ee1bb76e7391b93eb12'
|
24
|
-
end
|
25
|
-
end
|