to_pass 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -19,7 +19,7 @@ to_pass is distributed as rubygem
19
19
  If you want to install from source, you can download a tarball or zipfile from
20
20
  github.
21
21
 
22
- $ curl -L http://github.com/kronn/to_pass/tarball/v0.7.0 -o to_pass.tar.gz
22
+ $ curl -L https://github.com/kronn/to_pass/tarball/v0.9.0 -o to_pass.tar.gz
23
23
  $ tar -xzf to_pass.tar.gz
24
24
  $ cd kronn-to_pass-HASHVALUE
25
25
  $ ./setup.rb install
@@ -50,6 +50,8 @@ A more direct approach is the facade provided by ToPass::Base
50
50
  irb> require 'to_pass'
51
51
  irb> ToPass::Base.new('test', :basic_de).to_s
52
52
  # => 't35t'
53
+ irb> ToPass::Base.new('test', :basic_de).password
54
+ # => 't35t'
53
55
 
54
56
  === CLI
55
57
 
@@ -62,6 +64,27 @@ This example is a bit Mac OSX-centric, but you should get the point.
62
64
 
63
65
  $ echo "test" | to_pass | pbcopy
64
66
 
67
+ === Customizing
68
+
69
+ In order to fully utilize to_pass, you need to make your own algorithm.
70
+
71
+ You can get a list of existing algorithms through the CLI:
72
+
73
+ $ to_pass --algorithms # or: to_pass -A
74
+
75
+ Likewise, you can get a list of existing converters:
76
+
77
+ $ to_pass --converters # or: to_pass -C
78
+
79
+ === Configuration
80
+
81
+ You can customize the default behaviour by adding a configuration file like this
82
+
83
+ $ mkdir ~/.to_pass
84
+ $ echo 'algorithm: basic_de' >> ~/.to_pass/config
85
+ $ echo 'pipe_out: false' >> ~/.to_pass/config
86
+ $ echo 'pipe_in: false' >> ~/.to_pass/config
87
+
65
88
  == Development
66
89
 
67
90
  If you want to develop it further, patch something or are just plain curious:
@@ -110,4 +133,4 @@ And of course, there is a README, but I think you have found it already...
110
133
 
111
134
  == Copyright
112
135
 
113
- Copyright (c) 2009-2010 Matthias Viehweger. See doc/LICENSE for details.
136
+ Copyright (c) 2009-2011 Matthias Viehweger. See doc/LICENSE for details.
data/TODO CHANGED
@@ -3,21 +3,23 @@ CURRENT
3
3
  ✔ let tests run separated
4
4
  - Improve CLI-Code
5
5
  ✔ rescue OptionParser::InvalidOption with help screen
6
- - add ability to execute commands == handle CLI with Thor ?
7
- - add command to generate configuration path
8
- - add command to output available converters
9
- - add command to output available algorithms
6
+ add ability to execute commands == handle CLI with Thor ?
7
+ => done with switches to avoid having a transform command
8
+ add command to output available converters
9
+ add command to output available algorithms
10
10
  - add option '-c, --config PATH - Configuration Path (default is ~/.to_pass)'
11
+ - add command to generate configuration path
12
+ ✔ make default algorithm configurable in .to_passrc [kronn/to_pass GH-1]
11
13
 
12
14
 
13
15
  UP NEXT
14
16
  ============================================================================
15
17
  - make secure algorithm default
16
- - make default algorithm configurable in .to_passrc [kronn/to_pass GH-1]
17
18
  - make tests faster
18
19
  - integrate better with YARD
19
20
  - add the TODO file, the doc/ directory
20
21
  - also show protected and private methods because I want to have a complete documentation
22
+ - make ConverterReader a better child of FileReader
21
23
 
22
24
 
23
25
  SOMEDAY
@@ -26,6 +28,7 @@ SOMEDAY
26
28
  move decision wether a string is a word or a sentence into algorithm definition.
27
29
  add task to validate user supplied algorithms and converters
28
30
  check out and maybe integrate https://github.com/stephencelis/rdoctest
31
+ i18n && l10n of messages
29
32
  ?? replace Rake with Thor
30
33
 
31
34
 
@@ -0,0 +1,5 @@
1
+ algorithm: basic_de
2
+ pipe_out: false
3
+ pipe_in: false
4
+
5
+ # vim:ft=yaml
data/lib/to_pass.rb CHANGED
@@ -14,6 +14,8 @@ module ToPass
14
14
  autoload :DATE, 'to_pass/version'
15
15
  autoload :APP_NAME, 'to_pass/version'
16
16
 
17
+ autoload :FileReader, 'to_pass/file_reader'
18
+ autoload :ConfigReader, 'to_pass/config_reader'
17
19
  autoload :AlgorithmReader, 'to_pass/algorithm_reader'
18
20
  autoload :Base, 'to_pass/base'
19
21
  autoload :Cli, 'to_pass/cli.rb'
@@ -1,6 +1,5 @@
1
1
  # vim:ft=ruby:fileencoding=utf-8
2
2
 
3
- require 'pathname'
4
3
  require 'yaml'
5
4
 
6
5
  module ToPass
@@ -11,50 +10,23 @@ module ToPass
11
10
  # and managed in ToPass::Directories
12
11
  #
13
12
  # see ToPass::Converter for usage of the loaded algorithm
14
- class AlgorithmReader
15
- attr_reader :load_path
16
-
13
+ class AlgorithmReader < FileReader
17
14
  def initialize(algorithm) # :nodoc:
18
- @algorithm = algorithm
19
- @load_path = []
20
- ToPass::Directories[:standard].map do |dir|
21
- dir + '/algorithms'
22
- end.each do |dir|
23
- dir = Pathname.new(dir).expand_path
24
- @load_path << dir if dir.exist?
25
- end
15
+ super(algorithm, 'algorithms')
26
16
  end
