h 2.0.0 → 2.1.1

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: c2252b8ef1fd60b325187cc109d55b7877a737de
4
- data.tar.gz: 86ec92d920c7ee56b6b810b38a36d3e9af5c4e59
3
+ metadata.gz: c07dc8a1160801aa395ef4a00a614038c5ce47b3
4
+ data.tar.gz: a2cc31855430b3c748f052d940f18efba1aeb178
5
5
  SHA512:
6
- metadata.gz: 60086b1404f5b51e36f2007f044780614693545a736990d826dfb03ae8f92498a8f741eb4f87eda8d0430868ed11a71d0e7ec3b1f81dac444887bf9bc3122737
7
- data.tar.gz: 5ac7b4848c58bb7b4f4c2a110bd25974ee57661c2db0325cae63023712fd273bae49d3a3663a24408083c7913b282014896adb59a330397e45337eb2ac15a344
6
+ metadata.gz: f119cb301bca5c0245bc4ec16a28999730a509c250759c87a482becda3ef653c40704ce1bb859b0ab45779253159201ac1e478296004c123ab0a08f793068570
7
+ data.tar.gz: 5382479ddf4fd3cb89a31612ba1d1bb213953a64ec5fdd4168c5c42cda9ec4f1f7924705e8a584efa161904b25a533218ee6c347dcc94b276fdcdf17b60e9b38
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
2
  .bundle
3
- .env
4
3
  Gemfile.lock
