rest_pki 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +6 -1
- data/lib/rest_pki.rb +32 -0
- data/lib/rest_pki/cades_signature.rb +52 -0
- data/lib/rest_pki/color.rb +37 -0
- data/lib/rest_pki/digest_algorithm.rb +158 -0
- data/lib/rest_pki/digest_algorithm_and_value.rb +29 -0
- data/lib/rest_pki/oids.rb +163 -0
- data/lib/rest_pki/pades_measurement_units.rb +6 -0
- data/lib/rest_pki/pades_page_orientation.rb +7 -0
- data/lib/rest_pki/pades_paper_size.rb +17 -0
- data/lib/rest_pki/pades_signature_explorer.rb +17 -0
- data/lib/rest_pki/pades_signer_info.rb +11 -0
- data/lib/rest_pki/pades_size.rb +17 -0
- data/lib/rest_pki/pades_visual_rectangle.rb +25 -0
- data/lib/rest_pki/page_optimization.rb +34 -0
- data/lib/rest_pki/pdf_container_definition.rb +266 -0
- data/lib/rest_pki/pdf_helper.rb +29 -0
- data/lib/rest_pki/pdf_mark.rb +81 -0
- data/lib/rest_pki/pdf_mark_element.rb +54 -0
- data/lib/rest_pki/pdf_mark_element_type.rb +7 -0
- data/lib/rest_pki/pdf_mark_image.rb +25 -0
- data/lib/rest_pki/pdf_mark_image_element.rb +33 -0
- data/lib/rest_pki/pdf_mark_page_options.rb +8 -0
- data/lib/rest_pki/pdf_mark_qr_code_element.rb +32 -0
- data/lib/rest_pki/pdf_mark_text_element.rb +47 -0
- data/lib/rest_pki/pdf_marker.rb +61 -0
- data/lib/rest_pki/pdf_text_section.rb +57 -0
- data/lib/rest_pki/pdf_text_style.rb +7 -0
- data/lib/rest_pki/pk_algorithms.rb +173 -0
- data/lib/rest_pki/pk_certificate.rb +99 -0
- data/lib/rest_pki/resource_content_or_reference.rb +25 -0
- data/lib/rest_pki/resources/pades_explorer_model.rb +12 -0
- data/lib/rest_pki/resources/pdf_marker_model.rb +12 -0
- data/lib/rest_pki/signature_algorithm_and_value.rb +11 -0
- data/lib/rest_pki/signature_explorer.rb +48 -0
- data/lib/rest_pki/signature_policy_identifier.rb +10 -0
- data/lib/rest_pki/validation_item.rb +2 -2
- data/lib/rest_pki/validation_results.rb +11 -11
- data/lib/rest_pki/version.rb +1 -1
- metadata +37 -3
@@ -0,0 +1,17 @@
|
|
1
|
+
module RestPki
|
2
|
+
PDF_MIME_TYPE = 'application/pdf'
|
3
|
+
class PadesSignatureExplorer < SignatureExplorer
|
4
|
+
def initialize(restpki_client)
|
5
|
+
super(restpki_client)
|
6
|
+
end
|
7
|
+
|
8
|
+
def open()
|
9
|
+
if @signature_file_content.to_s.empty?
|
10
|
+
raise 'The signature file to be opened not set'
|
11
|
+
end
|
12
|
+
|
13
|
+
request = get_request(PDF_MIME_TYPE)
|
14
|
+
@restpki_client.post('Api/PadesSignatures/Open', request, 'pades_explorer_model')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RestPki
|
2
|
+
class PadesSignerInfo < CadesSignerInfo
|
3
|
+
attr_reader :is_document_timestamp, :signature_fie_id_name
|
4
|
+
|
5
|
+
def initialize(model)
|
6
|
+
super(model)
|
7
|
+
@is_document_timestamp = model['isDocumentTimestamp']
|
8
|
+
@signature_fie_id_name = model['signatureFieldName']
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RestPki
|
2
|
+
class PadesVisualRectangle
|
3
|
+
attr_accessor :left, :right, :top, :bottom, :width, :height
|
4
|
+
|
5
|
+
def initialize()
|
6
|
+
@left = nil
|
7
|
+
@top = nil
|
8
|
+
@right = nil
|
9
|
+
@bottom = nil
|
10
|
+
@width = nil
|
11
|
+
@height = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_model()
|
15
|
+
return {
|
16
|
+
left: @left,
|
17
|
+
top: @top,
|
18
|
+
right: @right,
|
19
|
+
bottom: @bottom,
|
20
|
+
width: @width,
|
21
|
+
height: @height
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RestPki
|
2
|
+
class PageOptimization
|
3
|
+
attr_accessor :paper_size, :page_orientation
|
4
|
+
attr_reader :custom_paper_size
|
5
|
+
|
6
|
+
def initialize(paper_size = nil, custom_paper_size = nil, page_orientation = nil)
|
7
|
+
@paper_size = paper_size
|
8
|
+
@page_orientation = page_orientation
|
9
|
+
unless custom_paper_size.nil?
|
10
|
+
@custom_paper_size = PadesSize.new(custom_paper_size.width, custom_paper_size.height)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def custom_paper_size=(value)
|
15
|
+
@custom_paper_size = value
|
16
|
+
@paper_size = PadesPaperSize::CUSTOM
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_model
|
20
|
+
custom_paper_size = nil
|
21
|
+
if @paper_size.equal?(PadesPaperSize::CUSTOM)
|
22
|
+
if @custom_paper_size.nil?
|
23
|
+
raise 'The custom paper size parameters was not provided'
|
24
|
+
end
|
25
|
+
custom_paper_size = @custom_paper_size.to_model
|
26
|
+
end
|
27
|
+
{
|
28
|
+
paperSize: @paper_size,
|
29
|
+
customPaperSize: custom_paper_size,
|
30
|
+
pageOrientation: @page_orientation,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,266 @@
|
|
1
|
+
module RestPki
|
2
|
+
class PdfContainerDefinition
|
3
|
+
attr_reader :container
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@container = PadesVisualRectangle.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def width(value)
|
10
|
+
@container.width = value
|
11
|
+
FixedWidth.new(@container)
|
12
|
+
end
|
13
|
+
|
14
|
+
def var_width
|
15
|
+
VarWidth.new(@container)
|
16
|
+
end
|
17
|
+
|
18
|
+
def full_width
|
19
|
+
@container.left = 0.0
|
20
|
+
@container.right = 0.0
|
21
|
+
WidthDefined.new(@container)
|
22
|
+
end
|
23
|
+
|
24
|
+
def height(value)
|
25
|
+
@container.height = value
|
26
|
+
FixedHeight.new(@container)
|
27
|
+
end
|
28
|
+
|
29
|
+
def var_height
|
30
|
+
VarHeight.new(@container)
|
31
|
+
end
|
32
|
+
|
33
|
+
def full_height
|
34
|
+
@container.top = 0.0
|
35
|
+
@container.bottom = 0.0
|
36
|
+
HeightDefined.new(@container)
|
37
|
+
end
|
38
|
+
|
39
|
+
def var_width_and_height
|
40
|
+
VarWidthAndHeight.new(@container)
|
41
|
+
end
|
42
|
+
|
43
|
+
def full
|
44
|
+
@container.top = 0.0
|
45
|
+
@container.right = 0.0
|
46
|
+
@container.bottom = 0.0
|
47
|
+
@container.left = 0.0
|
48
|
+
@container
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class FixedWidth
|
53
|
+
|
54
|
+
def initialize(container)
|
55
|
+
@container = container
|
56
|
+
end
|
57
|
+
|
58
|
+
def anchor_left(margin=0.0)
|
59
|
+
@container.left = margin
|
60
|
+
WidthDefined.new(@container)
|
61
|
+
end
|
62
|
+
|
63
|
+
def anchor_right(margin=0.0)
|
64
|
+
@container.right = margin
|
65
|
+
WidthDefined.new(@container)
|
66
|
+
end
|
67
|
+
|
68
|
+
def center
|
69
|
+
WidthDefined.new(@container)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class VarWidth
|
74
|
+
|
75
|
+
def initialize(container)
|
76
|
+
@container = container
|
77
|
+
end
|
78
|
+
|
79
|
+
def margins(left_margin, right_margin=nil)
|
80
|
+
if right_margin.nil?
|
81
|
+
right_margin = left_margin
|
82
|
+
end
|
83
|
+
@container.left = left_margin
|
84
|
+
@container.right = right_margin
|
85
|
+
WidthDefined.new(@container)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class FixedHeight
|
90
|
+
|
91
|
+
def initialize(container)
|
92
|
+
@container = container
|
93
|
+
end
|
94
|
+
|
95
|
+
def anchor_top(margin=0.0)
|
96
|
+
@container.top = margin
|
97
|
+
HeightDefined.new(@container)
|
98
|
+
end
|
99
|
+
|
100
|
+
def anchor_bottom(margin=0.0)
|
101
|
+
@container.bottom = margin
|
102
|
+
HeightDefined.new(@container)
|
103
|
+
end
|
104
|
+
|
105
|
+
def center
|
106
|
+
HeightDefined.new(@container)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class VarHeight
|
111
|
+
|
112
|
+
def initialize(container)
|
113
|
+
@container = container
|
114
|
+
end
|
115
|
+
|
116
|
+
def margins(top_margin, bottom_margin=nil)
|
117
|
+
if bottom_margin.nil?
|
118
|
+
bottom_margin = top_margin
|
119
|
+
end
|
120
|
+
@container.top = top_margin
|
121
|
+
@container.bottom = bottom_margin
|
122
|
+
HeightDefined.new(@container)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class WidthDefined
|
127
|
+
def initialize(container)
|
128
|
+
@container = container
|
129
|
+
end
|
130
|
+
|
131
|
+
def height(value)
|
132
|
+
@container.height = value
|
133
|
+
WidthDefinedFixedHeight.new(@container)
|
134
|
+
end
|
135
|
+
|
136
|
+
def var_height
|
137
|
+
WidthDefinedVarHeight.new(@container)
|
138
|
+
end
|
139
|
+
|
140
|
+
def full_height
|
141
|
+
@container.top = 0.0
|
142
|
+
@container.bottom = 0.0
|
143
|
+
@container
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class HeightDefined
|
148
|
+
def initialize(container)
|
149
|
+
@container = container
|
150
|
+
end
|
151
|
+
|
152
|
+
def width(value)
|
153
|
+
@container.width = value
|
154
|
+
HeightDefinedFixedWidth.new(@container)
|
155
|
+
end
|
156
|
+
|
157
|
+
def var_width
|
158
|
+
HeightDefinedVarWidth.new(@container)
|
159
|
+
end
|
160
|
+
|
161
|
+
def full_width
|
162
|
+
@container.left = 0.0
|
163
|
+
@container.right = 0.0
|
164
|
+
@container
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class WidthDefinedFixedHeight
|
169
|
+
|
170
|
+
def initialize(container)
|
171
|
+
@container = container
|
172
|
+
end
|
173
|
+
|
174
|
+
def anchor_top(margin=0.0)
|
175
|
+
@container.top = margin
|
176
|
+
@container
|
177
|
+
end
|
178
|
+
|
179
|
+
def anchor_bottom(margin=0.0)
|
180
|
+
@container.bottom = margin
|
181
|
+
@container
|
182
|
+
end
|
183
|
+
|
184
|
+
def center
|
185
|
+
@container
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
class WidthDefinedVarHeight
|
190
|
+
|
191
|
+
def initialize(container)
|
192
|
+
@container = container
|
193
|
+
end
|
194
|
+
|
195
|
+
def margins(top_margin, bottom_margin=nil)
|
196
|
+
if bottom_margin.nil?
|
197
|
+
bottom_margin = top_margin
|
198
|
+
end
|
199
|
+
@container.top = top_margin
|
200
|
+
@container.bottom = bottom_margin
|
201
|
+
@container
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class HeightDefinedFixedWidth
|
206
|
+
|
207
|
+
def initialize(container)
|
208
|
+
@container = container
|
209
|
+
end
|
210
|
+
|
211
|
+
def anchor_left(margin=0.0)
|
212
|
+
@container.left = margin
|
213
|
+
@container
|
214
|
+
end
|
215
|
+
|
216
|
+
def anchor_right(margin=0.0)
|
217
|
+
@container.right = margin
|
218
|
+
@container
|
219
|
+
end
|
220
|
+
|
221
|
+
def center
|
222
|
+
@container
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class HeightDefinedVarWidth
|
227
|
+
|
228
|
+
def initialize(container)
|
229
|
+
@container = container
|
230
|
+
end
|
231
|
+
|
232
|
+
def margins(left_margin, right_margin=nil)
|
233
|
+
if right_margin.nil?
|
234
|
+
right_margin = left_margin
|
235
|
+
end
|
236
|
+
@container.left = left_margin
|
237
|
+
@container.right = right_margin
|
238
|
+
@container
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
class VarWidthAndHeight
|
243
|
+
|
244
|
+
def initialize(container)
|
245
|
+
@container = container
|
246
|
+
end
|
247
|
+
|
248
|
+
def margins(top_margin, right_margin=nil, bottom_margin=nil, left_margin=nil)
|
249
|
+
if right_margin.nil?
|
250
|
+
right_margin = top_margin
|
251
|
+
end
|
252
|
+
if bottom_margin.nil?
|
253
|
+
bottom_margin = top_margin
|
254
|
+
end
|
255
|
+
if left_margin.nil?
|
256
|
+
left_margin = right_margin
|
257
|
+
end
|
258
|
+
@container.top = top_margin
|
259
|
+
@container.right = right_margin
|
260
|
+
@container.left = left_margin
|
261
|
+
@container.bottom = bottom_margin
|
262
|
+
@container
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RestPki
|
2
|
+
class PdfHelper
|
3
|
+
def initialize; end
|
4
|
+
|
5
|
+
def container
|
6
|
+
PdfContainerDefinition.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def mark
|
10
|
+
PdfMark.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def text_element
|
14
|
+
PdfMarkTextElement.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def image_element
|
18
|
+
PdfMarkImageElement.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def qr_code_element
|
22
|
+
PdfMarkQRCodeElement.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def text_section(text=nil)
|
26
|
+
PdfTextSection.new(text)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module RestPki
|
2
|
+
class PdfMark
|
3
|
+
attr_accessor :container, :border_width, :border_color, :background_color, :page_option, :page_option_number
|
4
|
+
attr_reader :elements
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@container = nil
|
8
|
+
@border_width = 0.0
|
9
|
+
@border_color = Color.from_rgb_string('#000000') # Black
|
10
|
+
@background_color = Color.from_rgb_string('#FFFFFF', 0) # Transparent
|
11
|
+
@elements = []
|
12
|
+
@page_option = PdfMarkPageOptions::ALL_PAGES
|
13
|
+
@page_option_number = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_model
|
17
|
+
elements = @elements.map { |e| e.to_model }
|
18
|
+
|
19
|
+
{
|
20
|
+
container: @container,
|
21
|
+
backgroundColor: @background_color.to_model,
|
22
|
+
borderColor: @border_color.to_model,
|
23
|
+
borderWidth: @border_width,
|
24
|
+
elements: elements,
|
25
|
+
pageOption: @page_option,
|
26
|
+
pageOptionNumber: @page_option_number,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
#region FluentApi
|
31
|
+
|
32
|
+
def on_container(container)
|
33
|
+
@container = container
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_border_width(border_width)
|
38
|
+
@border_width = border_width
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_all_pages
|
43
|
+
@page_option = PdfMarkPageOptions::ALL_PAGES
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_new_page
|
48
|
+
@page_option = PdfMarkPageOptions::NEW_PAGE
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def on_single_page(page_number)
|
53
|
+
@page_option = PdfMarkPageOptions::SINGLE_PAGE
|
54
|
+
@page_option_number = page_number
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_single_page_from_end(page_number)
|
59
|
+
@page_option = PdfMarkPageOptions::SINGLE_PAGE_FROM_END
|
60
|
+
@page_option_number = page_number
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
def add_element(element)
|
65
|
+
@elements.push(element)
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def with_border_color(border_color)
|
70
|
+
@border_color = border_color
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
def with_background_color(background_color)
|
75
|
+
@background_color = background_color
|
76
|
+
self
|
77
|
+
end
|
78
|
+
#endregion
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|