27
17
 
28
18
  class << self
29
- # load an algorithm with a given identifier
30
- def load(algorithm)
31
- new(algorithm).load_from_file
32
- end
33
-
34
- # searches for available algorithms
35
- def discover
36
- new(nil).load_path.collect do |dir|
37
- Dir["#{dir}/*.yml"]
38
- end.flatten.compact.map do |fn|
39
- File.basename(fn).gsub('.yml', '')
40
- end
19
+ def extension # :nodoc:
20
+ 'yml'
41
21
  end
42
22
  end
43
23
 
44
24
  def load_from_file # :nodoc:
45
- fn = load_path.map do |dir|
46
- file = Pathname.new("#{dir}/#{@algorithm}.yml")
47
-
48
- if file.exist?
49
- file
50
- else
51
- next
52
- end
53
- end.compact.first
54
-
55
- raise LoadError, "algorithm #{@algorithm} could not be found in #{load_path}" if fn.nil?
25
+ fn = super
56
26
 
57
27
  YAML.load_file(fn.expand_path)
28
+ rescue LoadError
29
+ raise LoadError, "algorithm #{@file} could not be found in #{load_path}" if fn.nil?
58
30
  end
59
31
  end
60
32
  end
data/lib/to_pass/base.rb CHANGED
@@ -5,20 +5,23 @@ module ToPass
5
5
  #
6
6
  # Given a string and a algorithm identifier, the right rules
7
7
  # are loaded and applied to the string. With a simple "to_s",
8
- # you can get the final password.
8
+ # you can get the final password. The password is also readable
9
+ # directly through ToPass::Base#password.
9
10
  #
10
11
  # see ToPass::AlgorithmReader and ToPass::Converter for details
11
12
  class Base
13
+ attr_reader :password
14
+
12
15
  # transform a string according to a certain algorithm
13
- def initialize( string, algorithm )
16
+ def initialize(string, algorithm)
14
17
  rules = AlgorithmReader.load(algorithm)
15
- converter = Converter.new( rules )
18
+ converter = Converter.new(rules)
16
19
  @password = converter.convert(string)
17
20
  end
18
21
 
19
22
  # return the generated password
20
23
  def to_s
21
- @password
24
+ password
22
25
  end
23
26
  end
24
27
  end
data/lib/to_pass/cli.rb CHANGED
@@ -19,6 +19,13 @@ module ToPass
19
19
  # :pipe_in => false
20
20
  # }
21
21
  #
22
+ # If you want to override always, you can create a config file with the
23
+ # following name:
24
+ #
25
+ # ~/.to_pass/config
26
+ #
27
+ # The file is expected to be a YAML-File. Keys and values are transformed
28
+ # symbols automatically. See ToPass::ConfigReader for details.
22
29
  def initialize(options = {})
23
30
  @options = parse_options(options)
24
31
  @string = get_input_string
@@ -34,6 +41,32 @@ module ToPass
34
41
  end
35
42
  end
36
43
 
44
+ class << self
45
+ # output list of algorithms
46
+ def algorithms
47
+ puts ""
48
+ puts " available password algorithms"
49
+ puts " ============================================"
50
+ AlgorithmReader.discover.each do |algorithm|
51
+ puts " - #{algorithm}"
52
+ end
53
+ puts " ============================================"
54
+ puts ""
55
+ end
56
+
57
+ # output list of converters
58
+ def converters
59
+ puts ""
60
+ puts " available converters for password algorithms"
61
+ puts " ============================================"
62
+ ConverterReader.new.discover.each do |converter|
63
+ puts " - #{converter}"
64
+ end
65
+ puts " ============================================"
66
+ puts ""
67
+ end
68
+ end
69
+
37
70
  protected
38
71
 
39
72
  # parse the options
@@ -42,7 +75,9 @@ module ToPass
42
75
  :algorithm => 'basic_de',
43
76
  :pipe_out => false,
44
77
  :pipe_in => false
45
- }.merge(options)
78
+ }.merge(
79
+ ConfigReader.load
80
+ ).merge(options)
46
81
 
47
82
  cli_options = OptionParser.new do |opts|
48
83
  opts.banner = "Usage: #{File.basename($0)} [options] passphrase"
@@ -56,6 +91,34 @@ module ToPass
56
91
  options[:pipe_out] = value
57
92
  end
58
93
 
94
+ ## ACTIONS
95
+
96
+ # not used at the moment
97
+ #
98
+ # opts.on('-c', '--config [PATH]', "look in PATH for configurations (instead of ~/.to_pass)") do |value|
99
+ # if File.exist?(value)
100
+ # options[:path] = value
101
+ # else
102
+ # puts 'configuration path not found'
103
+ # puts "run '#{File.basename($0)} --setup --config #{value}' to set it up"
104
+ # exit 1
105
+ # end
106
+ # end
107
+ #
108
+ # opts.on('--setup', "create a configuration directory") do |value|
109
+ # options[:setup] == true
110
+ # end
111
+
112
+ opts.on('-A', '--algorithms', "list available algorithms") do |value|
113
+ Cli.algorithms
114
+ exit
115
+ end
116
+
117
+ opts.on('-C', '--converters', "list available converters for password algorithms") do |value|
118
+ Cli.converters
119
+ exit
120
+ end
121
+
59
122
  opts.separator ""
60
123
 
