ppp 0.1.3.alpha → 0.1.4.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/ppp/cppp.c +0 -9
- data/lib/ppp.rb +2 -0
- data/lib/ppp/card/base.rb +29 -8
- data/lib/ppp/card/html.rb +12 -7
- data/lib/ppp/card/plain.rb +20 -29
- data/lib/ppp/card/xml.rb +20 -0
- data/lib/ppp/version.rb +1 -1
- metadata +3 -2
data/ext/ppp/cppp.c
CHANGED
@@ -12,7 +12,6 @@ void Init_Cppp()
|
|
12
12
|
{
|
13
13
|
cPpp = rb_define_class( "Cppp", rb_cObject );
|
14
14
|
rb_define_module_function( cPpp, "random_key", t_random_key, 0 );
|
15
|
-
rb_define_module_function( cPpp, "key_from_string", t_key_from_string, 1 );
|
16
15
|
rb_define_module_function( cPpp, "passcodes", t_get_passcodes, 5 );
|
17
16
|
}
|
18
17
|
|
@@ -38,14 +37,6 @@ static VALUE t_random_key( VALUE self )
|
|
38
37
|
return key_to_string( &key );
|
39
38
|
}
|
40
39
|
|
41
|
-
static VALUE t_key_from_string( VALUE self, VALUE str )
|
42
|
-
{
|
43
|
-
SequenceKey key;
|
44
|
-
|
45
|
-
GenerateSequenceKeyFromString( StringValueCStr( str ), &key );
|
46
|
-
return key_to_string( &key );
|
47
|
-
}
|
48
|
-
|
49
40
|
static VALUE t_get_passcodes( VALUE self, VALUE v_key, VALUE v_offset, VALUE v_count, VALUE v_length, VALUE v_alphabet )
|
50
41
|
{
|
51
42
|
SequenceKey key;
|
data/lib/ppp.rb
CHANGED
@@ -4,6 +4,7 @@ require "ppp/generator"
|
|
4
4
|
require 'ppp/Cppp'
|
5
5
|
require 'ppp/card/base'
|
6
6
|
require 'ppp/card/html'
|
7
|
+
require 'ppp/card/xml'
|
7
8
|
require 'ppp/card/plain'
|
8
9
|
|
9
10
|
module Ppp
|
@@ -29,6 +30,7 @@ module Ppp
|
|
29
30
|
def printer style, *args
|
30
31
|
case style
|
31
32
|
when :html then return Card::Html.new *args
|
33
|
+
when :xml then return Card::Xml.new *args
|
32
34
|
when :plain then return Card::Plain.new *args
|
33
35
|
end
|
34
36
|
raise ArgumentError.new( "%s is not a valid printer style." % style )
|
data/lib/ppp/card/base.rb
CHANGED
@@ -3,6 +3,8 @@ require 'ppp/generator'
|
|
3
3
|
module Ppp
|
4
4
|
module Card
|
5
5
|
class Base
|
6
|
+
attr_reader :card_number, :row_count, :title
|
7
|
+
|
6
8
|
@@CHARS_PER_LINE = 34
|
7
9
|
@@FIRST_COLUMN = ?A
|
8
10
|
@@ROW_COL_PATTERN = /[[:digit:]][[:alpha:]]/
|
@@ -14,24 +16,39 @@ module Ppp
|
|
14
16
|
@generator = generator
|
15
17
|
raise ArgumentError.new( @@ERROR_LONG_CODES ) if code_length > 16
|
16
18
|
|
17
|
-
options = { :
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
options = { :row_count => 10,
|
20
|
+
:card_title => 'PPP Passcard',
|
21
|
+
:first_card_number => 1 }
|
22
|
+
options.merge! opts
|
23
|
+
@title = options[ :card_title ]
|
24
|
+
@row_count = options[ :row_count ]
|
25
|
+
@card_number = options[ :first_card_number ]
|
21
26
|
end
|
22
27
|
|
23
28
|
def code_length
|
24
29
|
@generator.length
|
25
30
|
end
|
26
31
|
|
32
|
+
def card_number= number
|
33
|
+
raise ArgumentError.new( "card number must be a positive integer" ) if number < 1
|
34
|
+
@card_number = number
|
35
|
+
end
|
36
|
+
|
27
37
|
def passcodes_per_line
|
28
38
|
@passcodes_per_line ||= ( (@@CHARS_PER_LINE+1) / (code_length + 1) ).to_i
|
29
39
|
end
|
30
40
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
def passcodes_per_card
|
42
|
+
passcodes_per_line * row_count
|
43
|
+
end
|
44
|
+
|
45
|
+
def codes
|
46
|
+
(1..row_count).collect do |row|
|
47
|
+
card_offset = (card_number-1) * passcodes_per_card
|
48
|
+
offset = card_offset + ((row-1) * passcodes_per_line)
|
49
|
+
puts "offset: #{offset}"
|
50
|
+
@generator.passcodes( offset, passcodes_per_line )
|
51
|
+
end
|
35
52
|
end
|
36
53
|
|
37
54
|
def passcode row_col
|
@@ -45,6 +62,10 @@ module Ppp
|
|
45
62
|
|
46
63
|
@generator.passcode row_offset * passcodes_per_line + col_offset
|
47
64
|
end
|
65
|
+
|
66
|
+
def column_label column_number
|
67
|
+
(@@FIRST_COLUMN.ord + (column_number - 1)).chr
|
68
|
+
end
|
48
69
|
end
|
49
70
|
end
|
50
71
|
end
|
data/lib/ppp/card/html.rb
CHANGED
@@ -15,7 +15,7 @@ class Ppp::Card::Html < Ppp::Card::Base
|
|
15
15
|
def css
|
16
16
|
%[
|
17
17
|
<style>
|
18
|
-
.card, .card .title, .card .
|
18
|
+
.card, .card .title, .card .card_number, .card .codes, .card .codes td {
|
19
19
|
font-family: monospace;
|
20
20
|
font-size: 3.5mm;
|
21
21
|
}
|
@@ -39,12 +39,12 @@ class Ppp::Card::Html < Ppp::Card::Base
|
|
39
39
|
.title td:first-child {
|
40
40
|
width: 2.5em;
|
41
41
|
}
|
42
|
-
.
|
42
|
+
.card_number {
|
43
43
|
float: right;
|
44
44
|
margin-right: 1ex;
|
45
45
|
}
|
46
|
-
.
|
47
|
-
.
|
46
|
+
.card_number:before { content: '['; }
|
47
|
+
.card_number:after { content: ']'; }
|
48
48
|
|
49
49
|
.codes_heading th {
|
50
50
|
text-align: center;
|
@@ -79,20 +79,25 @@ class Ppp::Card::Html < Ppp::Card::Base
|
|
79
79
|
end
|
80
80
|
|
81
81
|
def html
|
82
|
+
rows = codes.each_with_index.collect do |row, i|
|
83
|
+
cols = row.collect { |code| " <td>#{code}</td>" }.join(?\n)
|
84
|
+
"<tr>\n <td>#{i+1}:</td>\n#{cols}</tr>"
|
85
|
+
end.join(?\n)
|
86
|
+
|
82
87
|
%[
|
83
88
|
<table class="card">
|
84
89
|
<caption class="title">
|
85
90
|
#{@title}
|
86
|
-
<span class="
|
91
|
+
<span class="card_number">#{card_number}</span>
|
87
92
|
</caption>
|
88
93
|
<colgroup span="1">
|
89
94
|
<colgroup span="#{passcodes_per_line}">
|
90
95
|
<thead class="codes_heading">
|
91
96
|
<th> </th>
|
92
|
-
#{
|
97
|
+
#{ passcodes_per_line.times.collect { |i| %[<th>#{column_label(i+1)}</th>] }.join ?\n }
|
93
98
|
</thead>
|
94
99
|
<tbody class="codes">
|
95
|
-
#{
|
100
|
+
#{rows}
|
96
101
|
</tbody>
|
97
102
|
</table>
|
98
103
|
]
|
data/lib/ppp/card/plain.rb
CHANGED
@@ -4,9 +4,6 @@ class Ppp::Card::Plain < Ppp::Card::Base
|
|
4
4
|
|
5
5
|
def initialize generator, opts={}
|
6
6
|
super
|
7
|
-
|
8
|
-
options = { :row_count => 10 }.merge opts
|
9
|
-
@row_count = options[ :row_count ]
|
10
7
|
end
|
11
8
|
|
12
9
|
def to_s
|
@@ -18,59 +15,53 @@ class Ppp::Card::Plain < Ppp::Card::Base
|
|
18
15
|
line( split_bar )
|
19
16
|
end
|
20
17
|
|
18
|
+
def card_number= number
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
21
22
|
private
|
22
23
|
|
23
24
|
def bar
|
24
|
-
|
25
|
+
'-' * (width + 2)
|
25
26
|
end
|
26
27
|
|
27
28
|
def width
|
28
|
-
|
29
|
-
|
30
|
-
header.size
|
31
|
-
end
|
29
|
+
return rows.first.join( ' ' ).size if rows.size >= 1
|
30
|
+
header.size
|
32
31
|
end
|
33
32
|
|
34
33
|
def rows
|
35
|
-
|
36
|
-
(1..@row_count).collect do |i|
|
37
|
-
[ first_column( i ) ] + (1..passcodes_per_line).collect {next_code}
|
38
|
-
end
|
39
|
-
end
|
34
|
+
codes.each_with_index.collect { |row, i| [ first_column( i ) ] + row }
|
40
35
|
end
|
41
36
|
|
42
37
|
def header
|
43
|
-
|
38
|
+
header_cells.join ' '
|
44
39
|
end
|
45
40
|
|
46
41
|
def header_cells
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
cells = passcodes_per_line.times.collect { |i| column_label(i+1).center code_length }
|
43
|
+
|
44
|
+
[' ' * first_column_width ] + cells
|
50
45
|
end
|
51
46
|
|
52
47
|
def title_str
|
53
|
-
@
|
54
|
-
title = @title[0, width - card_label.size] # trim title if it's too long to fit
|
48
|
+
title = @title[0, width - card_label.size] # trim title if it's too long to fit
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
end
|
50
|
+
blank_space = width - (title.size + card_label.size)
|
51
|
+
title = title + (' ' * blank_space) + card_label
|
59
52
|
end
|
60
53
|
|
61
54
|
def card_label
|
62
|
-
|
55
|
+
"[#{card_number}]"
|
63
56
|
end
|
64
57
|
|
65
58
|
def split_bar
|
66
|
-
|
67
|
-
|
68
|
-
"-#{parts.join '+'}-"
|
69
|
-
end
|
59
|
+
parts = ['-' * first_column_width] + (1..passcodes_per_line).collect { '-' * code_length }
|
60
|
+
"-#{parts.join '+'}-"
|
70
61
|
end
|
71
62
|
|
72
63
|
def row_lines
|
73
|
-
|
64
|
+
rows.collect{ |r| line :pad, r.join( ' ' ) }
|
74
65
|
end
|
75
66
|
|
76
67
|
def line pad=:nopad, str
|
@@ -86,6 +77,6 @@ class Ppp::Card::Plain < Ppp::Card::Base
|
|
86
77
|
end
|
87
78
|
|
88
79
|
def first_column_width
|
89
|
-
@
|
80
|
+
@row_count.to_s.size + 1
|
90
81
|
end
|
91
82
|
end
|
data/lib/ppp/card/xml.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'ppp/generator'
|
2
|
+
require 'ppp/card/base'
|
3
|
+
|
4
|
+
class Ppp::Card::Xml < Ppp::Card::Base
|
5
|
+
def initialize generator, opts={}
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
rows = codes.each_with_index.collect do |row, i|
|
11
|
+
cols = row.each_with_index.collect { |code, j| " <column label=\"#{column_label(j+1)}\">#{code}</column>" }.join(?\n)
|
12
|
+
" <row number=\"#{i+1}\">\n#{cols}\n </row>\n"
|
13
|
+
end.join(?\n)
|
14
|
+
|
15
|
+
%[<?xml version="1.0" encoding="UTF-8" ?>\n] +
|
16
|
+
%[<card title="#{@title}" number="#{card_number}">\n] +
|
17
|
+
rows +
|
18
|
+
%[</card>\n]
|
19
|
+
end
|
20
|
+
end
|
data/lib/ppp/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4.alpha
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby-PPP is a Ruby language binding of PPP (Perfect Paper Passwords).
|
15
15
|
PPP is a library designed to create one-time passwords, described at http://grc.com/ppp.htm
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- lib/ppp/version.rb
|
27
27
|
- lib/ppp/card/base.rb
|
28
28
|
- lib/ppp/card/plain.rb
|
29
|
+
- lib/ppp/card/xml.rb
|
29
30
|
- lib/ppp/card/html.rb
|
30
31
|
- ext/ppp/ppp.c
|
31
32
|
- ext/ppp/cppp.c
|