vacman_controller 0.5.0 → 0.6.0

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.
@@ -40,7 +40,7 @@ module VacmanController
40
40
  name = name.to_s
41
41
  value = VacmanController::LowLevel.get_token_property(@token.to_h, name)
42
42
 
43
- cast(name, value)
43
+ read_cast(name, value)
44
44
  end
45
45
 
46
46
 
@@ -52,63 +52,114 @@ module VacmanController
52
52
  # the property name. See +Token.property_names+
53
53
  #
54
54
  # value::
55
- # the property value. Only values convertible to integer are
56
- # supported.
55
+ # the property value. The AAL2 library accepts only values
56
+ # convertible to integer. For symmetry with +[]+, boolean
57
+ # values are converted to the appropriate integer.
58
+ #
59
+ # see::
60
+ # +write_cast!+
57
61
  #
58
62
  def []=(name, value)
59
63
  name = name.to_s
60
- value = value.to_i
61
-
62
- check_bounded_property!(name, value)
64
+ value = write_cast!(name, value)
63
65
 
64
66
  VacmanController::LowLevel.set_token_property(@token.to_h, name, value)
65
67
  end
66
68
 
67
-
68
69
  protected
69
- def bounded_property?(name)
70
- PROPERTY_BOUNDS.key?(name)
70
+ #
71
+ def write_cast!(property, value)
72
+ case property
73
+ # Bounded integer values
74
+ when 'last_time_used'
75
+ write_check_bounds! property, value,
76
+ [631152000, 2147483647]
77
+
78
+ when 'last_time_shift'
79
+ write_check_bounds! property, value,
80
+ [-100_000, 100_000]
81
+
82
+ when 'pin_enabled'
83
+ value ? 1 : 2
84
+
85
+ when 'pin_change_forced'
86
+ if value
87
+ 1
88
+ else
89
+ raise VacmanController::Error,
90
+ "Token property #{property} cannot be set to #{value.inspect}"
91
+ end
92
+
93
+ when 'pin_min_len', 'pin_minimum_length'
94
+ write_check_bounds! property, value,
95
+ [3, 8]
96
+
97
+ when 'virtual_token_grace_period'
98
+ write_check_bounds! property, value,
99
+ [1, 364]
100
+
101
+ when 'virtual_token_remain_use'
102
+ write_check_bounds! property, value,
103
+ [0, 254]
104
+
105
+ when 'error_count'
106
+ if value == 0
107
+ value
108
+ else
109
+ raise VacmanController::Error,
110
+ "Token property #{property} cannot be set to #{value.inspect}"
111
+ end
112
+
113
+ when 'event_value'
114
+ write_check_bounds! property, value,
115
+ [0, 4_294_967_294]
116
+
117
+ when 'token_status'
118
+ case value
119
+ when :disabled then 0
120
+ when :primary_only then 1
121
+ when :backup_only then 2
122
+ when :enabled then 3
123
+ else
124
+ raise VacmanController::Error,
125
+ "Token property #{property} cannot be set to #{value.inspect}"
126
+ end
127
+
128
+ else
129
+ raise VacmanController::Error,
130
+ "Invalid or read-only property: #{property}"
131
+ end
71
132
  end
72
133
 
73
134
  # The library also does these checks, but we want to present
74
135
  # custom error message to the caller.
75
136
  #
76
- def check_bounded_property!(name, value)
77
- return unless bounded_property?(name)
78
-
79
- min, max = PROPERTY_BOUNDS.fetch(name)
137
+ def write_check_bounds!(property, value, bounds)
138
+ min, max = bounds
80
139
 
81
140
  if value < min || value > max
82
141
  raise VacmanController::Error,
83
- "Invalid #{name} value provided: #{value}. " \
142
+ "Invalid #{property} value provided: #{value}. " \
84
143
  "Must be between greater than #{min} and less than #{max}."
85
144
  end
86
145
 
87
- true
146
+ value
88
147
  end
89
148
 
90
- PROPERTY_BOUNDS = {
91
- 'last_time_used' => [ 631152000, 2147483647 ],
92
-
93
- 'last_time_shift' => [ -100_000, 100_000 ],
94
-
95
- 'pin_min_length' => [ 3, 8 ],
96
- 'pin_minimum_length' => [ 3, 8 ],
97
-
98
- 'virtual_token_grace_period' => [ 1, 364 ],
99
-
100
- 'virtual_token_remain_use' => [ 0, 254 ],
101
-
102
- 'event_value' => [ 0, 4_294_967_294 ],
103
- }
104
-
105
- def cast(property, value)
106
149
 
150
+ # Maps the given property value to a Ruby value for:
151
+ #
152
+ # * Integers
153
+ # * Booleans
154
+ # * Dates
155
+ # * Enumerations (Symbols)
156
+ #
157
+ def read_cast(property, value)
107
158
  # Short-circuit on 'NA'
108
159
  return nil if value == 'NA' or value == 'DISABLE'