61
124
  opts.on_tail("-h", "--help", "Show this message") do
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ module ToPass
4
+ # The ConfigReader reads the given file from a YAML-file
5
+ # into a Hash. All Strings in the Hash are converted into
6
+ # symbols.
7
+ #
8
+ # Search locations are managed in ToPass::Directories
9
+ class ConfigReader < FileReader
10
+ def initialize(fn='config',dir=nil) # :nodoc:
11
+ super
12
+ end
13
+
14
+ # as the ConfigReader is only intended to read the configuration
15
+ # file, the name is fixed here.
16
+ def self.load(fn = 'config')
17
+ super
18
+ end
19
+
20
+ def load_from_file
21
+ fn = super
22
+ config = {}
23
+
24
+ YAML.load_file(fn).each_pair do |key, value|
25
+ config[key.to_sym] = value.kind_of?(String) ? value.to_sym : value
26
+ end
27
+
28
+ config
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,5 @@
1
1
  # vim:ft=ruby:fileencoding=utf-8
2
2
 
3
- require 'pathname'
4
-
5
3
  module ToPass
6
4
  # The ConverterReader's primary API is to load the converters from right
7
5
  # directories into an Array
@@ -13,19 +11,13 @@ module ToPass
13
11
  # User-provided converters are always required (for now).
14
12
  #
15
13
  # see ToPass::Converter
16
- class ConverterReader
17
- attr_reader :load_path, :loaded
14
+ class ConverterReader < FileReader
15
+ attr_reader :loaded
18
16
 
19
17
  def initialize # :nodoc:
20
- @load_path = []
21
18
  @loaded = []
22
19
  @discovered = []
23
- ToPass::Directories[:standard].map do |dir|
24
- dir + '/converters'
25
- end.each do |dir|
26
- dir = Pathname.new(dir).expand_path
27
- @load_path << dir if dir.exist?
28
- end
20
+ super(nil, 'converters')
29
21
  end
30
22
 
31
23
  # loads the converters
@@ -0,0 +1,80 @@
1
+ # vim:fileencoding=utf-8
2
+ # require 'pathname'
3
+ # require 'yaml'
4
+
5
+ require 'pathname'
6
+
7
+ module ToPass
8
+ # a generic Filereader, abstracting (among others) ToPass::AlgorithmReader
9
+ # and ToPass::ConverterReader.
10
+ #
11
+ # Files are searched in a list of standard directories. Those are defined
12
+ # and managed in ToPass::Directories
13
+ class FileReader
14
+ attr_reader :load_path
15
+
16
+ def initialize(file = nil, dir_suffix = nil) # :nodoc:
17
+ @file = file
18
+ @load_path = []
19
+
20
+ @load_path.concat(standard_directories(dir_suffix))
21
+ end
22
+
23
+ class << self
24
+ # load a file with a given identifier
25
+ def load(fn)
26
+ new(fn).load_from_file
27
+ end
28
+
29
+ # searches for available algorithms
30
+ def discover
31
+ extension = ".#{extension}" if extension
32
+
33
+ new(nil).load_path.collect do |dir|
34
+ Dir["#{dir}/#{search_pattern}#{extension}"]
35
+ end.flatten.compact.map do |fn|
36
+ File.basename(fn).gsub('#{extension}', '')
37
+ end
38
+ end
39
+
40
+ def search_pattern
41
+ '*'
42
+ end
43
+
44
+ def extension
45
+ nil
46
+ end
47
+ end
48
+
49
+ def load_from_file # :nodoc:
50
+ fn = load_path.map do |dir|
51
+ extension = ".#{self.class.extension}" if self.class.extension
52
+ file = Pathname.new("#{dir}/#{@file}#{extension}")
53
+
54
+ if file.exist?
55
+ file
56
+ else
57
+ next
58
+ end
59
+ end.compact.first
60
+
61
+ raise LoadError, "file #{@file} could not be found in #{load_path}" if fn.nil?
62
+
63
+ fn
64
+ end
65
+
66
+ private
67
+
68
+ def standard_directories(suffix = nil)
69
+ suffix = suffix.to_s
70
+ suffix = "/#{suffix}" unless suffix =~ /^\//
71
+
72
+ ToPass::Directories[:standard].map do |dir|
73
+ dir + suffix
74
+ end.map do |dir|
75
+ dir = Pathname.new(dir).expand_path
76
+ dir if dir.exist?
77
+ end.compact
78
+ end
79
+ end
80
+ end
@@ -3,7 +3,7 @@
3
3
  unless defined?(ToPass::VERSION)
4
4
  module ToPass
5
5
  # version of gem
6
- VERSION = '0.8.0'
6
+ VERSION = '0.9.0'
7
7
 
8
8
  # name of gem
9
9
  APP_NAME = 'to_pass'
data/man/man1/to_pass.1 CHANGED
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "TO_PASS" "1" "August 2010" "" ""
4
+ .TH "TO_PASS" "1" "December 2010" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBto_pass\fR \- transform a string to a password
@@ -10,28 +10,31 @@
10
10
  \fBto_pass\fR [\-a ALG | \-\-algorithm ALG] [\-\-pipe | \-\-no\-pipe] string
11
11
  .
12
12
  .br
13
- \fBto_pass\fR [\-a ALG | \-\-algorithm ALG] [\-\-pipe | \-\-no\-pipe] < <file>
13
+ \fBto_pass\fR [\-a ALG | \-\-algorithm ALG] [\-\-pipe | \-\-no\-pipe] < FILE
14
14
  .
15
15
  .br
16
- \fBpassword_of\fR [\-a ALG | \-\-algorithm ALG] [\-\-pipe | \-\-no\-pipe] string
16
+ \fBto_pass\fR [\-A|\-\-algorithms]
17
17
  .
18
18
  .br
