1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
%global _empty_manifest_terminate_build 0
Name: python-pysisl
Version: 0.0.11
Release: 1
Summary: A python library for serialising and deserialising SISL (Simple Information Serialization Language)
License: MIT License
URL: https://github.com/oakdoor
Source0: https://mirrors.aliyun.com/pypi/web/packages/de/c4/8c9ff6b24c60b7d4b689ea1164a74bb7eae45ecd0a1c22631e6aeb32d055/pysisl-0.0.11.tar.gz
BuildArch: noarch
Requires: python3-ply
Requires: python3-jsonschema
Requires: python3-deepmerge
Requires: python3-mergedeep
Requires: python3-construct
%description
# pySISL
A Python library for serialising and deserialising SISL (Simple Information Serialization Language). SISL is a simple structured text format designed for use in the [NCSC Safely Importing Data Pattern](https://www.ncsc.gov.uk/guidance/pattern-safely-importing-data). This library provides the ability to serialise and deserialise SISL as well as perform semantic verification of the SISL.
Hardware enforced syntatic verification may be carried out by the [Oakdoor<sup>TM</sup> family of data diodes](https://www.oakdoor.io/products/oakdoor-data-diodes/).
Also provides the functionality to wrap and unwrap files with an XOR scrambling technique used on the Oakdoor<sup>TM</sup> data diodes which is designed to render files inert if they fail the syntatic verification allowing the file to be safely transported or stored for later unwrapping and inspection.
## Examples
Encoding basic Python object to SISL:
>>> import pysisl
>>> pysisl.dumps({"hello": "world"})
'{hello: !str "world"}'
>>> pysisl.dumps({"name": "helpful_name", "flag": False, "count": 3})
'{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
Decoding SISL to Python:
>>> import pysisl
>>> pysisl.loads('{name: !str "helpful_name", flag: !bool "false", count: !int "3"}')
{'name': 'helpful_name', 'flag': False, 'count': 3}
## Basic Usage
pysisl.dumps(obj)
Serialise a basic Python object into a SISL formatted str.
pysisl.loads(sisl, schema=None)
Deserialise SISL str to a basic Python object. Optionally, verify the SISL schema using a json schema.
pysisl.SislWrapper().wraps(data)
Applies an XOR data scrambling technique to wrap and render data inert, equivalent to the Oakdoor<sup>TM</sup> data diode hardware. The data must be bytes() or bytearray(). The XOR key is internally generated and prepended as part of a header.
pysisl.SislWrapper().unwraps(data)
Unwraps data scrambled with the above XOR data scrambling technique. The data must be bytes() or bytearray().
See the [conversion](#conversion-table) table on this page for more details.
### Splitting large objects into multiple SISL files
pySISL supports a maximum length in bytes for SISL files. If the input Python object exceeds this max length it is split into multiple SISL files. A Python list is returned where each item is a SISL string.
#### Split an object into SISL with max bytes as 20
>>> import pysisl
>>> pysisl.dumps({"abc": 2, "def": 3}, max_length=20)
['{abc: !int "2"}', '{def: !int "3"}']
### Joining multiple SISL files to form a single Python object
If a SISL file has been split in the way described above, pySISL supports joining the split files into a single Python object. When a list of SISL strings is passed to pySISL.loads(), this joining is done by default. A single Python dictionary is returned. Joining is done by merging nesting structures of arbitrary depth, while maintaining order.
>>> import pysisl
>>> pysisl.loads(['{abc: !list {_0: !str "I", _1: !list {_0: !str "am"}}}',
'{abc: !list {_1: !list {_1: !str "a"}, _2: !str "list"}}'])
{"abc": ['I', ['am', 'a'], 'list']}
>>> pysisl.loads(['{abc: !list {_0: !str "I", _1: !list {_0: !str "am"}}}',
'{abc: !list {_2: !list {_0: !str "a"}, _3: !str "list"}}'])
{"abc": ['I', ['am'], ['a'], 'list']}
### Semantic Verification with a Schema
The [jsonschema](https://pypi.org/project/jsonschema/) library is used to optionally verify the parsed SISL data structure. See [JSON Schema](https://json-schema.org/) for details on the json schema syntax. For example
#### Successful Parsing
>>> import pysisl
>>> my_schema = {
"properties": {
"name": {
"type": "string"
},
"flag": {
"type": "boolean"
},
"count": {
"type": "number"
}
}
}
>>> decode_example = '{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
>>> pysisl.loads(decode_example, my_schema)
{'name': 'helpful_name', 'flag': False, 'count': 3}
#### Schema Verification Fails
>>> import pysisl
>>> my_schema = {
"properties": {
"name": {
"type": "string"
},
"flag": {
"type": "boolean"
},
"count": {
"type": "string"
}
}
}
>>> decode_example = '{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
>>> pysisl.loads(decode_example, my_schema)
Traceback (most recent call last):
File "/home/vagrant/pysisl/pysisl/sisl_decoder.py", line 31, in _verify_schema_if_required
json_validator(flattened_sisl, schema=schema, format_checker=FormatChecker())
File "/home/vagrant/pysisl/venv/lib64/python3.6/site-packages/jsonschema/validators.py", line 934, in validate
raise error
jsonschema.exceptions.ValidationError: 3 is not of type 'string'
Failed validating 'type' in schema['properties']['count']:
{'type': 'string'}
#### Conversion table
| Python | SISL |
| ------ | ---- |
| dict | obj |
| list | list |
| str | str |
| int | int |
| float | float|
| bool | bool |
| None | null |
## Background
The [NCSC Safely Importing Data Pattern](https://www.ncsc.gov.uk/guidance/pattern-safely-importing-data), an architecture pattern describes a safe mechanism for handling structured data from an external untrusted source. We use a Transform - Verify approach taking our source data, transforming to an intermediate format, inspecting the intermediate format and then transforming back to the original format. SISL was designed to be a simple and easily inspectable intermediate format for just such an approach.
Oakdoor<sup>TM</sup> products enable one- or two-way data transfers between segregated networks, letting organisations safely run services, such as file transfer, protocol exchanges, secure internet browsing and systems management. This is done using a combination of hardware enforced verification and software.
pySISL can form part of the transformation engine sub-system that enables cross-network communication that is compatible with the NCSC Safely importing data pattern. The pySISL encoder can be used to convert complex Python dictionaries into valid SISL that is compatible with the diodes and the decoder will convert the SISL back into the same dictionaries without loss of data.
## License
MIT licence
## SISL Specification
For reference, this is ABNF for SISL.
sislfile = grouping *255wsp
grouping = "{" ( (*255wsp collection *255wsp ) / *255wsp ) "}"
collection = element *("," *255wsp element)
element = name ":" 1*255wsp "!" type 1*255wsp value
name = ( "_" / ALPHA ) *( "_" / "-" / "." / ALPHA / DIGIT )
type = ( "_" / ALPHA ) *254( "_" / "-" / "." / ALPHA / DIGIT )
value = ( DQUOTE *( printable / escape) DQUOTE ) / grouping
escape = "\" ( lcr / lct / lcn / DQUOTE / "\" / (lcx 2HEXDIG) / (lcu 4HEXDIG) / (ucu 8HEXDIG) )
wsp = SP / HTAB / CR / LF
printable = %x20-21 / %x23-5B / %x5D-7E ; Printable chars apart from '"' or '\'
lcr = %x72 ; lower case r
lct = %x74 ; lower case t
lcn = %x6E ; lower case n
lcx = %x78 ; lower case x
lcu = %x75 ; lower case u
ucu = %x55 ; upper case u
; Core rules
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
DQUOTE = %x22 ; " (double-quote)
SP = %x20 ; space
HTAB = %x09 ; horizontal tab
CR = %x0D ; carriage return
LF = %x0A ; line feed
## Getting Help
If you need help using the pySISL module, please contact Oakdoor<sup>TM</sup> support at oakdoor.support@paconsulting.com.
## Examples
|Type | Python |SISL |
|--------------------|-------------------------------------------|--------------------------------------------------------------------|
| Dictionary | `{"field_one": {"key_one": "teststring"}}`| `'{"field_one": !obj {"key_one": !str "teststring"}}'` |
| List | `{"field_one": [1, 2, 3]}` | `'{"field_one": !list {_0: !int "1", _1: !int "2", _2: !int "3"}}'`|
| Anonymous list | `[1, 2, 3]` | `'{"_": !_list {_0: !int "1", _1: !int "2", _2: !int "3"}}'` |
| String | `{"field_one": "teststring"}` | `'{"field_one": !str "teststring"}'` |
| Anonymous string | `"teststring"` | `'{"_": !_str "teststring"}'` |
| Int | `{"field_one": 1}` | `'{"field_one": !int "1"}'` |
| Anonymous int | `1` | `'{"_": !_int "1"}'` |
| Float | `{"field_one": 5.3}` | `'{"field_one": !float "5.3"}'` |
| Anonymous float | `5.3` | `'{"_": !_float "5.3"}'` |
| Bool | `{"field_one": True}` | `'{"field_one": !bool "true"}'` |
| Anonymous bool | `True` | `'{"_": !_bool "true"}'` |
| None | `{"field_one": None}` | `'{"field_one": !null ""}'` |
| Anonymous none | `None` | `'{"_": !_null ""}'` |
## Contributing to pySISL
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
If you notice a bug or would like to make an update to pySISL, please open an issue or raise a pull request.
%package -n python3-pysisl
Summary: A python library for serialising and deserialising SISL (Simple Information Serialization Language)
Provides: python-pysisl
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-pip
%description -n python3-pysisl
# pySISL
A Python library for serialising and deserialising SISL (Simple Information Serialization Language). SISL is a simple structured text format designed for use in the [NCSC Safely Importing Data Pattern](https://www.ncsc.gov.uk/guidance/pattern-safely-importing-data). This library provides the ability to serialise and deserialise SISL as well as perform semantic verification of the SISL.
Hardware enforced syntatic verification may be carried out by the [Oakdoor<sup>TM</sup> family of data diodes](https://www.oakdoor.io/products/oakdoor-data-diodes/).
Also provides the functionality to wrap and unwrap files with an XOR scrambling technique used on the Oakdoor<sup>TM</sup> data diodes which is designed to render files inert if they fail the syntatic verification allowing the file to be safely transported or stored for later unwrapping and inspection.
## Examples
Encoding basic Python object to SISL:
>>> import pysisl
>>> pysisl.dumps({"hello": "world"})
'{hello: !str "world"}'
>>> pysisl.dumps({"name": "helpful_name", "flag": False, "count": 3})
'{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
Decoding SISL to Python:
>>> import pysisl
>>> pysisl.loads('{name: !str "helpful_name", flag: !bool "false", count: !int "3"}')
{'name': 'helpful_name', 'flag': False, 'count': 3}
## Basic Usage
pysisl.dumps(obj)
Serialise a basic Python object into a SISL formatted str.
pysisl.loads(sisl, schema=None)
Deserialise SISL str to a basic Python object. Optionally, verify the SISL schema using a json schema.
pysisl.SislWrapper().wraps(data)
Applies an XOR data scrambling technique to wrap and render data inert, equivalent to the Oakdoor<sup>TM</sup> data diode hardware. The data must be bytes() or bytearray(). The XOR key is internally generated and prepended as part of a header.
pysisl.SislWrapper().unwraps(data)
Unwraps data scrambled with the above XOR data scrambling technique. The data must be bytes() or bytearray().
See the [conversion](#conversion-table) table on this page for more details.
### Splitting large objects into multiple SISL files
pySISL supports a maximum length in bytes for SISL files. If the input Python object exceeds this max length it is split into multiple SISL files. A Python list is returned where each item is a SISL string.
#### Split an object into SISL with max bytes as 20
>>> import pysisl
>>> pysisl.dumps({"abc": 2, "def": 3}, max_length=20)
['{abc: !int "2"}', '{def: !int "3"}']
### Joining multiple SISL files to form a single Python object
If a SISL file has been split in the way described above, pySISL supports joining the split files into a single Python object. When a list of SISL strings is passed to pySISL.loads(), this joining is done by default. A single Python dictionary is returned. Joining is done by merging nesting structures of arbitrary depth, while maintaining order.
>>> import pysisl
>>> pysisl.loads(['{abc: !list {_0: !str "I", _1: !list {_0: !str "am"}}}',
'{abc: !list {_1: !list {_1: !str "a"}, _2: !str "list"}}'])
{"abc": ['I', ['am', 'a'], 'list']}
>>> pysisl.loads(['{abc: !list {_0: !str "I", _1: !list {_0: !str "am"}}}',
'{abc: !list {_2: !list {_0: !str "a"}, _3: !str "list"}}'])
{"abc": ['I', ['am'], ['a'], 'list']}
### Semantic Verification with a Schema
The [jsonschema](https://pypi.org/project/jsonschema/) library is used to optionally verify the parsed SISL data structure. See [JSON Schema](https://json-schema.org/) for details on the json schema syntax. For example
#### Successful Parsing
>>> import pysisl
>>> my_schema = {
"properties": {
"name": {
"type": "string"
},
"flag": {
"type": "boolean"
},
"count": {
"type": "number"
}
}
}
>>> decode_example = '{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
>>> pysisl.loads(decode_example, my_schema)
{'name': 'helpful_name', 'flag': False, 'count': 3}
#### Schema Verification Fails
>>> import pysisl
>>> my_schema = {
"properties": {
"name": {
"type": "string"
},
"flag": {
"type": "boolean"
},
"count": {
"type": "string"
}
}
}
>>> decode_example = '{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
>>> pysisl.loads(decode_example, my_schema)
Traceback (most recent call last):
File "/home/vagrant/pysisl/pysisl/sisl_decoder.py", line 31, in _verify_schema_if_required
json_validator(flattened_sisl, schema=schema, format_checker=FormatChecker())
File "/home/vagrant/pysisl/venv/lib64/python3.6/site-packages/jsonschema/validators.py", line 934, in validate
raise error
jsonschema.exceptions.ValidationError: 3 is not of type 'string'
Failed validating 'type' in schema['properties']['count']:
{'type': 'string'}
#### Conversion table
| Python | SISL |
| ------ | ---- |
| dict | obj |
| list | list |
| str | str |
| int | int |
| float | float|
| bool | bool |
| None | null |
## Background
The [NCSC Safely Importing Data Pattern](https://www.ncsc.gov.uk/guidance/pattern-safely-importing-data), an architecture pattern describes a safe mechanism for handling structured data from an external untrusted source. We use a Transform - Verify approach taking our source data, transforming to an intermediate format, inspecting the intermediate format and then transforming back to the original format. SISL was designed to be a simple and easily inspectable intermediate format for just such an approach.
Oakdoor<sup>TM</sup> products enable one- or two-way data transfers between segregated networks, letting organisations safely run services, such as file transfer, protocol exchanges, secure internet browsing and systems management. This is done using a combination of hardware enforced verification and software.
pySISL can form part of the transformation engine sub-system that enables cross-network communication that is compatible with the NCSC Safely importing data pattern. The pySISL encoder can be used to convert complex Python dictionaries into valid SISL that is compatible with the diodes and the decoder will convert the SISL back into the same dictionaries without loss of data.
## License
MIT licence
## SISL Specification
For reference, this is ABNF for SISL.
sislfile = grouping *255wsp
grouping = "{" ( (*255wsp collection *255wsp ) / *255wsp ) "}"
collection = element *("," *255wsp element)
element = name ":" 1*255wsp "!" type 1*255wsp value
name = ( "_" / ALPHA ) *( "_" / "-" / "." / ALPHA / DIGIT )
type = ( "_" / ALPHA ) *254( "_" / "-" / "." / ALPHA / DIGIT )
value = ( DQUOTE *( printable / escape) DQUOTE ) / grouping
escape = "\" ( lcr / lct / lcn / DQUOTE / "\" / (lcx 2HEXDIG) / (lcu 4HEXDIG) / (ucu 8HEXDIG) )
wsp = SP / HTAB / CR / LF
printable = %x20-21 / %x23-5B / %x5D-7E ; Printable chars apart from '"' or '\'
lcr = %x72 ; lower case r
lct = %x74 ; lower case t
lcn = %x6E ; lower case n
lcx = %x78 ; lower case x
lcu = %x75 ; lower case u
ucu = %x55 ; upper case u
; Core rules
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
DQUOTE = %x22 ; " (double-quote)
SP = %x20 ; space
HTAB = %x09 ; horizontal tab
CR = %x0D ; carriage return
LF = %x0A ; line feed
## Getting Help
If you need help using the pySISL module, please contact Oakdoor<sup>TM</sup> support at oakdoor.support@paconsulting.com.
## Examples
|Type | Python |SISL |
|--------------------|-------------------------------------------|--------------------------------------------------------------------|
| Dictionary | `{"field_one": {"key_one": "teststring"}}`| `'{"field_one": !obj {"key_one": !str "teststring"}}'` |
| List | `{"field_one": [1, 2, 3]}` | `'{"field_one": !list {_0: !int "1", _1: !int "2", _2: !int "3"}}'`|
| Anonymous list | `[1, 2, 3]` | `'{"_": !_list {_0: !int "1", _1: !int "2", _2: !int "3"}}'` |
| String | `{"field_one": "teststring"}` | `'{"field_one": !str "teststring"}'` |
| Anonymous string | `"teststring"` | `'{"_": !_str "teststring"}'` |
| Int | `{"field_one": 1}` | `'{"field_one": !int "1"}'` |
| Anonymous int | `1` | `'{"_": !_int "1"}'` |
| Float | `{"field_one": 5.3}` | `'{"field_one": !float "5.3"}'` |
| Anonymous float | `5.3` | `'{"_": !_float "5.3"}'` |
| Bool | `{"field_one": True}` | `'{"field_one": !bool "true"}'` |
| Anonymous bool | `True` | `'{"_": !_bool "true"}'` |
| None | `{"field_one": None}` | `'{"field_one": !null ""}'` |
| Anonymous none | `None` | `'{"_": !_null ""}'` |
## Contributing to pySISL
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
If you notice a bug or would like to make an update to pySISL, please open an issue or raise a pull request.
%package help
Summary: Development documents and examples for pysisl
Provides: python3-pysisl-doc
%description help
# pySISL
A Python library for serialising and deserialising SISL (Simple Information Serialization Language). SISL is a simple structured text format designed for use in the [NCSC Safely Importing Data Pattern](https://www.ncsc.gov.uk/guidance/pattern-safely-importing-data). This library provides the ability to serialise and deserialise SISL as well as perform semantic verification of the SISL.
Hardware enforced syntatic verification may be carried out by the [Oakdoor<sup>TM</sup> family of data diodes](https://www.oakdoor.io/products/oakdoor-data-diodes/).
Also provides the functionality to wrap and unwrap files with an XOR scrambling technique used on the Oakdoor<sup>TM</sup> data diodes which is designed to render files inert if they fail the syntatic verification allowing the file to be safely transported or stored for later unwrapping and inspection.
## Examples
Encoding basic Python object to SISL:
>>> import pysisl
>>> pysisl.dumps({"hello": "world"})
'{hello: !str "world"}'
>>> pysisl.dumps({"name": "helpful_name", "flag": False, "count": 3})
'{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
Decoding SISL to Python:
>>> import pysisl
>>> pysisl.loads('{name: !str "helpful_name", flag: !bool "false", count: !int "3"}')
{'name': 'helpful_name', 'flag': False, 'count': 3}
## Basic Usage
pysisl.dumps(obj)
Serialise a basic Python object into a SISL formatted str.
pysisl.loads(sisl, schema=None)
Deserialise SISL str to a basic Python object. Optionally, verify the SISL schema using a json schema.
pysisl.SislWrapper().wraps(data)
Applies an XOR data scrambling technique to wrap and render data inert, equivalent to the Oakdoor<sup>TM</sup> data diode hardware. The data must be bytes() or bytearray(). The XOR key is internally generated and prepended as part of a header.
pysisl.SislWrapper().unwraps(data)
Unwraps data scrambled with the above XOR data scrambling technique. The data must be bytes() or bytearray().
See the [conversion](#conversion-table) table on this page for more details.
### Splitting large objects into multiple SISL files
pySISL supports a maximum length in bytes for SISL files. If the input Python object exceeds this max length it is split into multiple SISL files. A Python list is returned where each item is a SISL string.
#### Split an object into SISL with max bytes as 20
>>> import pysisl
>>> pysisl.dumps({"abc": 2, "def": 3}, max_length=20)
['{abc: !int "2"}', '{def: !int "3"}']
### Joining multiple SISL files to form a single Python object
If a SISL file has been split in the way described above, pySISL supports joining the split files into a single Python object. When a list of SISL strings is passed to pySISL.loads(), this joining is done by default. A single Python dictionary is returned. Joining is done by merging nesting structures of arbitrary depth, while maintaining order.
>>> import pysisl
>>> pysisl.loads(['{abc: !list {_0: !str "I", _1: !list {_0: !str "am"}}}',
'{abc: !list {_1: !list {_1: !str "a"}, _2: !str "list"}}'])
{"abc": ['I', ['am', 'a'], 'list']}
>>> pysisl.loads(['{abc: !list {_0: !str "I", _1: !list {_0: !str "am"}}}',
'{abc: !list {_2: !list {_0: !str "a"}, _3: !str "list"}}'])
{"abc": ['I', ['am'], ['a'], 'list']}
### Semantic Verification with a Schema
The [jsonschema](https://pypi.org/project/jsonschema/) library is used to optionally verify the parsed SISL data structure. See [JSON Schema](https://json-schema.org/) for details on the json schema syntax. For example
#### Successful Parsing
>>> import pysisl
>>> my_schema = {
"properties": {
"name": {
"type": "string"
},
"flag": {
"type": "boolean"
},
"count": {
"type": "number"
}
}
}
>>> decode_example = '{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
>>> pysisl.loads(decode_example, my_schema)
{'name': 'helpful_name', 'flag': False, 'count': 3}
#### Schema Verification Fails
>>> import pysisl
>>> my_schema = {
"properties": {
"name": {
"type": "string"
},
"flag": {
"type": "boolean"
},
"count": {
"type": "string"
}
}
}
>>> decode_example = '{name: !str "helpful_name", flag: !bool "false", count: !int "3"}'
>>> pysisl.loads(decode_example, my_schema)
Traceback (most recent call last):
File "/home/vagrant/pysisl/pysisl/sisl_decoder.py", line 31, in _verify_schema_if_required
json_validator(flattened_sisl, schema=schema, format_checker=FormatChecker())
File "/home/vagrant/pysisl/venv/lib64/python3.6/site-packages/jsonschema/validators.py", line 934, in validate
raise error
jsonschema.exceptions.ValidationError: 3 is not of type 'string'
Failed validating 'type' in schema['properties']['count']:
{'type': 'string'}
#### Conversion table
| Python | SISL |
| ------ | ---- |
| dict | obj |
| list | list |
| str | str |
| int | int |
| float | float|
| bool | bool |
| None | null |
## Background
The [NCSC Safely Importing Data Pattern](https://www.ncsc.gov.uk/guidance/pattern-safely-importing-data), an architecture pattern describes a safe mechanism for handling structured data from an external untrusted source. We use a Transform - Verify approach taking our source data, transforming to an intermediate format, inspecting the intermediate format and then transforming back to the original format. SISL was designed to be a simple and easily inspectable intermediate format for just such an approach.
Oakdoor<sup>TM</sup> products enable one- or two-way data transfers between segregated networks, letting organisations safely run services, such as file transfer, protocol exchanges, secure internet browsing and systems management. This is done using a combination of hardware enforced verification and software.
pySISL can form part of the transformation engine sub-system that enables cross-network communication that is compatible with the NCSC Safely importing data pattern. The pySISL encoder can be used to convert complex Python dictionaries into valid SISL that is compatible with the diodes and the decoder will convert the SISL back into the same dictionaries without loss of data.
## License
MIT licence
## SISL Specification
For reference, this is ABNF for SISL.
sislfile = grouping *255wsp
grouping = "{" ( (*255wsp collection *255wsp ) / *255wsp ) "}"
collection = element *("," *255wsp element)
element = name ":" 1*255wsp "!" type 1*255wsp value
name = ( "_" / ALPHA ) *( "_" / "-" / "." / ALPHA / DIGIT )
type = ( "_" / ALPHA ) *254( "_" / "-" / "." / ALPHA / DIGIT )
value = ( DQUOTE *( printable / escape) DQUOTE ) / grouping
escape = "\" ( lcr / lct / lcn / DQUOTE / "\" / (lcx 2HEXDIG) / (lcu 4HEXDIG) / (ucu 8HEXDIG) )
wsp = SP / HTAB / CR / LF
printable = %x20-21 / %x23-5B / %x5D-7E ; Printable chars apart from '"' or '\'
lcr = %x72 ; lower case r
lct = %x74 ; lower case t
lcn = %x6E ; lower case n
lcx = %x78 ; lower case x
lcu = %x75 ; lower case u
ucu = %x55 ; upper case u
; Core rules
ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
DIGIT = %x30-39 ; 0-9
DQUOTE = %x22 ; " (double-quote)
SP = %x20 ; space
HTAB = %x09 ; horizontal tab
CR = %x0D ; carriage return
LF = %x0A ; line feed
## Getting Help
If you need help using the pySISL module, please contact Oakdoor<sup>TM</sup> support at oakdoor.support@paconsulting.com.
## Examples
|Type | Python |SISL |
|--------------------|-------------------------------------------|--------------------------------------------------------------------|
| Dictionary | `{"field_one": {"key_one": "teststring"}}`| `'{"field_one": !obj {"key_one": !str "teststring"}}'` |
| List | `{"field_one": [1, 2, 3]}` | `'{"field_one": !list {_0: !int "1", _1: !int "2", _2: !int "3"}}'`|
| Anonymous list | `[1, 2, 3]` | `'{"_": !_list {_0: !int "1", _1: !int "2", _2: !int "3"}}'` |
| String | `{"field_one": "teststring"}` | `'{"field_one": !str "teststring"}'` |
| Anonymous string | `"teststring"` | `'{"_": !_str "teststring"}'` |
| Int | `{"field_one": 1}` | `'{"field_one": !int "1"}'` |
| Anonymous int | `1` | `'{"_": !_int "1"}'` |
| Float | `{"field_one": 5.3}` | `'{"field_one": !float "5.3"}'` |
| Anonymous float | `5.3` | `'{"_": !_float "5.3"}'` |
| Bool | `{"field_one": True}` | `'{"field_one": !bool "true"}'` |
| Anonymous bool | `True` | `'{"_": !_bool "true"}'` |
| None | `{"field_one": None}` | `'{"field_one": !null ""}'` |
| Anonymous none | `None` | `'{"_": !_null ""}'` |
## Contributing to pySISL
All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
If you notice a bug or would like to make an update to pySISL, please open an issue or raise a pull request.
%prep
%autosetup -n pysisl-0.0.11
%build
%py3_build
%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .
%files -n python3-pysisl -f filelist.lst
%dir %{python3_sitelib}/*
%files help -f doclist.lst
%{_docdir}/*
%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.0.11-1
- Package Spec generated
|