5
4
  pkg/*
data/Gemfile CHANGED
@@ -1,9 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- ruby '2.1.1'
4
-
5
3
  gemspec
6
4
 
7
5
  gem 'rake'
8
6
  gem 'highline'
9
- gem 'dotenv'
File without changes
data/README.md CHANGED
@@ -1,79 +1,49 @@
1
- H
2
- =
1
+ # H
3
2
 
4
- Overview
5
- --------
3
+ ## Overview
6
4
 
7
- Very small cryptographic tool that generates on-the-fly custom message digests,
8
- according to some parameters.
5
+ Small tool that generates salted hashes, scented with the SHA2 function.
9
6
 
10
- Why?
11
- ----
7
+ ## Why?
12
8
 
13
- Because I prefer to put makeup on passwords rather than yield them to Manager™.
9
+ > I prefer to put makeup on passwords rather than yield them to Manager™.
14
10
 
15
- Installation
16
- ------------
11
+ ## Installation
17
12
 
18
13
  $ gem install h
19
14
 
20
- Configuration
21
- -------------
15
+ ## Configuration
22
16
 
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:
17
+ H reads its configuration from the `~/.h` file at initialization. This file, which should be readable by its owner only, have the salt value.
25
18
 
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
- --------
19
+ ## Examples
33
20
 
34
21
  Generate a digest from the system:
35
22
 
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
23
+ $ echo "塩" > ~/.h
24
+ $ h シークレット
25
+ -q0zMnMSszj8D23a8aNJX_VYry9oSSLZ30XlHkmFt9I=
26
+ $ h secret 3
27
+ -q0
47
28
 
48
29
  Same operation, from Ruby:
49
30
 
50
31
  irb(main):001:0> require "h"
51
32
  true
52
- irb(main):002:0> H::Generator.new.input "secret"
53
- "t3dpe24xie3y74t"
33
+ irb(main):002:0> H::Generator.new("塩").input "シークレット", 3
34
+ "-q0"
54
35
 
55
36
  To prevent your log display the message as a string, do not specify it at first.
56
37
 
57
38
  $ h
58
39
  Message: ******
59
- t3dpe24xie3y74t
60
-
61
- Example with the SHA2 cryptographic hash instead of SHA1, and a custom key:
40
+ -q0zMnMSszj8D23a8aNJX_VYry9oSSLZ30XlHkmFt9I=
62
41
 
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
- -----------
42
+ ## Code Status
75
43
 
76
44
  * [![Build Status](https://secure.travis-ci.org/cyril/h.png)](http://travis-ci.org/cyril/h)
77
45
  * [![Dependencies Status](https://gemnasium.com/cyril/h.png?travis)](https://gemnasium.com/cyril/h)
78
46
 
79
- Copyright (c) 2011 Cyril Wack, released under the ISC license
47
+ * * *
48
+
49
+ Copyright (c) 2014 Cyril Wack, released under the [ISC license](LICENSE.md)
@@ -0,0 +1 @@
1
+ 2.1.1
data/bin/h CHANGED
@@ -6,9 +6,9 @@ h = H::Generator.new
6
6
 
7
7
  result = if ARGV.first
8
8
  if ARGV[1]
9
- h.input ARGV[0], ARGV[1].to_i
9
+ h.input ARGV[0].to_s, ARGV[1].to_i
10
10
  else
11
- h.input ARGV[0]
11
+ h.input ARGV[0].to_s
12
12
  end
13
13
  else
14
14
  h.prompt
data/h.gemspec CHANGED
@@ -1,23 +1,22 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'yaml'
4
-
5
3
  Gem::Specification.new do |s|
6
4
  s.name = 'h'
7
- s.version = YAML.load_file('VERSION.yml').values.join('.')
5
+ s.version = File.read('VERSION.semver')
8
6
  s.platform = Gem::Platform::RUBY
9
7
  s.authors = ['Cyril Wack']
10
8
  s.email = ['contact@cyril.io']
11
9
  s.homepage = 'https://github.com/cyril/h'
12
- s.summary = %q{Custom hash generator}
13
- s.description = %q{A quick tool for those who prefer to put makeup on passwords rather than yield them to Manager}
10
+ s.summary = %q{Salted hashes tool}
11
+ s.description = %q{Small tool that generates salted hashes, scented with the SHA2 function, for those who prefer to put makeup on passwords rather than yield them to Manager™.}
12
+ s.license = 'ISC'
14
13
 
15
14
  s.rubyforge_project = 'h'
16
15
 
17
16
  s.bindir = 'bin'
18
17
  s.executables = ['h']
19
18
 
20
- s.add_dependency 'highline'
19
+ s.add_runtime_dependency 'highline'
21
20
 
22
21
  s.files = `git ls-files`.split("\n")
23
22
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/lib/h.rb CHANGED
@@ -1,33 +1,48 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- Bundler.require
5
-
6
1
  require 'highline/import'
7
2
  require 'digest'
8
- require 'dotenv'
9
- Dotenv.load
10
3
 
11
4
  module H
12
5
  class Generator
6
+ CONF_PATH = File.join(File.expand_path('~'), '.h')
7
+
8
+ def initialize(static_key = nil)
9
+ @static_key = if static_key
10
+ static_key
11
+ else
12
+ unless File.exists?(CONF_PATH)
13
+ print "Creating #{CONF_PATH} file... "
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
+
13
28
  def prompt
14
29
  input ask('Message: ') {|q| q.echo = '*' }
15
30
  end
16
31
 
17
32
  def input(m, l = 44)
18
- m = m + ENV.fetch('STATIC_KEY')
33
+ m = m + @static_key
19
34
  d = cryptographic_hash(m)
20
35
  truncate d, l
21
36
  end
22
37
 
23
38
  protected
24
39
 
25
- def cryptographic_hash(message)
26
- Digest::SHA2.base64digest(message).tr('+/', '-_')
40
+ def cryptographic_hash(m)
41
+ Digest::SHA2.base64digest(m).tr('+/', '-_')
27
42
  end
28
43
 
29
- def truncate(string, length)
30
- string[0, length]
44
+ def truncate(str, lng)
45
+ str[0, lng]
31
46
  end
32
47
  end
33
48
  end
@@ -1,4 +1,2 @@
1
1
  require 'h'
2
2
  require 'minitest/autorun'
3
-
4
- ENV['STATIC_KEY'] = 'secret-key-here'
@@ -1,12 +1,17 @@
1
+ # encoding: utf-8
2
+
1
3
  require_relative '_test_helper'
2
4
 
3
5
  class HTest < MiniTest::Unit::TestCase
4
- def setup
5
- @h = H::Generator.new
6
- end
7
-
8
6
  def test_h
9
- assert_equal @h.input('p@ssw0rd'), 'SdsRrcHHSpJvfhkPM8Np047CocaWRQ2nzPYEw9qWYIo='
10
- assert_equal @h.input('p@ssw0rd', 8), 'SdsRrcHH'
7
+ @h = H::Generator.new('my-salt')
8
+
9
+ assert_equal @h.input('p@ssw0rd'), 'LCoF25LqK6yFMRs6OoQoZEI4GV4-gR7vd1JZtbi8swA='
10
+ assert_equal @h.input('p@ssw0rd', 8), 'LCoF25Lq'
11
+
12
+ @h = H::Generator.new('塩')
13
+
14
+ assert_equal @h.input('シークレット'), '-q0zMnMSszj8D23a8aNJX_VYry9oSSLZ30XlHkmFt9I='
15
+ assert_equal @h.input('シークレット', 3), '-q0'
11
16
  end
12
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: h
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
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-04-24 00:00:00.000000000 Z
11
+ date: 2014-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: A quick tool for those who prefer to put makeup on passwords rather than
28
- yield them to Manager
27
+ description: Small tool that generates salted hashes, scented with the SHA2 function,
28
+ for those who prefer to put makeup on passwords rather than yield them to Manager™.
29
29
  email:
30
30
  - contact@cyril.io
31
31
  executables:
@@ -33,22 +33,22 @@ executables:
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
- - ".env.example"
37
36
  - ".gitignore"
38
37
  - ".ruby-version"
39
38
  - ".travis.yml"
40
39
  - Gemfile
41
- - ISC-LICENSE.md
40
+ - LICENSE.md
42
41
  - README.md
43
42
  - Rakefile
44
- - VERSION.yml
43
+ - VERSION.semver
45
44
  - bin/h
46
45
  - h.gemspec
47
46
  - lib/h.rb
48
47
  - test/_test_helper.rb
49
48
  - test/test_h.rb
50
49
  homepage: https://github.com/cyril/h
51
- licenses: []
50
+ licenses:
51
+ - ISC
52
52
  metadata: {}
53
53
  post_install_message:
54
54
  rdoc_options: []
@@ -69,7 +69,7 @@ rubyforge_project: h
69
69
  rubygems_version: 2.2.2
70
70
  signing_key:
71
71
  specification_version: 4
72
- summary: Custom hash generator
72
+ summary: Salted hashes tool
73
73
  test_files:
74
74
  - test/_test_helper.rb
75
75
  - test/test_h.rb
@@ -1 +0,0 @@
1
- STATIC_KEY=secret
@@ -1,4 +0,0 @@
1
- ---
2
- :major: 2
3
- :minor: 0
4
- :patch: 0