19
- \fBpassword_of\fR [\-a ALG | \-\-algorithm ALG] [\-\-pipe | \-\-no\-pipe] < <file>
19
+ \fBto_pass\fR [\-C|\-\-converters]
20
+ .
21
+ .P
22
+ \fBpassword_of\fR is an alias of \fBto_pass\fR
20
23
  .
21
24
  .SH "DESCRIPTION"
22
25
  \fBto_pass\fR converts a string (be it a word, a sentence or a whole book) into a password\. The transformation is done according to a algorithm which basically is a list of conversion steps\.
23
26
  .
24
27
  .P
25
- Some algorithms and conversions are supplied, but you can easily add your own\. User supplied Algorithms are searched in \fB~/\.to_pass/algorithms/\fR, converter classes are searched in \fB~/\.to_pass/converters/\fR\.
28
+ Some algorithms and conversions are supplied, but you can easily add your own\. User supplied algorithms are searched in \fB~/\.to_pass/algorithms/\fR, converter classes are searched in \fB~/\.to_pass/converters/\fR\.
26
29
  .
27
30
  .P
28
31
  to_pass\-algorithm(5) files are written in yaml(3pm), to_pass\-converter(5) classes are ruby(1) classes\.
29
32
  .
30
33
  .SH "FILES"
31
- The \fBto_pass\fR command can reads both algorithms and converters\.
34
+ The \fBto_pass\fR command can read both algorithms and converters\.
32
35
  .
33
36
  .P
34
- Algorithm names should match the filenames so that the library can find and load them\. Search locations are the user\-directory ~/\.to_pass/algorithm/ and the bundled algorithms\. The file is expected to have a "\.yml"\-extension
37
+ Algorithm names should match the filenames so that the library can find and load them\. Search locations are the user\-directory ~/\.to_pass/algorithm/ and the bundled algorithms\. The file is expected to have a "\.yml"\-extension\. Details can be found in to_pass\-algorithm(5)\.
35
38
  .
36
39
  .P
37
40
  Converters should be named like the method they provide\. Details about the expected class can be found in to_pass\-converter(5)\.
@@ -47,6 +50,21 @@ Use the named algorithm\.
47
50
  \fB\-\-pipe\fR
48
51
  Output just the resulting string, without a line\-ending\.
49
52
  .
53
+ .SS "ACTIONS"
54
+ Further, the following switches trigger an action other than converting a string to a password
55
+ .
56
+ .TP
57
+ \fB\-A\fR, \fB\-\-algorithms\fR
58
+ list all available algorithms
59
+ .
60
+ .TP
61
+ \fB\-C\fR, \fB\-\-converters\fR
62
+ list all converters which can be used for algorithms
63
+ .
64
+ .TP
65
+ \fB\-h\fR, \fB\-\-help\fR
66
+ show usage information
67
+ .
50
68
  .SH "EXAMPLES"
51
69
  Transform the word "test" into a password:
52
70
  .
@@ -76,10 +94,10 @@ ti1pwtsi2ltti@pf
76
94
  .IP "" 0
77
95
  .
78
96
  .SH "BUGS"
79
- So far, no bugs are known\.
97
+ So far, no bugs are known\. If you encounter any, please file a bugreport under https://github\.com/kronn/to_pass/issues
80
98
  .
81
99
  .SH "COPYRIGHT"
82
- ToPass is Copyright (C) 2010 Matthias Viehweger
100
+ ToPass is Copyright (C) 2010 Matthias Viehweger\. It is open sourced under a MIT\-license\.
83
101
  .
84
102
  .SH "SEE ALSO"
85
103
  to_pass\-converter(5), to_pass\-algorithm(5)
@@ -68,7 +68,7 @@
68
68
  <a href="#BUGS">BUGS</a>
69
69
  <a href="#COPYRIGHT">COPYRIGHT</a>
70
70
  <a href="#SEE-ALSO">SEE ALSO</a>
71
- </div>
71
+ </div>
72
72
 
73
73
  <ol class='man-decor man-head man head'>
74
74
  <li class='tl'>to_pass(1)</li>
@@ -84,9 +84,11 @@
84
84
  <h2 id="SYNOPSIS">SYNOPSIS</h2>
85
85
 
86
86
  <p><code>to_pass</code> [-a ALG | --algorithm ALG] [--pipe | --no-pipe] string<br />
87
- <code>to_pass</code> [-a ALG | --algorithm ALG] [--pipe | --no-pipe] &lt; &lt;file&gt;<br />
88
- <code>password_of</code> [-a ALG | --algorithm ALG] [--pipe | --no-pipe] string<br />
89
- <code>password_of</code> [-a ALG | --algorithm ALG] [--pipe | --no-pipe] &lt; &lt;file&gt;</p>
87
+ <code>to_pass</code> [-a ALG | --algorithm ALG] [--pipe | --no-pipe] &lt; FILE<br />
88
+ <code>to_pass</code> [-A|--algorithms]<br />
89
+ <code>to_pass</code> [-C|--converters]</p>
90
+
91
+ <p><code>password_of</code> is an alias of <code>to_pass</code></p>
90
92
 
91
93
  <h2 id="DESCRIPTION">DESCRIPTION</h2>
92
94
 
@@ -95,7 +97,7 @@ password. The transformation is done according to a algorithm which basically is
95
97
  a list of conversion steps.</p>
96
98
 
97
99
  <p>Some algorithms and conversions are supplied, but you can easily add your own.
98
- User supplied Algorithms are searched in <code>~/.to_pass/algorithms/</code>, converter
100
+ User supplied algorithms are searched in <code>~/.to_pass/algorithms/</code>, converter
99
101
  classes are searched in <code>~/.to_pass/converters/</code>.</p>
100
102
 
