h 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (10) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +13 -0
  4. data/README.textile +79 -0
  5. data/Rakefile +2 -0
  6. data/bin/h +12 -0
  7. data/h.gemspec +21 -0
  8. data/lib/h.rb +49 -0
  9. data/lib/h/version.rb +3 -0
  10. metadata +76 -0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in h.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2011, Cyril Wack <cyril@gosu.fr>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,79 @@
1
+ h1. H
2
+
3
+ h2. Overview
4
+
5
+ Very small cryptographic tool that generates on-the-fly custom message digests,
6
+ according to some parameters.
7
+
8
+ h2. Why?
9
+
10
+ Because I prefer to put makeup on passwords rather than yield them to Managerâ„¢.
11
+
12
+ h2. Installation
13
+
14
+ <pre>
15
+ gem install h
16
+ </pre>
17
+
18
+ h2. Configuration
19
+
20
+ H reads its configuration from the YAML <tt>~/.h</tt> file at initialization.
21
+ This file, which should be readable by its owner only, has four parameters:
22
+
23
+ * Max length: The maximum length of returned message digests.
24
+ * Radix: The number of unique digits that compose message digests.
25
+ * Encryption: A cryptographic hash function in Ruby's Digest module.
26
+ * Static key: Provides salted messages through concatenation.
27
+
28
+ h2. Examples
29
+
30
+ Generate a digest from the system:
31
+
32
+ <pre>
33
+ $ h secret
34
+ t3dpe24xie3y74t
35
+ </pre>
36
+
37
+ Because no configuration has been detected, this default file was created:
38
+
39
+ <pre>
40
+ $ cat ~/.h
41
+ ---
42
+ max_length: 15
43
+ radix: 36
44
+ encryption: SHA1
45
+ static_key: foobar
46
+ </pre>
47
+
48
+ Same operation, from Ruby:
49
+
50
+ <pre>
51
+ irb(main):001:0> require "h"
52
+ true
53
+ irb(main):002:0> H::Generator.new.input "secret"
54
+ "t3dpe24xie3y74t"
55
+ </pre>
56
+
57
+ To prevent your log display the message as a string, do not specify it at first.
58
+
59
+ <pre>
60
+ $ h
61
+ Message: ******
62
+ t3dpe24xie3y74t
63
+ </pre>
64
+
65
+ Example with the SHA2 cryptographic hash instead of SHA1, and a custom key:
66
+
67
+ <pre>
68
+ $ echo "{max_length: 15, radix: 36, encryption: SHA2, static_key: sun}" > ~/.h
69
+ $ h secret
70
+ 5gumh4smv1iit23
71
+ </pre>
72
+
73
+ And now a useless test, with conventional parameters. You can Google the result.
74
+
75
+ <pre>
76
+ $ echo "{max_length: 40, radix: 16, encryption: SHA1, static_key: ''}" > ~/.h
77
+ $ h "The quick brown fox jumps over the lazy dog"
78
+ 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
79
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/h ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require 'h'
5
+
6
+ h = H::Generator.new
7
+
8
+ if ARGV.first.nil?
9
+ puts h.prompt
10
+ else
11
+ puts h.input ARGV.first
12
+ end
data/h.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "h/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "h"
7
+ s.version = H::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Cyril Wack"]
10
+ s.email = ["cyril@gosu.fr"]
11
+ s.homepage = "http://github.com/cyril/h"
12
+ s.summary = %q{Custom hash generator}
13
+ s.description = %q{Very small cryptographic tool that generates custom message digests according to some parameters.}
14
+
15
+ s.rubyforge_project = "h"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
data/lib/h.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'digest'
2
+ require 'highline/import'
3
+ require 'yaml'
4
+
5
+ module H
6
+ class Generator
7
+ CONF_PATH = File.join(File.expand_path('~'), '.h')
8
+
9
+ def initialize
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.freeze
23
+ end
24
+
25
+ def input(message)
26
+ m = message + @params['static_key']
27
+ d = cryptographic_hash(m)
28
+ truncate codage(d)
29
+ end
30
+
31
+ def prompt
32
+ input ask('Message: ') {|q| q.echo = '*' }
33
+ end
34
+
35
+ protected
36
+
37
+ def codage(hexdigest)
38
+ hexdigest.to_i(16).to_s(@params['radix'])
39
+ end
40
+
41
+ def cryptographic_hash(message)
42
+ Digest.class_eval(@params['encryption']).hexdigest(message)
43
+ end
44
+
45
+ def truncate(string)
46
+ string[0, @params['max_length']]
47
+ end
48
+ end
49
+ end
data/lib/h/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module H
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: h
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Cyril Wack
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-08 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Very small cryptographic tool that generates custom message digests according to some parameters.
23
+ email:
24
+ - cyril@gosu.fr
25
+ executables:
26
+ - h
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.textile
36
+ - Rakefile
37
+ - bin/h
38
+ - h.gemspec
39
+ - lib/h.rb
40
+ - lib/h/version.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/cyril/h
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: h
71
+ rubygems_version: 1.5.0
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Custom hash generator
75
+ test_files: []
76
+