pki_express 1.3.1 → 1.3.2

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -2
  3. data/.github/workflows/test.yml +21 -21
  4. data/.gitignore +27 -27
  5. data/CHANGELOG.md +19 -16
  6. data/Gemfile +8 -7
  7. data/README.md +24 -24
  8. data/Rakefile +6 -6
  9. data/lib/pki_express/auth_complete_result.rb +21 -21
  10. data/lib/pki_express/auth_start_result.rb +76 -76
  11. data/lib/pki_express/authentication.rb +284 -284
  12. data/lib/pki_express/base_signer.rb +54 -54
  13. data/lib/pki_express/cades_signature.rb +89 -89
  14. data/lib/pki_express/cades_signature_starter.rb +242 -242
  15. data/lib/pki_express/check_service_result.rb +15 -15
  16. data/lib/pki_express/command_error.rb +13 -13
  17. data/lib/pki_express/commands.rb +24 -24
  18. data/lib/pki_express/digest_algorithm.rb +118 -118
  19. data/lib/pki_express/digest_algorithm_and_value.rb +30 -30
  20. data/lib/pki_express/discovery_service_result.rb +25 -25
  21. data/lib/pki_express/enum.rb +9 -9
  22. data/lib/pki_express/error_codes.rb +46 -46
  23. data/lib/pki_express/installation_not_found_error.rb +8 -8
  24. data/lib/pki_express/name.rb +47 -47
  25. data/lib/pki_express/oids.rb +30 -30
  26. data/lib/pki_express/pades_certification_level.rb +7 -7
  27. data/lib/pki_express/pades_horizontal_align.rb +9 -9
  28. data/lib/pki_express/pades_measurement_units.rb +8 -8
  29. data/lib/pki_express/pades_page_optimization.rb +50 -50
  30. data/lib/pki_express/pades_page_orientation.rb +9 -9
  31. data/lib/pki_express/pades_paper_size.rb +21 -21
  32. data/lib/pki_express/pades_signature.rb +16 -16
  33. data/lib/pki_express/pades_signature_explorer.rb +30 -30
  34. data/lib/pki_express/pades_signature_starter.rb +251 -251
  35. data/lib/pki_express/pades_signer.rb +274 -274
  36. data/lib/pki_express/pades_signer_info.rb +9 -9
  37. data/lib/pki_express/pades_size.rb +17 -17
  38. data/lib/pki_express/pades_text_horizontal_align.rb +8 -8
  39. data/lib/pki_express/pades_vertical_align.rb +9 -9
  40. data/lib/pki_express/pades_visual_auto_positioning.rb +21 -21
  41. data/lib/pki_express/pades_visual_image.rb +51 -51
  42. data/lib/pki_express/pades_visual_manual_positioning.rb +16 -16
  43. data/lib/pki_express/pades_visual_positioning.rb +27 -27
  44. data/lib/pki_express/pades_visual_rectangle.rb +74 -74
  45. data/lib/pki_express/pades_visual_representation.rb +22 -22
  46. data/lib/pki_express/pades_visual_text.rb +35 -35
  47. data/lib/pki_express/pk_algorithms.rb +157 -157
  48. data/lib/pki_express/pk_certificate.rb +61 -61
  49. data/lib/pki_express/pki_brazil_certificate_fields.rb +57 -57
  50. data/lib/pki_express/pki_brazil_certificate_types.rb +19 -19
  51. data/lib/pki_express/pki_express_config.rb +39 -26
  52. data/lib/pki_express/pki_express_operator.rb +240 -240
  53. data/lib/pki_express/pki_italy_certificate_fields.rb +15 -15
  54. data/lib/pki_express/pki_italy_certificate_types.rb +11 -11
  55. data/lib/pki_express/signature_algorithm_and_value.rb +34 -34
  56. data/lib/pki_express/signature_explorer.rb +74 -74
  57. data/lib/pki_express/signature_finisher.rb +314 -314
  58. data/lib/pki_express/signature_policy_identifier.rb +20 -20
  59. data/lib/pki_express/signature_start_result.rb +12 -12
  60. data/lib/pki_express/signature_starter.rb +116 -116
  61. data/lib/pki_express/signer.rb +151 -151
  62. data/lib/pki_express/standard_signature_policies.rb +58 -58
  63. data/lib/pki_express/timestamp_authority.rb +50 -50
  64. data/lib/pki_express/trust_service_auth_parameters.rb +20 -20
  65. data/lib/pki_express/trust_service_info.rb +37 -37
  66. data/lib/pki_express/trust_service_manager.rb +258 -258
  67. data/lib/pki_express/trust_service_session_result.rb +29 -29
  68. data/lib/pki_express/trust_service_session_types.rb +7 -7
  69. data/lib/pki_express/tsa_authentication_type.rb +14 -14
  70. data/lib/pki_express/validation_error.rb +8 -8
  71. data/lib/pki_express/validation_item.rb +43 -43
  72. data/lib/pki_express/validation_item_types.rb +103 -103
  73. data/lib/pki_express/validation_results.rb +120 -120
  74. data/lib/pki_express/version.rb +3 -3
  75. data/lib/pki_express/version_manager.rb +20 -20
  76. data/lib/pki_express.rb +69 -69
  77. data/pki_express.gemspec +26 -26
  78. data/spec/pki_express/pki_express_config_spec.rb +73 -0
  79. data/spec/pki_express/pki_express_operator_spec.rb +30 -30
  80. metadata +4 -2