101
103
  <p><a href="../man5/to_pass-algorithm.5.html" class="man-ref">to_pass-algorithm<span class="s">(5)</span></a> files are written in <a href="http://man.cx/yaml(3pm)" class="man-ref">yaml<span class="s">(3pm)</span></a>, <a href="../man5/to_pass-converter.5.html" class="man-ref">to_pass-converter<span class="s">(5)</span></a> classes are
@@ -103,11 +105,12 @@ classes are searched in <code>~/.to_pass/converters/</code>.</p>
103
105
 
104
106
  <h2 id="FILES">FILES</h2>
105
107
 
106
- <p>The <code>to_pass</code> command can reads both algorithms and converters.</p>
108
+ <p>The <code>to_pass</code> command can read both algorithms and converters.</p>
107
109
 
108
110
  <p>Algorithm names should match the filenames so that the library can find and
109
111
  load them. Search locations are the user-directory ~/.to_pass/algorithm/ and
110
- the bundled algorithms. The file is expected to have a ".yml"-extension</p>
112
+ the bundled algorithms. The file is expected to have a ".yml"-extension.
113
+ Details can be found in <a href="../man5/to_pass-algorithm.5.html" class="man-ref">to_pass-algorithm<span class="s">(5)</span></a>.</p>
111
114
 
112
115
  <p>Converters should be named like the method they provide. Details about the
113
116
  expected class can be found in <a href="../man5/to_pass-converter.5.html" class="man-ref">to_pass-converter<span class="s">(5)</span></a>.</p>
@@ -122,6 +125,18 @@ expected class can be found in <a href="../man5/to_pass-converter.5.html" class=
122
125
  </dl>
123
126
 
124
127
 
128
+ <h3 id="ACTIONS">ACTIONS</h3>
129
+
130
+ <p>Further, the following switches trigger an action other than converting a
131
+ string to a password</p>
132
+
133
+ <dl>
134
+ <dt><code>-A</code>, <code>--algorithms</code></dt><dd><p>list all available algorithms</p></dd>
135
+ <dt><code>-C</code>, <code>--converters</code></dt><dd><p>list all converters which can be used for algorithms</p></dd>
136
+ <dt><code>-h</code>, <code>--help</code></dt><dd><p>show usage information</p></dd>
137
+ </dl>
138
+
139
+
125
140
  <h2 id="EXAMPLES">EXAMPLES</h2>
126
141
 
127
142
  <p>Transform the word "test" into a password:</p>
@@ -138,11 +153,12 @@ ti1pwtsi2ltti@pf
138
153
 
139
154
  <h2 id="BUGS">BUGS</h2>
140
155
 
141
- <p>So far, no bugs are known.</p>
156
+ <p>So far, no bugs are known. If you encounter any, please file a bugreport under
157
+ https://github.com/kronn/to_pass/issues</p>
142
158
 
143
159
  <h2 id="COPYRIGHT">COPYRIGHT</h2>
144
160
 
145
- <p>ToPass is Copyright (C) 2010 Matthias Viehweger</p>
161
+ <p>ToPass is Copyright (C) 2010 Matthias Viehweger. It is open sourced under a MIT-license.</p>
146
162
 
147
163
  <h2 id="SEE-ALSO">SEE ALSO</h2>
148
164
 
@@ -151,7 +167,7 @@ ti1pwtsi2ltti@pf
151
167
 
152
168
  <ol class='man-decor man-foot man foot'>
153
169
  <li class='tl'></li>
154
- <li class='tc'>August 2010</li>
170
+ <li class='tc'>December 2010</li>
155
171
  <li class='tr'>to_pass(1)</li>
156
172
  </ol>
157
173
 
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "TO_PASS\-ALGORITHM" "5" "August 2010" "" ""
4
+ .TH "TO_PASS\-ALGORITHM" "5" "November 2010" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBto_pass\-algorithm\fR \- algorithm\-description for to_pass(1)
@@ -65,7 +65,7 @@
65
65
  <a href="#CAVEATS">CAVEATS</a>
66
66
  <a href="#AUTHOR">AUTHOR</a>
67
67
  <a href="#SEE-ALSO">SEE ALSO</a>
68
- </div>
68
+ </div>
69
69
 
70
70
  <ol class='man-decor man-head man head'>
71
71
  <li class='tl'>to_pass-algorithm(5)</li>
@@ -176,7 +176,7 @@ design however is intentionally simple and constrained.</p>
176
176
 
177
177
  <ol class='man-decor man-foot man foot'>
178
178
  <li class='tl'></li>
179
- <li class='tc'>August 2010</li>
179
+ <li class='tc'>November 2010</li>
180
180
  <li class='tr'>to_pass-algorithm(5)</li>
181
181
  </ol>
182
182
 
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "TO_PASS\-CONVERTER" "5" "August 2010" "" ""
4
+ .TH "TO_PASS\-CONVERTER" "5" "November 2010" "" ""
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBto_pass\-converter\fR \- converter\-class for to_pass(1)
@@ -65,7 +65,7 @@
65
65
  <a href="#CAVEATS">CAVEATS</a>
66
66
  <a href="#AUTHOR">AUTHOR</a>
67
67
  <a href="#SEE-ALSO">SEE ALSO</a>
68
- </div>
68
+ </div>
69
69
 
70
70
  <ol class='man-decor man-head man head'>
71
71
  <li class='tl'>to_pass-converter(5)</li>
@@ -155,7 +155,7 @@ end
155
155
 
156
156
  <ol class='man-decor man-foot man foot'>
157
157
  <li class='tl'></li>
158
- <li class='tc'>August 2010</li>
158
+ <li class='tc'>November 2010</li>
159
159
  <li class='tr'>to_pass-converter(5)</li>
