Class: Rights::KeySettings
- Inherits:
-
Object
- Object
- Rights::KeySettings
- Defined in:
- lib/key_settings.rb
Overview
The key settings determine the level of authentication needed to perform operations on the tag (DESFire) top-level, or on an application.
Instance Attribute Summary collapse
-
#auth_create ⇒ Object
readonly
Can files/applications be created or deleted / created without application/tag master key authentication? Takes values 0 or 1.
-
#auth_get ⇒ Object
readonly
Can the commands (
GetFileIDs
,GetFileSettings
,GetKeySettings
) / (GetApplicationIDs
,GetKeySettings
) be performed without application/tag master key authentication? Takes values 0 or 1. -
#change_key ⇒ Object
readonly
Only defined for application keys settings.
-
#master_change ⇒ Object
readonly
Is the application/tag master key modifiable? Takes values 0 or 1.
-
#settings_change ⇒ Object
readonly
Can the key settings for this application/tag be changed again? Takes values 0 or 1.
Class Method Summary collapse
-
.from_byte(byte) ⇒ Object
Creates a
KeySettings
object from a byte representing the key settings.
Instance Method Summary collapse
-
#can_change_key?(aid, changing_key, change_key) ⇒ Boolean
Can key
changing_key
of applicationaid
be changed by authenticating with keychange_key
?. -
#can_change_key_settings?(key_no) ⇒ Boolean
Can we change this key settings on the tag’s currently selected application if authenticated with the given key?.
-
#can_create_app?(aid, key_no) ⇒ Boolean
Can we create an application if authenticated with the given key on the given application?.
-
#can_delete_app?(aid, key_no) ⇒ Boolean
Can we delete an application if authenticated with the given key on the given application?.
-
#can_edit_file?(key_no) ⇒ Boolean
Can we create or delete a file if authenticated with the given key?.
-
#can_get0?(aid, key_no) ⇒ Boolean
Can we perform the top-level
GetApplicationIDs
andGetKeySettings
) commands if authenticated with the given key?. -
#can_get?(key_no) ⇒ Boolean
Can we perform the application-level
GetFileIDs
,GetFileSettings
andGetKeySettings
commands if authenticated with the given key on the given application?. -
#initialize(hash = {}) ⇒ KeySettings
constructor
The constructor takes a hash of parameters, which correspond to the class attributes.
-
#to_byte ⇒ Object
Returns a byte representing the key settings, fit to be used as a command parameter.
Constructor Details
#initialize(hash = {}) ⇒ KeySettings
The constructor takes a hash of parameters, which correspond to the class attributes.
42 43 44 45 46 47 48 |
# File 'lib/key_settings.rb', line 42 def initialize(hash={}) @master_change = hash[:master_change] || 1 @auth_get = hash[:auth_get] || 1 @auth_create = hash[:auth_create] || 0 @settings_change = hash[:settings_change] || 1 @change_key = hash[:change_key] || 0x0 end |
Instance Attribute Details
#auth_create ⇒ Object (readonly)
Can files/applications be created or deleted / created without application/tag master key authentication? Takes values 0 or 1.
26 27 28 |
# File 'lib/key_settings.rb', line 26 def auth_create @auth_create end |
#auth_get ⇒ Object (readonly)
Can the commands (GetFileIDs
, GetFileSettings
, GetKeySettings
) / (GetApplicationIDs
, GetKeySettings
) be performed without application/tag master key authentication? Takes values 0 or 1.
22 23 24 |
# File 'lib/key_settings.rb', line 22 def auth_get @auth_get end |
#change_key ⇒ Object (readonly)
Only defined for application keys settings. Defines the key needed to change application keys. It can be an application key number between 0x0 and 0xE (inclusive, 0x0 being the application master key) or one of the constants CHANGED_KEY
(authenticated with the key that will be changed) or IMMUTABLE
(keys cannot be changed) (constants defined in the Rights
module). Takes a value key
such that (0x0 <= key
<= 0xF).
38 39 40 |
# File 'lib/key_settings.rb', line 38 def change_key @change_key end |
#master_change ⇒ Object (readonly)
Is the application/tag master key modifiable? Takes values 0 or 1.
17 18 19 |
# File 'lib/key_settings.rb', line 17 def master_change @master_change end |
#settings_change ⇒ Object (readonly)
Can the key settings for this application/tag be changed again? Takes values 0 or 1.
30 31 32 |
# File 'lib/key_settings.rb', line 30 def settings_change @settings_change end |
Class Method Details
.from_byte(byte) ⇒ Object
Creates a KeySettings
object from a byte representing the key settings.
51 52 53 54 55 56 57 58 |
# File 'lib/key_settings.rb', line 51 def self.from_byte(byte) KeySettings.new( :master_change => (byte & 0x1) % 2, :auth_get => (byte & 0x2) % 2, :auth_create => (byte & 0x4) % 2, :settings_change => (byte & 0x8) % 2, :change_key => byte >> 4) end |
Instance Method Details
#can_change_key?(aid, changing_key, change_key) ⇒ Boolean
Can key changing_key
of application aid
be changed by authenticating with key change_key
?
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/key_settings.rb', line 72 def can_change_key?(aid, changing_key, change_key) if aid == 0 changing_key == 0 && change_key == 0 elsif @change_key == IMMUTABLE false elsif @change_key == CHANGED_KEY change_key == changing_key elsif @change_key == changing_key change_key == 0 else change_key == @change_key end end |
#can_change_key_settings?(key_no) ⇒ Boolean
Can we change this key settings on the tag’s currently selected application if authenticated with the given key?
118 119 120 |
# File 'lib/key_settings.rb', line 118 def can_change_key_settings?(key_no) @settings_change and key_no == 0 end |
#can_create_app?(aid, key_no) ⇒ Boolean
Can we create an application if authenticated with the given key on the given application?
106 107 108 |
# File 'lib/key_settings.rb', line 106 def can_create_app?(aid, key_no) aid == 0 and (@auth_create = 1 or key_no = 0) end |
#can_delete_app?(aid, key_no) ⇒ Boolean
Can we delete an application if authenticated with the given key on the given application?
112 113 114 |
# File 'lib/key_settings.rb', line 112 def can_delete_app?(aid, key_no) aid == 0 and key_no == 0 end |
#can_edit_file?(key_no) ⇒ Boolean
Can we create or delete a file if authenticated with the given key?
100 101 102 |
# File 'lib/key_settings.rb', line 100 def can_edit_file?(key_no) @auth_create == 1 or key_no == 0 end |
#can_get0?(aid, key_no) ⇒ Boolean
Can we perform the top-level GetApplicationIDs
and GetKeySettings
) commands if authenticated with the given key?
95 96 97 |
# File 'lib/key_settings.rb', line 95 def can_get0?(aid, key_no) aid == 0 and (@auth_get == 1 or key_no == 0) end |
#can_get?(key_no) ⇒ Boolean
Can we perform the application-level GetFileIDs
, GetFileSettings
and GetKeySettings
commands if authenticated with the given key on the given application?
89 90 91 |
# File 'lib/key_settings.rb', line 89 def can_get?(key_no) @auth_get == 1 or key_no == 0 end |
#to_byte ⇒ Object
Returns a byte representing the key settings, fit to be used as a command parameter.
62 63 64 65 66 67 68 |
# File 'lib/key_settings.rb', line 62 def to_byte 1 * @master_change + 2 * @auth_get + 4 * @auth_create + 8 * @settings_change + 16 * @change_key end |