pki_express 1.3.0 → 1.3.2

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