109
160
 
110
161
  case property
111
- when # Integer values
162
+ when # Integer values
112
163
  'use_count',
113
164
  'pin_len',
114
165
  'pin_length',
@@ -123,7 +174,6 @@ module VacmanController
123
174
  'response_len',
124
175
  'response_length',
125
176
  'time_step'
126
-
127
177
  value.to_i
128
178
 
129
179
  when # Boolean values
@@ -178,6 +228,10 @@ module VacmanController
178
228
  end
179
229
 
180
230
  private
231
+ # Exposes a getter and setter method for each
232
+ # property name. Delegates error handling for
233
+ # invalid properties to +[]+ and +[]=+.
234
+ #
181
235
  def method_missing(name, *args, &block)
182
236
  prop, setter = name.to_s.match(/\A(.+?)(=)?\Z/).values_at(1, 2)
183
237
 
@@ -110,7 +110,7 @@ module VacmanController
110
110
  # Enables the PIN on this token
111
111
  #
112
112
  def enable_pin!
113
- properties[:pin_enabled] = 1
113
+ properties[:pin_enabled] = true
114
114
  true
115
115
  end
116
116
 
@@ -118,7 +118,7 @@ module VacmanController
118
118
  # Disables the PIN on this token
119
119
  #
120
120
  def disable_pin!
121
- properties[:pin_enabled] = 2
121
+ properties[:pin_enabled] = false
122
122
  true
123
123
  end
124
124
 
@@ -126,7 +126,7 @@ module VacmanController
126
126
  # Forces PIN change on this token
127
127
  #
128
128
  def force_pin_change!
129
- properties[:pin_change_forced] = 1
129
+ properties[:pin_change_forced] = true
130
130
  true
131
131
  end
132
132
 
@@ -142,7 +142,7 @@ module VacmanController
142
142
  # Sets the "disabled" token status
143
143
  #
144
144
  def disable!
145
- properties[:token_status] = 0
145
+ properties[:token_status] = :disabled
146
146
  true
147
147
  end
148
148
 
@@ -150,7 +150,7 @@ module VacmanController
150
150
  # Set the primary application enabled status
151
151
  #
152
152
  def enable_primary_only!
153
- properties[:token_status] = 1
153
+ properties[:token_status] = :primary_only
154
154
  true
155
155
  end
156
156
 
@@ -158,7 +158,7 @@ module VacmanController
158
158
  # Set the backup application enabled status
159
159
  #
160
160
  def enable_backup_only!
161
- properties[:token_status] = 2
161
+ properties[:token_status] = :backup_only
162
162
  true
163
163
  end
164
164
 
@@ -166,7 +166,7 @@ module VacmanController
166
166
  # Set both primary and backup application enabled status
167
167
  #
168
168
  def enable!
169
- properties[:token_status] = 3
169
+ properties[:token_status] = :enabled
170
170
  true
171
171
  end
172
172
 
@@ -0,0 +1,3 @@
1
+ module VacmanController
2
+ VERSION = '0.6.0'
3
+ end
@@ -1,4 +1,4 @@
1
- require 'vacman_controller/low_level'
1
+ require 'vacman_controller/vacman_low_level'
2
2
  require 'vacman_controller/token'
3
3
  require 'vacman_controller/kernel'
4
4
  require 'vacman_controller/error'
@@ -6,9 +6,6 @@ require 'vacman_controller/error'
6
6
  # Wraps VACMAN Controller functionality for Ruby.
7
7
  #
8
8
  module VacmanController
9
-
10
- VERSION = '0.5.0'
11
-
12
9
  class << self
13
10
  # Imports a .dpx file containing the token key material.
14
11
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacman_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Lankenau
@@ -53,6 +53,34 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: simplecov
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: byebug
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
56
84
  description: Expose the AAL2 SDK API via a set of Ruby classes optimised for developer
57
85
  happiness
58
86
  email:
@@ -63,13 +91,19 @@ extensions:
63
91
  - ext/vacman_controller/extconf.rb
64
92
  extra_rdoc_files: []
65
93
  files:
94
+ - ext/vacman_controller/dpx.c
66
95
  - ext/vacman_controller/extconf.rb
67
- - ext/vacman_controller/low_level.c
96
+ - ext/vacman_controller/kernel.c
97
+ - ext/vacman_controller/main.c
98
+ - ext/vacman_controller/serialize.c
99
+ - ext/vacman_controller/token.c
100
+ - ext/vacman_controller/vacman_controller.h
68
101
  - lib/vacman_controller.rb
69
102
  - lib/vacman_controller/error.rb
70
103
  - lib/vacman_controller/kernel.rb
71
104
  - lib/vacman_controller/token.rb
72
105
  - lib/vacman_controller/token/properties.rb
106
+ - lib/vacman_controller/version.rb
73
107
  homepage: https://github.com/ifad/vacman_controller
74
108
  licenses: []
75
109
  metadata: {}