160
160
  </ol>
161
161
 
data/man/to_pass.1.ronn CHANGED
@@ -4,9 +4,11 @@ to_pass(1) -- transform a string to a password
4
4
  ## SYNOPSIS
5
5
 
6
6
  `to_pass` [-a ALG | --algorithm ALG] [--pipe | --no-pipe] string<br>
7
- `to_pass` [-a ALG | --algorithm ALG] [--pipe | --no-pipe] &lt; &lt;file&gt;<br>
8
- `password_of` [-a ALG | --algorithm ALG] [--pipe | --no-pipe] string<br>
9
- `password_of` [-a ALG | --algorithm ALG] [--pipe | --no-pipe] &lt; &lt;file&gt;
7
+ `to_pass` [-a ALG | --algorithm ALG] [--pipe | --no-pipe] &lt; FILE<br>
8
+ `to_pass` [-A|--algorithms]<br>
9
+ `to_pass` [-C|--converters]
10
+
11
+ `password_of` is an alias of `to_pass`
10
12
 
11
13
  ## DESCRIPTION
12
14
 
@@ -15,7 +17,7 @@ password. The transformation is done according to a algorithm which basically is
15
17
  a list of conversion steps.
16
18
 
17
19
  Some algorithms and conversions are supplied, but you can easily add your own.
18
- User supplied Algorithms are searched in `~/.to_pass/algorithms/`, converter
20
+ User supplied algorithms are searched in `~/.to_pass/algorithms/`, converter
19
21
  classes are searched in `~/.to_pass/converters/`.
20
22
 
21
23
  to_pass-algorithm(5) files are written in yaml(3pm), to_pass-converter(5) classes are
@@ -23,11 +25,12 @@ ruby(1) classes.
23
25
 
24
26
  ## FILES
25
27
 
26
- The `to_pass` command can reads both algorithms and converters.
28
+ The `to_pass` command can read both algorithms and converters.
27
29
 
28
30
  Algorithm names should match the filenames so that the library can find and
29
31
  load them. Search locations are the user-directory ~/.to_pass/algorithm/ and
30
- the bundled algorithms. The file is expected to have a ".yml"-extension
32
+ the bundled algorithms. The file is expected to have a ".yml"-extension.
33
+ Details can be found in to_pass-algorithm(5).
31
34
 
32
35
  Converters should be named like the method they provide. Details about the
33
36
  expected class can be found in to_pass-converter(5).
@@ -44,6 +47,21 @@ The following options are supported:
44
47
  Output just the resulting string, without a line-ending.
45
48
 
46
49
 
50
+ ### ACTIONS
51
+
52
+ Further, the following switches trigger an action other than converting a
53
+ string to a password
54
+
55
+ * `-A`, `--algorithms`:
56
+ list all available algorithms
57
+
58
+ * `-C`, `--converters`:
59
+ list all converters which can be used for algorithms
60
+
61
+ * `-h`, `--help`:
62
+ show usage information
63
+
64
+
47
65
  ## EXAMPLES
48
66
 
49
67
  Transform the word "test" into a password:
@@ -58,11 +76,12 @@ Transform a phrase into a password using a different algorithm:
58
76
 
59
77
  ## BUGS
60
78
 
61
- So far, no bugs are known.
79
+ So far, no bugs are known. If you encounter any, please file a bugreport under
80
+ https://github.com/kronn/to_pass/issues
62
81
 
63
82
  ## COPYRIGHT
64
83
 
65
- ToPass is Copyright (C) 2010 Matthias Viehweger
84
+ ToPass is Copyright (C) 2010 Matthias Viehweger. It is open sourced under a MIT-license.
66
85
 
67
86
  ## SEE ALSO
68
87
 
data/test/test_base.rb CHANGED
@@ -62,4 +62,11 @@ class TestBase < Test::Unit::TestCase
62
62
  assert_nil ToPass::RELEASE_NOTES
63
63
  end
64
64
  end
65
+
66
+ # def test_uses_to_passrc_for_configuration
67
+ # assert_nothing_raised do
68
+ # # make default algorithm configurable in .to_passrc [kronn/to_pass GH-1]
69
+ # fail 'this needs to be implemeted'
70
+ # end
71
+ # end
65
72
  end
data/test/test_cli.rb CHANGED
@@ -73,6 +73,51 @@ class TestCli < Test::Unit::TestCase
73
73
  assert_match /Show this message/, result, 'should contain hint for help'
74
74
  end
75
75
 
76
+
77
+ # def test_configuration_path_is_configurable
78
+ # [
79
+ # `#{binpath}to_pass test -c /tmp/my_to_pass`,
80
+ # `#{binpath}to_pass test --config /tmp/my_to_pass`
81
+ # ].each do |result|
82
+ # assert_match /configuration path not found/, result, 'should output an errormessage'
83
+ # assert_match %r!to_pass --setup --config /tmp/my_to_pass!, result, 'should provide a hint how to fix it'
84
+ # end
85
+ # end
86
+
87
+ # def test_cli_has_setup_command
88
+ # result = `#{binpath}to_pass --setup 2>&1`
89
+ #
90
+ # assert path_not_present
91
+ # assert_match /successfully created configuration paths/i, result, 'should print success message'
92
+ # assert path_present
93
+ # end
94
+
95
+ def test_cli_can_output_algorithms
96
+ algorithms = %w(basic_de basic_en secure)
97
+ [
98
+ `#{binpath}to_pass -A`,
99
+ `#{binpath}to_pass --algorithms`
100
+ ].each do |result|
101
+ assert_match /available password algorithms/, result
102
+ algorithms.each do |algorithm|
103
+ assert_match /#{algorithm}/, result
104
+ end
105
+ end
106
+ end
107
+
108
+ def test_cli_can_output_converters
109
+ converters = %w(collapse_chars downcase expand_below first_chars remove_repetition replace reverse swapcase)
110
+ [
111
+ `#{binpath}to_pass -C`,
112
+ `#{binpath}to_pass --converters`
113
+ ].each do |result|
114
+ assert_match /available converters for password algorithms/, result
115
+ converters.each do |converter|
116
+ assert_match /#{converter}/, result
117
+ end
118
+ end
119
+ end
120
+
76
121
  protected