@@ -1,240 +1,240 @@
1
- require 'shellwords'
2
- require 'securerandom'
3
- require 'open3'
4
- require 'tmpdir'
5
- require 'tempfile'
6
-
7
- module PkiExpress
8
-
9
- class PkiExpressOperator
10
- attr_accessor :offline, :trust_lacuna_test_root, :signature_policy,
11
- :timestamp_authority, :culture, :time_zone
12
-
13
- def initialize(config = PkiExpressConfig.new)
14
- @temp_files = []
15
- @file_references = {}
16
-
17
- @config = config
18
- @version_manager = VersionManager.new
19
- @trusted_roots = []
20
- @offline = false
21
- @trust_lacuna_test_root = false
22
- @signature_policy = nil
23
- @timestamp_authority = nil
24
- @culture = nil
25
- @time_zone = nil
26
-
27
- @id = SecureRandom.uuid
28
- ObjectSpace.define_finalizer(@id, proc {
29
- self.class.finalize(@temp_files)
30
- })
31
- end
32
-
33
- def self.finalize(temp_files)
34
- temp_files.each do |file|
35
- File.delete(file) if File.exist?(file)
36
- end
37
- end
38
-
39
- def add_file_reference(key, reference_path)
40
-
41
- if reference_path.nil?
42
- raise ArgumentError.new('The provided reference path is not valid')
43
- end
44
-
45
- unless File.exists?(reference_path)
46
- raise ArgumentError.new('The provided reference file was not found')
47
- end
48
-
49
- @file_references[key] = reference_path
50
- end
51
-
52
- def add_trusted_root(root_path)
53
-
54
- if root_path.nil?
55
- raise ArgumentError.new('The provided trusted root path is not valid')
56
- end
57
-
58
- unless File.exists?(root_path)
59
- raise ArgumentError.new("The provided trusted root path doesn't exist: #{root_path}")
60
- end
61
-
62
- @trusted_roots.append(root_path)
63
- end
64
-
65
- protected
66
- def invoke_plain(command, args = [])
67
- invoke(command, args, true)
68
- end
69
-
70
- def invoke(command, args = [], plain_output = false)
71
-
72
- # Add PKI Express invocation arguments.
73
- cmd_args = []
74
- get_pki_express_invocation.each do |arg|
75
- cmd_args.append(arg)
76
- end
77
-
78
- # Add PKI Express command.
79
- cmd_args.append(command)
80
-
81
- # Add PKI Express arguments.
82
- cmd_args.concat args
83
-
84
- # Add file references if added.
85
- unless @file_references.nil?
86
- @file_references.each do |key, value|
87
- cmd_args.append('--file-reference')
88
- cmd_args.append("#{key}=#{value}")
89
- end
90
- end
91
-
92
- # Add trusted roots if added.
93
- unless @trusted_roots.nil?
94
- @trusted_roots.each do |trusted_root|
95
- cmd_args.append('--trust-root')
96
- cmd_args.append(trusted_root)
97
- end
98
- end
99
-
100
- # Add trust Lacuna test root if set.
101
- if @trust_lacuna_test_root
102
- cmd_args.append('--trust-test')
103
- end
104
-
105
- # Add offline option if provided.
106
- if @offline
107
- cmd_args.append('--offline')
108
- # This option can only be used on versions greater than 1.2 of the
109
- # PKI Express.
110
- @version_manager.require_version('1.2')
111
- end
112
-
113
- # Add base64 output option
114
- unless plain_output
115
- cmd_args.append('--base64')
116
- end
117
-
118
- unless @culture.nil?
119
- cmd_args.append('--culture')
120
- cmd_args.append(@culture)
121
- # This option can only be used on versions
122
- # greater than 1.10 of the PKI Express.
123
- @version_manager.require_version('1.10')
124
- end
125
-
126
- unless @time_zone.nil?
127
- cmd_args.append('--timezone')
128
- cmd_args.append(@time_zone)
129
- # This option can only be used on versions
130
- # greater than 1.10 of the PKI Express.
131
- @version_manager.require_version('1.10')
132
- end
133
-
134
- # Verify the necessity of using the --min-version flag.
135
- if @version_manager.require_min_version_flag?
136
- cmd_args.append('--min-version')
137
- cmd_args.append(@version_manager.min_version.to_s)
138
- end
139
-
140
- # Escape command args
141
- escaped = []
142
- cmd_args.each do |arg|
143
- escaped.append("\"#{arg}\"")
144
- # escaped.append(Shellwords.escape(arg))
145
- end
146
-
147
- # Perform the "dotnet" command.
148
- stdout, _stderr, status = Open3.capture3(escaped.join(' '))
149
-
150
- if status != 0
151
- if status === ErrorCodes::BAD_SYNTAX and @version_manager.min_version > '1.0'
152
- raise CommandError.new(status, "#{stdout} >>>>> TIP: This operation requires PKI Express #{@version_manager.min_version}, please check your PKI Express version.")
153
- end
154
- if status === ErrorCodes::VALIDATION_FAILED
155
- raise ValidationError.new(stdout)
156
- end
157
- if status === ErrorCodes::COMMAND_NOT_FOUND
158
- raise InstallationNotFoundError.new("Could not find PKI Express's installation.")
159
- end
160
-
161
- raise CommandError.new(status, stdout)
162
- end
163
-
164
- # Return stdout if the command executed with success.
165
- stdout
166
- end
167
-
168
- def get_pki_express_invocation
169
-
170
- # Identify OS.
171
- if (/linux/ =~ RUBY_PLATFORM) != nil
172
- system = :linux
173
- elsif (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
174
- system = :win
175
- else
176
- raise Error.new("Unsupported OS: #{RUBY_PLATFORM}")
177
- end
178
-
179
- # Verify if hte PKI Express home is set on configuration
180
- home = @config.pki_express_home
181
- if not home.nil?
182
-
183
- if system == :linux
184
- unless File.exists?(File.expand_path('pkie.dll', home))
185
- raise InstallationNotFoundError.new("The file pkie.dll could not be found on directory #{home}")
186
- end
187
- elsif not File.exists?(File.expand_path('pkie.exe', home))
188
- raise InstallationNotFoundError.new("The file pkie.exe could not be found on directory #{home}")
189
- end
190
-
191
- elsif system == :win
192
-
193
- if File.exists?(File.join(ENV['ProgramW6432'], 'Lacuna Software', 'PKI Express', 'pkie.exe'))
194
- home = File.join(ENV['ProgramW6432'], 'Lacuna Software', 'PKI Express')
195
- elsif File.exists?(File.join(ENV['ProgramFiles(x86)'], 'Lacuna Software', 'PKI Express', 'pkie.exe'))
196
- home = File.join(ENV['ProgramFiles(x86)'], 'Lacuna Software', 'PKI Express')
197
- elsif File.exists?(File.join(ENV['LOCALAPPDATA'], 'Lacuna Software', 'PKI Express', 'pkie.exe'))
198
- home = File.join(ENV['LOCALAPPDATA'], 'Lacuna Software', 'PKI Express')
199
- elsif File.exists?(File.join(ENV['LOCALAPPDATA'], 'Lacuna Software (x86)', 'PKI Express', 'pkie.exe'))
200
- home = File.join(ENV['LOCALAPPDATA'], 'Lacuna Software (x86)', 'PKI Express')
201
- end
202
-
203
- if home.nil?
204
- raise InstallationNotFoundError.new('Could not determine the
205
- installation folder of PKI Express. If you installed PKI Express on
206
- a custom folder, make sure your chosen folder are specified on the
207
- PkiExpressConfig object.')
208
- end
209
- end
210
-
211
- if system == :linux
212
- unless home.nil?
213
- return ['dotnet', File.expand_path('pkie.dll', home)]
214
- end
215
-
216
- return ['pkie']
217
- end
218
- [File.expand_path('pkie.exe', home)]
219
- end
220
-
221
- def parse_output(data_base64)
222
- json_buff = Base64.decode64(data_base64)
223
- JSON.parse(json_buff, symbolize_names: true)
224
- end
225
-
226
- def create_temp_file
227
- file = Tempfile.new('pkie', @config.temp_folder)
228
- temp_path = file.path
229
- file.close
230
- @temp_files.append(temp_path)
231
- temp_path
232
- end
233
-
234
- def get_transfer_filename
235
- # Generate 16 random bytes. Return a string containing the hex decimals of
236
- # this array.
237
- SecureRandom.hex(16)
238
- end
239
- end
240
- end
1
+ require 'shellwords'
2
+ require 'securerandom'
3
+ require 'open3'
4
+ require 'tmpdir'
5
+ require 'tempfile'
6
+
7
+ module PkiExpress
8
+
9
+ class PkiExpressOperator
10
+ attr_accessor :offline, :trust_lacuna_test_root, :signature_policy,
11
+ :timestamp_authority, :culture, :time_zone
12
+
13
+ def initialize(config = PkiExpressConfig.new)
14
+ @temp_files = []
15
+ @file_references = {}
16
+
17
+ @config = config
18
+ @version_manager = VersionManager.new
19
+ @trusted_roots = []
20
+ @offline = false
21
+ @trust_lacuna_test_root = false
22
+ @signature_policy = nil
23
+ @timestamp_authority = nil
24
+ @culture = nil
25
+ @time_zone = nil
26
+
27
+ @id = SecureRandom.uuid
28
+ ObjectSpace.define_finalizer(@id, proc {
29
+ self.class.finalize(@temp_files)
30
+ })
31
+ end
32
+
33
+ def self.finalize(temp_files)
34
+ temp_files.each do |file|
35
+ File.delete(file) if File.exist?(file)
36
+ end
37
+ end
38
+
39
+ def add_file_reference(key, reference_path)
40
+
41
+ if reference_path.nil?
42
+ raise ArgumentError.new('The provided reference path is not valid')
43
+ end
44
+
45
+ unless File.exists?(reference_path)
46
+ raise ArgumentError.new('The provided reference file was not found')
47
+ end
48
+
49
+ @file_references[key] = reference_path
50
+ end
51
+
52
+ def add_trusted_root(root_path)
53
+
54
+ if root_path.nil?
55
+ raise ArgumentError.new('The provided trusted root path is not valid')
56
+ end
57
+
58
+ unless File.exists?(root_path)
59
+ raise ArgumentError.new("The provided trusted root path doesn't exist: #{root_path}")
60
+ end
61
+
62
+ @trusted_roots.append(root_path)
63
+ end
64
+
65
+ protected
66
+ def invoke_plain(command, args = [])
67
+ invoke(command, args, true)
68
+ end
69
+
70
+ def invoke(command, args = [], plain_output = false)
71
+
72
+ # Add PKI Express invocation arguments.
73
+ cmd_args = []
74
+ get_pki_express_invocation.each do |arg|
75
+ cmd_args.append(arg)
76
+ end
77
+
78
+ # Add PKI Express command.
79
+ cmd_args.append(command)
80
+
81
+ # Add PKI Express arguments.
82
+ cmd_args.concat args
83
+
84
+ # Add file references if added.
85
+ unless @file_references.nil?
86
+ @file_references.each do |key, value|
87
+ cmd_args.append('--file-reference')
88
+ cmd_args.append("#{key}=#{value}")
89
+ end
90
+ end
91
+
92
+ # Add trusted roots if added.
93
+ unless @trusted_roots.nil?
94
+ @trusted_roots.each do |trusted_root|
95
+ cmd_args.append('--trust-root')
96
+ cmd_args.append(trusted_root)
97
+ end
98
+ end
99
+
100
+ # Add trust Lacuna test root if set.
101
+ if @trust_lacuna_test_root
102
+ cmd_args.append('--trust-test')
103
+ end
104
+
105
+ # Add offline option if provided.
106
+ if @offline
107
+ cmd_args.append('--offline')
108
+ # This option can only be used on versions greater than 1.2 of the
109
+ # PKI Express.
110
+ @version_manager.require_version('1.2')
111
+ end
112
+
113
+ # Add base64 output option
114
+ unless plain_output
115
+ cmd_args.append('--base64')
116
+ end
117
+
118
+ unless @culture.nil?
119
+ cmd_args.append('--culture')
120
+ cmd_args.append(@culture)
121
+ # This option can only be used on versions
122
+ # greater than 1.10 of the PKI Express.
123
+ @version_manager.require_version('1.10')
124
+ end
125
+
126
+ unless @time_zone.nil?
127
+ cmd_args.append('--timezone')
128
+ cmd_args.append(@time_zone)
129
+ # This option can only be used on versions
130
+ # greater than 1.10 of the PKI Express.
131
+ @version_manager.require_version('1.10')
132
+ end
133
+
134
+ # Verify the necessity of using the --min-version flag.
135
+ if @version_manager.require_min_version_flag?
136
+ cmd_args.append('--min-version')
137
+ cmd_args.append(@version_manager.min_version.to_s)
138
+ end
139
+
140
+ # Escape command args
141
+ escaped = []
142
+ cmd_args.each do |arg|
143
+ escaped.append("\"#{arg}\"")
144
+ # escaped.append(Shellwords.escape(arg))
145
+ end
146
+
147
+ # Perform the "dotnet" command.
148
+ stdout, _stderr, status = Open3.capture3(escaped.join(' '))
149
+
150
+ if status != 0
151
+ if status === ErrorCodes::BAD_SYNTAX and @version_manager.min_version > '1.0'
152
+ raise CommandError.new(status, "#{stdout} >>>>> TIP: This operation requires PKI Express #{@version_manager.min_version}, please check your PKI Express version.")
153
+ end
154
+ if status === ErrorCodes::VALIDATION_FAILED
155
+ raise ValidationError.new(stdout)
156
+ end
157
+ if status === ErrorCodes::COMMAND_NOT_FOUND
158
+ raise InstallationNotFoundError.new("Could not find PKI Express's installation.")
159
+ end
160
+
161
+ raise CommandError.new(status, stdout)
162
+ end
163
+
164
+ # Return stdout if the command executed with success.
165
+ stdout
166
+ end
167
+
168
+ def get_pki_express_invocation
169
+
170
+ # Identify OS.
171
+ if (/linux/ =~ RUBY_PLATFORM) != nil
172
+ system = :linux
173
+ elsif (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
174
+ system = :win
175
+ else
176
+ raise Error.new("Unsupported OS: #{RUBY_PLATFORM}")
177
+ end
178
+
179
+ # Verify if hte PKI Express home is set on configuration
180
+ home = @config.pki_express_home
181
+ if not home.nil?
182
+
183
+ if system == :linux
184
+ unless File.exists?(File.expand_path('pkie.dll', home))
185
+ raise InstallationNotFoundError.new("The file pkie.dll could not be found on directory #{home}")
186
+ end
187
+ elsif not File.exists?(File.expand_path('pkie.exe', home))
188
+ raise InstallationNotFoundError.new("The file pkie.exe could not be found on directory #{home}")
189
+ end
190
+
191
+ elsif system == :win
192
+
193
+ if File.exists?(File.join(ENV['ProgramW6432'], 'Lacuna Software', 'PKI Express', 'pkie.exe'))
194
+ home = File.join(ENV['ProgramW6432'], 'Lacuna Software', 'PKI Express')
195
+ elsif File.exists?(File.join(ENV['ProgramFiles(x86)'], 'Lacuna Software', 'PKI Express', 'pkie.exe'))
196
+ home = File.join(ENV['ProgramFiles(x86)'], 'Lacuna Software', 'PKI Express')
197
+ elsif File.exists?(File.join(ENV['LOCALAPPDATA'], 'Lacuna Software', 'PKI Express', 'pkie.exe'))
198
+ home = File.join(ENV['LOCALAPPDATA'], 'Lacuna Software', 'PKI Express')
199
+ elsif File.exists?(File.join(ENV['LOCALAPPDATA'], 'Lacuna Software (x86)', 'PKI Express', 'pkie.exe'))
200
+ home = File.join(ENV['LOCALAPPDATA'], 'Lacuna Software (x86)', 'PKI Express')
201
+ end
202
+
203
+ if home.nil?
204
+ raise InstallationNotFoundError.new('Could not determine the
205
+ installation folder of PKI Express. If you installed PKI Express on
206
+ a custom folder, make sure your chosen folder are specified on the
207
+ PkiExpressConfig object.')
208
+ end
209
+ end
210
+
211
+ if system == :linux
212
+ unless home.nil?
213
+ return ['dotnet', File.expand_path('pkie.dll', home)]
214
+ end
215
+
216
+ return ['pkie']
217
+ end
218
+ [File.expand_path('pkie.exe', home)]
219
+ end
220
+
221
+ def parse_output(data_base64)
222
+ json_buff = Base64.decode64(data_base64)
223
+ JSON.parse(json_buff, symbolize_names: true)
224
+ end
225
+
226
+ def create_temp_file
227
+ file = Tempfile.new('pkie', @config.temp_folder)
228
+ temp_path = file.path
229
+ file.close
230
+ @temp_files.append(temp_path)
231
+ temp_path
232
+ end
233
+
234
+ def get_transfer_filename
235
+ # Generate 16 random bytes. Return a string containing the hex decimals of
236
+ # this array.
237
+ SecureRandom.hex(16)
238
+ end
239
+ end
240
+ end
@@ -1,16 +1,16 @@
1
- class PkiItalyCertificateFields
2
-
3
- attr_accessor :certificate_type, :codice_fiscale, :id_carta
4
-
5
- def initialize(model)
6
- @certificate_type = nil
7
- @codice_fiscale = nil
8
- @id_carta = nil
9
-
10
- unless model.nil?
11
- @certificate_type = model.fetch(:certificateType)
12
- @codice_fiscale = model.fetch(:codiceFiscale)
13
- @id_carta = model.fetch(:idCarta)
14
- end
15
- end
1
+ class PkiItalyCertificateFields
2
+
3
+ attr_accessor :certificate_type, :codice_fiscale, :id_carta
4
+
5
+ def initialize(model)
6
+ @certificate_type = nil
7
+ @codice_fiscale = nil
8
+ @id_carta = nil
9
+
10
+ unless model.nil?
11
+ @certificate_type = model.fetch(:certificateType)
12
+ @codice_fiscale = model.fetch(:codiceFiscale)
13
+ @id_carta = model.fetch(:idCarta)
14
+ end
15
+ end
16
16
  end
@@ -1,11 +1,11 @@
1
- module PkiExpress
2
- class PkiItalyCertificateTypes < Enum
3
- UNDEFINED = 'Undefined'
4
- CNS = 'Cns'
5
- DIGITAL_SIGNATURE = 'DigitalSignature'
6
-
7
- VALUES = [
8
- UNDEFINED, CNS, DIGITAL_SIGNATURE
9
- ]
10
- end
11
- end
1
+ module PkiExpress
2
+ class PkiItalyCertificateTypes < Enum
3
+ UNDEFINED = 'Undefined'
4
+ CNS = 'Cns'
5
+ DIGITAL_SIGNATURE = 'DigitalSignature'
6
+
7
+ VALUES = [
8
+ UNDEFINED, CNS, DIGITAL_SIGNATURE
9
+ ]
10
+ end
11
+ end
@@ -1,35 +1,35 @@
1
- module PkiExpress
2
-
3
- class SignatureAlgorithmAndValue
4
- attr_accessor :algorithm, :value
5
- def initialize(model)
6
- @algorithm = nil
7
- @value = nil
8
- algorithm_identifier = nil
9
-
10
- unless model.nil?
11
- value = model.fetch(:value)
12
- if value.nil?
13
- raise 'The value was not set'
14
- end
15
- @value = Base64.decode64(value).bytes
16
-
17
- algorithm_identifier = model.fetch(:algorithmIdentifier)
18
- if algorithm_identifier.nil?
19
- algorithm = model.fetch(:algorithm)
20
- unless algorithm.nil?
21
- @algorithm = DigestAlgorithm.get_instance_by_api_model(algorithm)
22
- end
23
- end
24
- end
25
- end
26
-
27
- def hex_value
28
- @value.map { |b| b.to_s(16).rjust(2,'0') }.join.upcase
29
- end
30
-
31
- def hex_value=(value)
32
- @value = [value].pack('H*').unpack('C*')
33
- end
34
- end
1
+ module PkiExpress
2
+
3
+ class SignatureAlgorithmAndValue
4
+ attr_accessor :algorithm, :value
5
+ def initialize(model)
6
+ @algorithm = nil
7
+ @value = nil
8
+ algorithm_identifier = nil
9
+
10
+ unless model.nil?
11
+ value = model.fetch(:value)
12
+ if value.nil?
13
+ raise 'The value was not set'
14
+ end
15
+ @value = Base64.decode64(value).bytes
16
+
17
+ algorithm_identifier = model.fetch(:algorithmIdentifier)
18
+ if algorithm_identifier.nil?
19
+ algorithm = model.fetch(:algorithm)
20
+ unless algorithm.nil?
21
+ @algorithm = DigestAlgorithm.get_instance_by_api_model(algorithm)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ def hex_value
28
+ @value.map { |b| b.to_s(16).rjust(2,'0') }.join.upcase
29
+ end
30
+
31
+ def hex_value=(value)
32
+ @value = [value].pack('H*').unpack('C*')
33
+ end
34
+ end
35
35
  end