77
122
 
78
123
  def binpath
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../helper', __FILE__)
2
+
3
+ class TestConfigReader < Test::Unit::TestCase
4
+ test_presence ToPass::ConfigReader
5
+
6
+ def test_config_reader_is_a_file_reader
7
+ assert_kind_of ToPass::FileReader, instance
8
+ end
9
+
10
+ def test_can_load_config_file
11
+ assert_not_nil klass.load
12
+ assert_kind_of Hash, klass.load
13
+ end
14
+
15
+ protected
16
+
17
+ def klass
18
+ ToPass::ConfigReader
19
+ end
20
+ def instance
21
+ klass.new
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ # vim:ft=ruby:fileencoding=utf-8
2
+
3
+ require File.expand_path('../helper', __FILE__)
4
+
5
+ class TestConfigs < Test::Unit::TestCase
6
+ def config
7
+ ToPass::ConfigReader.load('config')
8
+ end
9
+
10
+ def test_default_algorithm_is_basic_de
11
+ result = config[:algorithm]
12
+
13
+ assert_not_nil result, 'the algorithm should be configured by default'
14
+ assert_equal :basic_de, result
15
+ end
16
+ def test_default_pipe_out_behaviour_is_false
17
+ result = config[:pipe_out]
18
+
19
+ assert_not_nil result
20
+ assert_equal false, result
21
+ end
22
+ def test_default_pipe_in_behaviour_is_false
23
+ result = config[:pipe_in]
24
+
25
+ assert_not_nil result
26
+ assert_equal false, result
27
+ end
28
+
29
+ end
@@ -22,6 +22,7 @@ class TestConverter < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  # mock-tests to ensure presence and calling of protected methods
25
+ # the result-testing is done in test/test_converters.rb
25
26
  def test_replace
26
27
  assert_respond_to converter, :replace
27
28
  converter.expects(:apply_rule).with("test", {'replace'=>'special'}).once
@@ -47,7 +48,6 @@ class TestConverter < Test::Unit::TestCase
47
48
  converter.convert("test test")
48
49
  end
49
50
 
50
-
51
51
  # more complex/real-life setups
52
52
  def test_multiple_rules
53
53
  converter(basic_rules.merge({
@@ -67,34 +67,6 @@ class TestConverter < Test::Unit::TestCase
67
67
  Pferd auf dem Flur"))
68
68
  end
69
69
 
70
-
71
- # actual result-testing
72
- def test_replacement
73
- rules = {
74
- 'replacements' => {
75
- 'numbers' => {
76
- :e => 3,
77
- :s => 5
78
- }
79
- }
80
- }
81
- result = converter(rules).send(:apply_rule, "test", {'replace'=>'numbers'})
82
- assert_equal "t35t", result
83
- end
84
- def test_case_swapping
85
- assert_equal "tEsT", converter.send(:apply_rule, "test", 'swapcase')
86
- end
87
- def test_case_swapping_ignores_numbers
88
- assert_equal "tEsT4fUn", converter.send(:apply_rule, "test4fun", 'swapcase')
89
- assert_equal "fUn4TeSt", converter.send(:apply_rule, "fun4test", 'swapcase')
90
- end
91
- def test_char_collapsing
92
- assert_equal "abc", converter.send(:apply_rule, "a b c", 'collapse_chars')
93
- end
94
- def test_select_first_chars
95
- assert_equal "t a t f t", converter.send(:apply_rule, "test all the fucking time", 'first_chars')
96
- end
97
-
98
70
  protected
99
71
 
100
72
  def converter(rules = basic_rules)
@@ -26,16 +26,41 @@ class TestConverters < Test::Unit::TestCase
26
26
  assert_converter 'tset', 'reverse', 'test'
27
27
  end
28
28
 
29
+ def test_replacement
30
+ rules = {
31
+ 'replacements' => {
32
+ 'numbers' => {
33
+ :e => 3,
34
+ :s => 5
35
+ }
36
+ }
37
+ }
38
+ assert_converter 't35t', {'replace'=>'numbers'}, 'test', rules
39
+ end
40
+
41
+ def test_case_swapping
42
+ assert_converter 'tEsT', 'swapcase', 'test'
43
+ end
44
+
45
+ def test_case_swapping_ignores_numbers
46
+ assert_converter "tEsT4fUn", 'swapcase', "test4fun"
47
+ assert_converter "fUn4TeSt", 'swapcase', "fun4test"
48
+ end
49
+
50
+ def test_char_collapsing
51
+ assert_converter "abc", 'collapse_chars', "a b c"
52
+ end
53
+
54
+ def test_select_first_chars
55
+ assert_converter "t a t f t", 'first_chars', "test all the fucking time"
56
+ end
57
+
29
58
  protected
30
59
 
31
- def assert_converter(expected, rule, string = 'test')
60
+ def assert_converter(expected, rule, string = 'test', rules = {})
32
61
  assert_nothing_raised LoadError do
33
- result = converter.send(:apply_rule, string, rule)
62
+ result = ToPass::Converter.new(rules).send(:apply_rule, string, rule)
34
63
  assert_equal expected, result, "Converter '#{rule.inspect}' should convert #{string} to #{expected}."
35
64
  end
36
65
  end
37
-
38
- def converter
39
- ToPass::Converter.new({})
40
- end
41
66
  end
@@ -0,0 +1,51 @@
1
+ # vim:ft=ruby:fileencoding=utf-8
2
+
3
+ require File.expand_path('../helper', __FILE__)
4
+
5
+ class TestFileReader < Test::Unit::TestCase
6
+ test_presence ToPass::FileReader
7
+
8
+ def test_initialize
9
+ assert_nothing_raised do
10
+ klass.new
11
+ end
12
+ end
13
+
14
+ def test_load
15
+ assert_respond_to klass, :load
16
+ assert_not_nil klass.load('config')
17
+ end
18
+
19
+ def test_discover
20
+ assert_respond_to klass, :discover
21
+ assert_kind_of Array, klass.discover
22
+ end
23
+
24
+ def test_has_load_path
25
+ assert_respond_to reader, :load_path
26
+ assert_kind_of Array, reader.load_path
27
+ end
28
+
29
+ def test_load_path_contains_standard_dirs
30
+ dirs = standard_directories.map { |path| "#{path}#{concern}"}
31
+
32
+ Pathname.any_instance.expects(:exist?).at_least(dirs.size).returns(true)
33
+
34
+ dirs.each do |reldir|
35
+ dir = Pathname.new(reldir).expand_path
36
+ assert_include dir, reader.load_path
37
+ end
38
+ end
39
+
40
+ protected
41
+
42
+ def concern
43
+ ''
44
+ end
45
+ def klass
46
+ ToPass::FileReader
47
+ end
48
+ def reader
49
+ @reader ||= klass.new
50
+ end
51
+ end
data/test/tests.watchr ADDED
@@ -0,0 +1,45 @@
1
+ # vim:ft=ruby
2
+ require 'rubygems'
3
+ require 'watchr'
4
+
5
+ # helper methods
6
+ def run_all
7
+ puts "\rrunning all tests. Hit CTRL-\\ to quit."
8
+ sleep(1)
9
+ system "ruby test/all.rb"
10
+ end
11
+ def single_or_all(fn)
12
+ clear_screen
13
+ if File.exist?(File.expand_path(fn))
14
+ system "ruby -Ilib -Itest #{fn}"
15
+ else
16
+ run_all
17
+ end
18
+ end
19
+ def clear_screen
20
+ system "clear"
21
+ end
22
+
23
+ # test_runner-lambda
24
+ single_test = lambda { |m|
25
+ single_or_all("test/test_#{m[1]}.rb")
26
+ }
27
+
28
+ # specific mappings
29
+ watch '^data/to_pass/(algorithms|converters)/*.rb' do |m|
30
+ single_or_all("test/test_#{m[1]}.rb")
31
+ end
32
+ watch '^data/config' do |m|
33
+ single_or_all("test/test_configs.rb")
34
+ end
35
+
36
+ # simple mappings
37
+ watch '^lib/to_pass/(.*).rb', &single_test
38
+ watch '^test/test_(.*).rb', &single_test
39
+
40
+ Signal.trap 'QUIT' do
41
+ abort("\n")
42
+ end
43
+ Signal.trap 'INT' do
44
+ run_all
45
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_pass
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 59
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 8
8
+ - 9
9
9
  - 0
10
- version: 0.8.0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthias Viehweger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-15 00:00:00 +01:00
18
+ date: 2011-02-01 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,7 @@ files:
78
78
  - data/to_pass/algorithms/basic_de.yml
79
79
  - data/to_pass/algorithms/basic_en.yml
80
80
  - data/to_pass/algorithms/secure.yml
81
+ - data/to_pass/config
81
82
  - data/to_pass/converters/collapse_chars.rb
82
83
  - data/to_pass/converters/downcase.rb
83
84
  - data/to_pass/converters/expand_below.rb
@@ -92,10 +93,12 @@ files:
92
93
  - lib/to_pass/algorithm_reader.rb
93
94
  - lib/to_pass/base.rb
94
95
  - lib/to_pass/cli.rb
96
+ - lib/to_pass/config_reader.rb
95
97
  - lib/to_pass/converter.rb
96
98
  - lib/to_pass/converter_reader.rb
97
99
  - lib/to_pass/converters.rb
98
100
  - lib/to_pass/directories.rb
101
+ - lib/to_pass/file_reader.rb
99
102
  - lib/to_pass/integration.rb
100
103
  - lib/to_pass/version.rb
101
104
  - man/index.txt
@@ -116,10 +119,14 @@ files:
116
119
  - test/test_algorithms.rb
117
120
  - test/test_base.rb
118
121
  - test/test_cli.rb
122
+ - test/test_config_reader.rb
123
+ - test/test_configs.rb
119
124
  - test/test_converter.rb
120
125
  - test/test_converter_reader.rb
121
126
  - test/test_converters.rb
127
+ - test/test_file_reader.rb
122
128
  - test/test_integration.rb
129
+ - test/tests.watchr
123
130
  - README.rdoc
124
131
  - TODO
125
132
  has_rdoc: true
@@ -168,7 +175,11 @@ test_files:
168
175
  - test/test_algorithms.rb
169
176
  - test/test_base.rb
170
177
  - test/test_cli.rb
178
+ - test/test_config_reader.rb
179
+ - test/test_configs.rb
171
180
  - test/test_converter.rb
172
181
  - test/test_converter_reader.rb
173
182
  - test/test_converters.rb
183
+ - test/test_file_reader.rb
174
184
  - test/test_integration.rb
185
+ - test/tests.watchr