bc-envelope 0.43.0

Gordian Envelope for Rust.
Documentation
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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
#[cfg(feature = "encrypt")]
use bc_components::SymmetricKey;
#[cfg(feature = "known_value")]
use bc_components::{ARID, Digest};
use bc_envelope::prelude::*;
#[cfg(feature = "known_value")]
use hex_literal::hex;
use indoc::indoc;

mod common;
#[cfg(feature = "signature")]
use std::collections::HashSet;
#[cfg(feature = "signature")]
use std::{cell::RefCell, rc::Rc};

#[cfg(feature = "signature")]
use bc_components::DigestProvider;
#[cfg(feature = "signature")]
use bc_components::SigningOptions;
#[cfg(feature = "signature")]
use bc_rand::make_fake_random_number_generator;

use crate::common::{check_encoding::*, test_data::*};

#[test]
fn test_plaintext() {
    let envelope = Envelope::new(PLAINTEXT_HELLO);

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        "Hello."
    "#}.trim());

    assert_actual_expected!(envelope.format_flat(), r#""Hello.""#);

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format(), indoc! {r#"
        8cc96cdb "Hello."
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().context(FormatContextOpt::None)), indoc! {r#"
        8cc96cdb "Hello."
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().digest_display(DigestDisplayFormat::Full)), indoc! {r#"
        8cc96cdb771176e835114a0f8936690b41cfed0df22d014eedd64edaea945d59 "Hello."
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().digest_display(DigestDisplayFormat::UR)), indoc! {r#"
        ur:digest/hdcxlksojzuyktbykovsecbygebsldeninbdfptkwebtwzdpadglwetbgltnwdmwhlhksbbthtpy "Hello."
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        "Hello."
    "#}.trim());

    assert_actual_expected!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[cfg(feature = "signature")]
#[test]
fn test_signed_plaintext() {
    let rng = Rc::new(RefCell::new(make_fake_random_number_generator()));
    let options = SigningOptions::Schnorr { rng };
    let envelope = Envelope::new(PLAINTEXT_HELLO).add_signature_opt(
        &alice_private_key(),
        Some(options),
        None,
    );

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        "Hello." [
            'signed': Signature
        ]
    "#}.trim());

    assert_actual_expected!(
        envelope.format_flat(),
        r#""Hello." [ 'signed': Signature ]"#
    );

    let s = envelope.tree_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        949a991e NODE
            8cc96cdb subj "Hello."
            fcb4e2be ASSERTION
                d0e39e78 pred 'signed'
                b8bb043f obj Signature
    "#}.trim());

    let s = envelope.tree_format_opt(
        &TreeFormatOpts::default().context(FormatContextOpt::None),
    );
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        949a991e NODE
            8cc96cdb subj "Hello."
            fcb4e2be ASSERTION
                d0e39e78 pred '3'
                b8bb043f obj 40020(h'd0f6b2577edb3f4b0f533e21577bc12a58aaca2604bc71e84bd4e2c81421900bca361a1a8de3b7dbfe1cb5c16e34cb8c9a78fe6f7a387e959bbb15f6f3d898d3')
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj "Hello."
            ASSERTION
                pred 'signed'
                obj Signature
    "#}.trim());

    let s = envelope.tree_format_opt(
        &TreeFormatOpts::default()
            .hide_nodes(true)
            .context(FormatContextOpt::None),
    );
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        subj "Hello."
            ASSERTION
                pred '3'
                obj 40020(h'd0f6b2577edb3f4b0f533e21577bc12a58aaca2604bc71e84bd4e2c81421900bca361a1a8de3b7dbfe1cb5c16e34cb8c9a78fe6f7a387e959bbb15f6f3d898d3')
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[cfg(feature = "encrypt")]
#[test]
fn test_encrypt_subject() {
    let envelope = Envelope::new("Alice")
        .add_assertion("knows", "Bob")
        .encrypt_subject(&SymmetricKey::new())
        .unwrap();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        ENCRYPTED [
            "knows": "Bob"
        ]
    "#}.trim());

    assert_actual_expected!(
        envelope.format_flat(),
        r#"ENCRYPTED [ "knows": "Bob" ]"#
    );

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format(), indoc! {r#"
        8955db5e NODE
            13941b48 subj ENCRYPTED
            78d666eb ASSERTION
                db7dd21c pred "knows"
                13b74194 obj "Bob"
    "#}.trim());

    let actual = envelope.mermaid_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    let expected = indoc! {r#"
        %%{ init: { 'theme': 'default', 'flowchart': { 'curve': 'basis' } } }%%
        graph LR
        0(("NODE<br>8955db5e"))
            0 -- subj --> 1>"ENCRYPTED<br>13941b48"]
            0 --> 2(["ASSERTION<br>78d666eb"])
                2 -- pred --> 3["&quot;knows&quot;<br>db7dd21c"]
                2 -- obj --> 4["&quot;Bob&quot;<br>13b74194"]
        style 0 stroke:red,stroke-width:4px
        style 1 stroke:coral,stroke-width:4px
        style 2 stroke:green,stroke-width:4px
        style 3 stroke:teal,stroke-width:4px
        style 4 stroke:teal,stroke-width:4px
        linkStyle 0 stroke:red,stroke-width:2px
        linkStyle 1 stroke-width:2px
        linkStyle 2 stroke:cyan,stroke-width:2px
        linkStyle 3 stroke:magenta,stroke-width:2px
    "#}
    .trim();
    assert_actual_expected!(actual, expected);

    let actual =
        envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true));
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(actual, indoc! {r#"
        subj ENCRYPTED
            ASSERTION
                pred "knows"
                obj "Bob"
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[test]
fn test_top_level_assertion() {
    let envelope = Envelope::new_assertion("knows", "Bob");
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        "knows": "Bob"
    "#}.trim());

    assert_actual_expected!(envelope.format_flat(), r#""knows": "Bob""#);

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format(), indoc! {r#"
        78d666eb ASSERTION
            db7dd21c pred "knows"
            13b74194 obj "Bob"
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        ASSERTION
            pred "knows"
            obj "Bob"
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[test]
fn test_elided_object() {
    let envelope = Envelope::new("Alice").add_assertion("knows", "Bob");
    let elided = envelope.elide_removing_target(&"Bob".to_envelope());
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(elided.format(), indoc! {r#"
        "Alice" [
            "knows": ELIDED
        ]
    "#}.trim());

    assert_actual_expected!(
        elided.format_flat(),
        r#""Alice" [ "knows": ELIDED ]"#
    );

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(elided.tree_format(), indoc! {r#"
        8955db5e NODE
            13941b48 subj "Alice"
            78d666eb ASSERTION
                db7dd21c pred "knows"
                13b74194 obj ELIDED
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(elided.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj "Alice"
            ASSERTION
                pred "knows"
                obj ELIDED
    "#}.trim());

    assert_eq!(
        elided.elements_count(),
        elided.tree_format().split('\n').count()
    );
}

#[cfg(feature = "signature")]
#[test]
fn test_signed_subject() {
    let rng = Rc::new(RefCell::new(make_fake_random_number_generator()));
    let options = SigningOptions::Schnorr { rng };
    let envelope = Envelope::new("Alice")
        .add_assertion("knows", "Bob")
        .add_assertion("knows", "Carol")
        .add_signature_opt(&alice_private_key(), Some(options), None);
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        "Alice" [
            "knows": "Bob"
            "knows": "Carol"
            'signed': Signature
        ]
    "#}.trim());

    assert_actual_expected!(
        envelope.format_flat(),
        r#""Alice" [ "knows": "Bob", "knows": "Carol", 'signed': Signature ]"#
    );

    let s = envelope.tree_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        d595106e NODE
            13941b48 subj "Alice"
            399c974c ASSERTION
                d0e39e78 pred 'signed'
                ff10427c obj Signature
            4012caf2 ASSERTION
                db7dd21c pred "knows"
                afb8122e obj "Carol"
            78d666eb ASSERTION
                db7dd21c pred "knows"
                13b74194 obj "Bob"
    "#}.trim());

    let s =
        envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true));
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        subj "Alice"
            ASSERTION
                pred 'signed'
                obj Signature
            ASSERTION
                pred "knows"
                obj "Carol"
            ASSERTION
                pred "knows"
                obj "Bob"
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );

    // Elided assertions
    let mut target: HashSet<Digest> = HashSet::new();
    target.insert(envelope.digest());
    target.insert(envelope.subject().digest());
    let elided = envelope.elide_revealing_set(&target);
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(elided.format(), indoc! {r#"
        "Alice" [
            ELIDED (3)
        ]
    "#}.trim());

    assert_actual_expected!(elided.format_flat(), r#""Alice" [ ELIDED (3) ]"#);

    let s = elided.tree_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        d595106e NODE
            13941b48 subj "Alice"
            399c974c ELIDED
            4012caf2 ELIDED
            78d666eb ELIDED
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(elided.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj "Alice"
            ELIDED
            ELIDED
            ELIDED
    "#}.trim());

    assert_eq!(
        elided.elements_count(),
        elided.tree_format().split('\n').count()
    );
}

#[cfg(feature = "signature")]
#[test]
fn test_wrap_then_signed() {
    let rng = Rc::new(RefCell::new(make_fake_random_number_generator()));
    let options = SigningOptions::Schnorr { rng };
    let envelope = Envelope::new("Alice")
        .add_assertion("knows", "Bob")
        .add_assertion("knows", "Carol")
        .wrap()
        .add_signature_opt(&alice_private_key(), Some(options), None);
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        {
            "Alice" [
                "knows": "Bob"
                "knows": "Carol"
            ]
        } [
            'signed': Signature
        ]
    "#}.trim());

    assert_actual_expected!(
        envelope.format_flat(),
        r#"{ "Alice" [ "knows": "Bob", "knows": "Carol" ] } [ 'signed': Signature ]"#
    );

    let s = envelope.tree_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        66c9d594 NODE
            9e3b0673 subj WRAPPED
                b8d857f6 cont NODE
                    13941b48 subj "Alice"
                    4012caf2 ASSERTION
                        db7dd21c pred "knows"
                        afb8122e obj "Carol"
                    78d666eb ASSERTION
                        db7dd21c pred "knows"
                        13b74194 obj "Bob"
            f13623da ASSERTION
                d0e39e78 pred 'signed'
                e30a727c obj Signature
    "#}.trim());

    let s =
        envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true));
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        subj WRAPPED
            subj "Alice"
                ASSERTION
                    pred "knows"
                    obj "Carol"
                ASSERTION
                    pred "knows"
                    obj "Bob"
            ASSERTION
                pred 'signed'
                obj Signature
    "#}.trim());

    let s = envelope.tree_format_opt(
        &TreeFormatOpts::default().digest_display(DigestDisplayFormat::Full),
    );
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        66c9d5944eaedc418d8acf52df7842f50c2aa2d0da2857ad1048412cd070c3e8 NODE
            9e3b06737407b10cac0b9353dd978c4a68537709554dabdd66a8b68b8bd36cf6 subj WRAPPED
                b8d857f6e06a836fbc68ca0ce43e55ceb98eefd949119dab344e11c4ba5a0471 cont NODE
                    13941b487c1ddebce827b6ec3f46d982938acdc7e3b6a140db36062d9519dd2f subj "Alice"
                    4012caf2d96bf3962514bcfdcf8dd70c351735dec72c856ec5cdcf2ee35d6a91 ASSERTION
                        db7dd21c5169b4848d2a1bcb0a651c9617cdd90bae29156baaefbb2a8abef5ba pred "knows"
                        afb8122e3227657b415f9f1c930d4891fb040b3e23c1f7770f185e2d0396c737 obj "Carol"
                    78d666eb8f4c0977a0425ab6aa21ea16934a6bc97c6f0c3abaefac951c1714a2 ASSERTION
                        db7dd21c5169b4848d2a1bcb0a651c9617cdd90bae29156baaefbb2a8abef5ba pred "knows"
                        13b741949c37b8e09cc3daa3194c58e4fd6b2f14d4b1d0f035a46d6d5a1d3f11 obj "Bob"
            f13623dac926c57e2ac128868dfaa22fb8e434a7e4a552029992d6f6283da533 ASSERTION
                d0e39e788c0d8f0343af4588db21d3d51381db454bdf710a9a1891aaa537693c pred 'signed'
                e30a727cc1f43fbe3c9fd228447c34faaf6b54101bf7bcd766e280f8449ceade obj Signature
    "#}.trim());

    let s = envelope.tree_format_opt(
        &TreeFormatOpts::default().digest_display(DigestDisplayFormat::UR),
    );
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        ur:digest/hdcxiysotlmwglpluofplgletkgmurksfwykbndroetitndehgpmbefdfpdwtijosrvsbsdlsndm NODE
            ur:digest/hdcxnnframjkjyatpabnpsbdmuguutmslkgeisguktasgogtpyutiypdrplulutejzynmygrnlly subj WRAPPED
                ur:digest/hdcxrotphgynvtimlsjlrfissgbnvefmgotorhmnwstagabyntpyeeglbyssrdhtaajsaetafrbw cont NODE
                    ur:digest/hdcxbwmwcwfdkecauerfvsdirpwpfhfgtalfmulesnstvlrpoyfzuyenamdpmdcfutdlstyaqzrk subj "Alice"
                    ur:digest/hdcxfzbgsgwztajewfmtdabbrfzctklgtsbnecchecuestdwlpjtsksntkdmvlhlimmetlcpiyms ASSERTION
                        ur:digest/hdcxuykitdcegyinqzlrlgdrcwsbbkihcemtchsntabdpldtbzjepkwsrkdrlernykrddpjtgdfh pred "knows"
                        ur:digest/hdcxperobgdmeydiihkgfphenecemubtfdmezoaabdfmcnseylktbscshydpaxmtstemtarhmngd obj "Carol"
                    ur:digest/hdcxkstbiywmmygsasktnbfwhtrppkclwdcmmugejesokejlbnftrdwspsmdcechbboerhzebtws ASSERTION
                        ur:digest/hdcxuykitdcegyinqzlrlgdrcwsbbkihcemtchsntabdpldtbzjepkwsrkdrlernykrddpjtgdfh pred "knows"
                        ur:digest/hdcxbwrlfpmwnsemrovtnssrtnotcfgshdvezcjedlbbtypatiwtecoxjnjnhtcafhbysptsnsnl obj "Bob"
            ur:digest/hdcxwnencntnsodsskkbdrsedelnlgzsoedlroveeeosveongmaonlmotbyndefsoneorfutayas ASSERTION
                ur:digest/hdcxtivlnnkslkbtmyaxfxpefelouycltetlbwlyuyfegrurjsbknycsmepkoneminfnrpjpssla pred 'signed'
                ur:digest/hdcxvlbkjpkesewkfhrnfnnetddefykeeezspejeghbecwylrftsiyvolayafynswduefytsgaos obj Signature
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[cfg(all(feature = "recipient", feature = "secp256k1"))]
#[test]
fn test_encrypt_to_recipients() {
    let envelope = Envelope::new(PLAINTEXT_HELLO)
        .encrypt_subject_opt(&fake_content_key(), Some(fake_nonce()))
        .unwrap()
        .check_encoding()
        .unwrap()
        .add_recipient_opt(
            &bob_public_key(),
            &fake_content_key(),
            Some(fake_nonce()),
        )
        .check_encoding()
        .unwrap()
        .add_recipient_opt(
            &carol_public_key(),
            &fake_content_key(),
            Some(fake_nonce()),
        )
        .check_encoding()
        .unwrap();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        ENCRYPTED [
            'hasRecipient': SealedMessage
            'hasRecipient': SealedMessage
        ]
    "#}.trim());

    assert_actual_expected!(
        envelope.format_flat(),
        r#"ENCRYPTED [ 'hasRecipient': SealedMessage, 'hasRecipient': SealedMessage ]"#
    );

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj ENCRYPTED
            ASSERTION
                pred 'hasRecipient'
                obj SealedMessage
            ASSERTION
                pred 'hasRecipient'
                obj SealedMessage
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[test]
fn test_assertion_positions() {
    let predicate = Envelope::new("predicate")
        .add_assertion("predicate-predicate", "predicate-object");
    let object = Envelope::new("object")
        .add_assertion("object-predicate", "object-object");
    let envelope = Envelope::new("subject")
        .add_assertion(predicate, object)
        .check_encoding()
        .unwrap();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.format(), indoc! {r#"
        "subject" [
            "predicate" [
                "predicate-predicate": "predicate-object"
            ]
            : "object" [
                "object-predicate": "object-object"
            ]
        ]
    "#}.trim());

    assert_actual_expected!(
        envelope.format_flat(),
        r#""subject" [ "predicate" [ "predicate-predicate": "predicate-object" ] : "object" [ "object-predicate": "object-object" ] ]"#
    );

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format(), indoc! {r#"
        e06d7003 NODE
            8e4e62eb subj "subject"
            91a436e0 ASSERTION
                cece8b2c pred NODE
                    d21efb76 subj "predicate"
                    66a0c92b ASSERTION
                        ab829e9f pred "predicate-predicate"
                        f1098628 obj "predicate-object"
                03a99a27 obj NODE
                    fda63155 subj "object"
                    d1878aea ASSERTION
                        88bb262f pred "object-predicate"
                        0bdb89a6 obj "object-object"
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(envelope.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj "subject"
            ASSERTION
                subj "predicate"
                    ASSERTION
                        pred "predicate-predicate"
                        obj "predicate-object"
                subj "object"
                    ASSERTION
                        pred "object-predicate"
                        obj "object-object"
    "#}.trim());

    assert_eq!(
        envelope.elements_count(),
        envelope.tree_format().split('\n').count()
    );
}

#[cfg(feature = "known_value")]
#[test]
fn test_complex_metadata() {
    // Assertions made about an ARID are considered part of a distributed set.
    // Which assertions are returned depends on who resolves the ARID and
    // when it is resolved. In other words, the referent of an ARID is
    // mutable.
    let author = Envelope::new(ARID::from_data(hex!(
        "9c747ace78a4c826392510dd6285551e7df4e5164729a1b36198e56e017666c8"
    )))
    .add_assertion(known_values::DEREFERENCE_VIA, "LibraryOfCongress")
    .add_assertion(known_values::NAME, "Ayn Rand")
    .check_encoding()
    .unwrap();

    // Assertions made on a literal value are considered part of the same set of
    // assertions made on the digest of that value.
    let name_en = Envelope::new("Atlas Shrugged")
        .add_assertion(known_values::LANGUAGE, "en");

    let name_es = Envelope::new("La rebelión de Atlas")
        .add_assertion(known_values::LANGUAGE, "es");

    let work = Envelope::new(ARID::from_data(hex!(
        "7fb90a9d96c07f39f75ea6acf392d79f241fac4ec0be2120f7c82489711e3e80"
    )))
    .add_assertion(known_values::IS_A, "novel")
    .add_assertion("isbn", "9780451191144")
    .add_assertion("author", author)
    .add_assertion(known_values::DEREFERENCE_VIA, "LibraryOfCongress")
    .add_assertion(known_values::NAME, name_en)
    .add_assertion(known_values::NAME, name_es)
    .check_encoding()
    .unwrap();

    let book_data = "This is the entire book “Atlas Shrugged” in EPUB format.";
    // Assertions made on a digest are considered associated with that specific
    // binary object and no other. In other words, the referent of a Digest
    // is immutable.
    let book_metadata = Envelope::new(Digest::from_image(book_data))
        .add_assertion("work", work)
        .add_assertion("format", "EPUB")
        .add_assertion(known_values::DEREFERENCE_VIA, "IPFS")
        .check_encoding()
        .unwrap();

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(book_metadata.format(), indoc! {r#"
        Digest(26d05af5) [
            "format": "EPUB"
            "work": ARID(7fb90a9d) [
                'isA': "novel"
                "author": ARID(9c747ace) [
                    'dereferenceVia': "LibraryOfCongress"
                    'name': "Ayn Rand"
                ]
                "isbn": "9780451191144"
                'dereferenceVia': "LibraryOfCongress"
                'name': "Atlas Shrugged" [
                    'language': "en"
                ]
                'name': "La rebelión de Atlas" [
                    'language': "es"
                ]
            ]
            'dereferenceVia': "IPFS"
        ]
    "#}.trim());
    assert_actual_expected!(
        book_metadata.format_flat(),
        r#"Digest(26d05af5) [ "format": "EPUB", "work": ARID(7fb90a9d) [ 'isA': "novel", "author": ARID(9c747ace) [ 'dereferenceVia': "LibraryOfCongress", 'name': "Ayn Rand" ], "isbn": "9780451191144", 'dereferenceVia': "LibraryOfCongress", 'name': "Atlas Shrugged" [ 'language': "en" ], 'name': "La rebelión de Atlas" [ 'language': "es" ] ], 'dereferenceVia': "IPFS" ]"#
    );

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(book_metadata.tree_format(), indoc! {r#"
        c93370e7 NODE
            0c1e45b9 subj Digest(26d05af5)
            83b00bef ASSERTION
                cdb6a696 pred 'dereferenceVia'
                15eac58f obj "IPFS"
            953cdab2 ASSERTION
                a9a86b03 pred "format"
                9536cfe0 obj "EPUB"
            eec25a61 ASSERTION
                2ddb0b05 pred "work"
                26681136 obj NODE
                    0c69be6e subj ARID(7fb90a9d)
                    1786d8b5 ASSERTION
                        4019420b pred "isbn"
                        69ff76b1 obj "9780451191144"
                    5355d973 ASSERTION
                        2be2d79b pred 'isA'
                        6d7c7189 obj "novel"
                    63cd143a ASSERTION
                        14ff9eac pred 'name'
                        29fa40b1 obj NODE
                            5e825721 subj "La rebelión de Atlas"
                            c8db157b ASSERTION
                                60dfb783 pred 'language'
                                b33e79c2 obj "es"
                    7d6d5c1d ASSERTION
                        29c09059 pred "author"
                        1ba13788 obj NODE
                            3c47e105 subj ARID(9c747ace)
                            9c10d60f ASSERTION
                                cdb6a696 pred 'dereferenceVia'
                                34a04547 obj "LibraryOfCongress"
                            bff8435a ASSERTION
                                14ff9eac pred 'name'
                                98985bd5 obj "Ayn Rand"
                    9c10d60f ASSERTION
                        cdb6a696 pred 'dereferenceVia'
                        34a04547 obj "LibraryOfCongress"
                    b722c07c ASSERTION
                        14ff9eac pred 'name'
                        0cfacc06 obj NODE
                            e84c3091 subj "Atlas Shrugged"
                            b80d3b05 ASSERTION
                                60dfb783 pred 'language'
                                6700869c obj "en"
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(book_metadata.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj Digest(26d05af5)
            ASSERTION
                pred 'dereferenceVia'
                obj "IPFS"
            ASSERTION
                pred "format"
                obj "EPUB"
            ASSERTION
                pred "work"
                subj ARID(7fb90a9d)
                    ASSERTION
                        pred "isbn"
                        obj "9780451191144"
                    ASSERTION
                        pred 'isA'
                        obj "novel"
                    ASSERTION
                        pred 'name'
                        subj "La rebelión de Atlas"
                            ASSERTION
                                pred 'language'
                                obj "es"
                    ASSERTION
                        pred "author"
                        subj ARID(9c747ace)
                            ASSERTION
                                pred 'dereferenceVia'
                                obj "LibraryOfCongress"
                            ASSERTION
                                pred 'name'
                                obj "Ayn Rand"
                    ASSERTION
                        pred 'dereferenceVia'
                        obj "LibraryOfCongress"
                    ASSERTION
                        pred 'name'
                        subj "Atlas Shrugged"
                            ASSERTION
                                pred 'language'
                                obj "en"
    "#}.trim());

    assert_eq!(
        book_metadata.elements_count(),
        book_metadata.tree_format().split('\n').count()
    );
}

#[cfg(feature = "signature")]
#[test]
fn test_credential() {
    let credential = credential();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(credential.format(), indoc! {r#"
        {
            ARID(4676635a) [
                'isA': "Certificate of Completion"
                "certificateNumber": "123-456-789"
                "continuingEducationUnits": 1
                "expirationDate": 2028-01-01
                "firstName": "James"
                "issueDate": 2020-01-01
                "lastName": "Maxwell"
                "photo": "This is James Maxwell's photo."
                "professionalDevelopmentHours": 15
                "subject": "RF and Microwave Engineering"
                "topics": ["Subject 1", "Subject 2"]
                'controller': "Example Electrical Engineering Board"
                'issuer': "Example Electrical Engineering Board"
            ]
        } [
            'note': "Signed by Example Electrical Engineering Board"
            'signed': Signature
        ]
    "#}.trim());

    assert_actual_expected!(
        credential.format_flat(),
        r#"{ ARID(4676635a) [ 'isA': "Certificate of Completion", "certificateNumber": "123-456-789", "continuingEducationUnits": 1, "expirationDate": 2028-01-01, "firstName": "James", "issueDate": 2020-01-01, "lastName": "Maxwell", "photo": "This is James Maxwell's photo.", "professionalDevelopmentHours": 15, "subject": "RF and Microwave Engineering", "topics": ["Subject 1", "Subject 2"], 'controller': "Example Electrical Engineering Board", 'issuer': "Example Electrical Engineering Board" ] } [ 'note': "Signed by Example Electrical Engineering Board", 'signed': Signature ]"#
    );

    let s = credential.tree_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        0b721f78 NODE
            397a2d4c subj WRAPPED
                8122ffa9 cont NODE
                    10d3de01 subj ARID(4676635a)
                    1f9ff098 ASSERTION
                        9e3bff3a pred "certificateNumber"
                        21c21808 obj "123-456-789"
                    36c254d0 ASSERTION
                        6e5d379f pred "expirationDate"
                        639ae9bf obj 2028-01-01
                    3c114201 ASSERTION
                        5f82a16a pred "lastName"
                        fe4d5230 obj "Maxwell"
                    4a9b2e4d ASSERTION
                        222afe69 pred "issueDate"
                        cb67f31d obj 2020-01-01
                    4d67bba0 ASSERTION
                        2be2d79b pred 'isA'
                        051beee6 obj "Certificate of Completion"
                    5171cbaf ASSERTION
                        3976ef74 pred "photo"
                        231b8527 obj "This is James Maxwell's photo."
                    54b3e1e7 ASSERTION
                        f13aa855 pred "professionalDevelopmentHours"
                        dc0e9c36 obj 15
                    5dc6d4e3 ASSERTION
                        4395643b pred "firstName"
                        d6d0b768 obj "James"
                    68895d8e ASSERTION
                        e6bf4dd3 pred "topics"
                        543fcc09 obj ["Subject 1", "Subject 2"]
                    8ec5e912 ASSERTION
                        2b191589 pred "continuingEducationUnits"
                        4bf5122f obj 1
                    9b3d4785 ASSERTION
                        af10ee92 pred 'controller'
                        f8489ac1 obj "Example Electrical Engineering Board"
                    caf5ced3 ASSERTION
                        8e4e62eb pred "subject"
                        202c10ef obj "RF and Microwave Engineering"
                    d3e0cc15 ASSERTION
                        6dd16ba3 pred 'issuer'
                        f8489ac1 obj "Example Electrical Engineering Board"
            46a02aaf ASSERTION
                d0e39e78 pred 'signed'
                34c14941 obj Signature
            e6d7fca0 ASSERTION
                0fcd6a39 pred 'note'
                f106bad1 obj "Signed by Example Electrical Engineering…"
    "#}.trim());

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(credential.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true)), indoc! {r#"
        subj WRAPPED
            subj ARID(4676635a)
                ASSERTION
                    pred "certificateNumber"
                    obj "123-456-789"
                ASSERTION
                    pred "expirationDate"
                    obj 2028-01-01
                ASSERTION
                    pred "lastName"
                    obj "Maxwell"
                ASSERTION
                    pred "issueDate"
                    obj 2020-01-01
                ASSERTION
                    pred 'isA'
                    obj "Certificate of Completion"
                ASSERTION
                    pred "photo"
                    obj "This is James Maxwell's photo."
                ASSERTION
                    pred "professionalDevelopmentHours"
                    obj 15
                ASSERTION
                    pred "firstName"
                    obj "James"
                ASSERTION
                    pred "topics"
                    obj ["Subject 1", "Subject 2"]
                ASSERTION
                    pred "continuingEducationUnits"
                    obj 1
                ASSERTION
                    pred 'controller'
                    obj "Example Electrical Engineering Board"
                ASSERTION
                    pred "subject"
                    obj "RF and Microwave Engineering"
                ASSERTION
                    pred 'issuer'
                    obj "Example Electrical Engineering Board"
            ASSERTION
                pred 'signed'
                obj Signature
            ASSERTION
                pred 'note'
                obj "Signed by Example Electrical Engineering…"
    "#}.trim());

    assert_eq!(
        credential.elements_count(),
        credential.tree_format().split('\n').count()
    );
}

#[cfg(feature = "signature")]
#[test]
fn test_redacted_credential() {
    let redacted_credential = redacted_credential();
    let rng = Rc::new(RefCell::new(make_fake_random_number_generator()));
    let options = SigningOptions::Schnorr { rng };
    let warranty = redacted_credential
        .wrap()
        .add_assertion(
            "employeeHiredDate",
            Date::from_string("2022-01-01").unwrap(),
        )
        .add_assertion("employeeStatus", "active")
        .wrap()
        .add_assertion(known_values::NOTE, "Signed by Employer Corp.")
        .add_signature_opt(&bob_private_key(), Some(options), None)
        .check_encoding()
        .unwrap();

    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(warranty.format(), indoc! {r#"
        {
            {
                {
                    ARID(4676635a) [
                        'isA': "Certificate of Completion"
                        "expirationDate": 2028-01-01
                        "firstName": "James"
                        "lastName": "Maxwell"
                        "subject": "RF and Microwave Engineering"
                        'issuer': "Example Electrical Engineering Board"
                        ELIDED (7)
                    ]
                } [
                    'note': "Signed by Example Electrical Engineering Board"
                    'signed': Signature
                ]
            } [
                "employeeHiredDate": 2022-01-01
                "employeeStatus": "active"
            ]
        } [
            'note': "Signed by Employer Corp."
            'signed': Signature
        ]
    "#}.trim());

    assert_actual_expected!(
        warranty.format_flat(),
        r#"{ { { ARID(4676635a) [ 'isA': "Certificate of Completion", "expirationDate": 2028-01-01, "firstName": "James", "lastName": "Maxwell", "subject": "RF and Microwave Engineering", 'issuer': "Example Electrical Engineering Board", ELIDED (7) ] } [ 'note': "Signed by Example Electrical Engineering Board", 'signed': Signature ] } [ "employeeHiredDate": 2022-01-01, "employeeStatus": "active" ] } [ 'note': "Signed by Employer Corp.", 'signed': Signature ]"#
    );

    let s = warranty.tree_format();
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        7ab3e6b1 NODE
            3907ee6f subj WRAPPED
                719d5955 cont NODE
                    10fb2e18 subj WRAPPED
                        0b721f78 cont NODE
                            397a2d4c subj WRAPPED
                                8122ffa9 cont NODE
                                    10d3de01 subj ARID(4676635a)
                                    1f9ff098 ELIDED
                                    36c254d0 ASSERTION
                                        6e5d379f pred "expirationDate"
                                        639ae9bf obj 2028-01-01
                                    3c114201 ASSERTION
                                        5f82a16a pred "lastName"
                                        fe4d5230 obj "Maxwell"
                                    4a9b2e4d ELIDED
                                    4d67bba0 ASSERTION
                                        2be2d79b pred 'isA'
                                        051beee6 obj "Certificate of Completion"
                                    5171cbaf ELIDED
                                    54b3e1e7 ELIDED
                                    5dc6d4e3 ASSERTION
                                        4395643b pred "firstName"
                                        d6d0b768 obj "James"
                                    68895d8e ELIDED
                                    8ec5e912 ELIDED
                                    9b3d4785 ELIDED
                                    caf5ced3 ASSERTION
                                        8e4e62eb pred "subject"
                                        202c10ef obj "RF and Microwave Engineering"
                                    d3e0cc15 ASSERTION
                                        6dd16ba3 pred 'issuer'
                                        f8489ac1 obj "Example Electrical Engineering Board"
                            46a02aaf ASSERTION
                                d0e39e78 pred 'signed'
                                34c14941 obj Signature
                            e6d7fca0 ASSERTION
                                0fcd6a39 pred 'note'
                                f106bad1 obj "Signed by Example Electrical Engineering…"
                    4c159c16 ASSERTION
                        e1ae011e pred "employeeHiredDate"
                        13b5a817 obj 2022-01-01
                    e071508b ASSERTION
                        d03e7352 pred "employeeStatus"
                        1d7a790d obj "active"
            874aa7e1 ASSERTION
                0fcd6a39 pred 'note'
                f59806d2 obj "Signed by Employer Corp."
            d21d2033 ASSERTION
                d0e39e78 pred 'signed'
                5ba600c9 obj Signature
    "#}.trim());

    let s =
        warranty.tree_format_opt(&TreeFormatOpts::default().hide_nodes(true));
    // expected-text-output-rubric:
    #[rustfmt::skip]
    assert_actual_expected!(s, indoc! {r#"
        subj WRAPPED
            subj WRAPPED
                subj WRAPPED
                    subj ARID(4676635a)
                        ELIDED
                        ASSERTION
                            pred "expirationDate"
                            obj 2028-01-01
                        ASSERTION
                            pred "lastName"
                            obj "Maxwell"
                        ELIDED
                        ASSERTION
                            pred 'isA'
                            obj "Certificate of Completion"
                        ELIDED
                        ELIDED
                        ASSERTION
                            pred "firstName"
                            obj "James"
                        ELIDED
                        ELIDED
                        ELIDED
                        ASSERTION
                            pred "subject"
                            obj "RF and Microwave Engineering"
                        ASSERTION
                            pred 'issuer'
                            obj "Example Electrical Engineering Board"
                    ASSERTION
                        pred 'signed'
                        obj Signature
                    ASSERTION
                        pred 'note'
                        obj "Signed by Example Electrical Engineering…"
                ASSERTION
                    pred "employeeHiredDate"
                    obj 2022-01-01
                ASSERTION
                    pred "employeeStatus"
                    obj "active"
            ASSERTION
                pred 'note'
                obj "Signed by Employer Corp."
            ASSERTION
                pred 'signed'
                obj Signature
    "#}.trim());

    assert_eq!(
        warranty.elements_count(),
        warranty.tree_format().split('\n').count()
    );

    let actual = warranty.mermaid_format_opt(
        &MermaidFormatOpts::default().theme(MermaidTheme::Dark),
    );
    // expected-text-output-rubric:
    #[rustfmt::skip]
    let expected = indoc! {r#"
        %%{ init: { 'theme': 'dark', 'flowchart': { 'curve': 'basis' } } }%%
        graph LR
        0(("NODE<br>7ab3e6b1"))
            0 -- subj --> 1[/"WRAPPED<br>3907ee6f"\]
                1 -- cont --> 2(("NODE<br>719d5955"))
                    2 -- subj --> 3[/"WRAPPED<br>10fb2e18"\]
                        3 -- cont --> 4(("NODE<br>0b721f78"))
                            4 -- subj --> 5[/"WRAPPED<br>397a2d4c"\]
                                5 -- cont --> 6(("NODE<br>8122ffa9"))
                                    6 -- subj --> 7["ARID(4676635a)<br>10d3de01"]
                                    6 --> 8{{"ELIDED<br>1f9ff098"}}
                                    6 --> 9(["ASSERTION<br>36c254d0"])
                                        9 -- pred --> 10["&quot;expirationDate&quot;<br>6e5d379f"]
                                        9 -- obj --> 11["2028-01-01<br>639ae9bf"]
                                    6 --> 12(["ASSERTION<br>3c114201"])
                                        12 -- pred --> 13["&quot;lastName&quot;<br>5f82a16a"]
                                        12 -- obj --> 14["&quot;Maxwell&quot;<br>fe4d5230"]
                                    6 --> 15{{"ELIDED<br>4a9b2e4d"}}
                                    6 --> 16(["ASSERTION<br>4d67bba0"])
                                        16 -- pred --> 17[/"'isA'<br>2be2d79b"/]
                                        16 -- obj --> 18["&quot;Certificate of Compl…&quot;<br>051beee6"]
                                    6 --> 19{{"ELIDED<br>5171cbaf"}}
                                    6 --> 20{{"ELIDED<br>54b3e1e7"}}
                                    6 --> 21(["ASSERTION<br>5dc6d4e3"])
                                        21 -- pred --> 22["&quot;firstName&quot;<br>4395643b"]
                                        21 -- obj --> 23["&quot;James&quot;<br>d6d0b768"]
                                    6 --> 24{{"ELIDED<br>68895d8e"}}
                                    6 --> 25{{"ELIDED<br>8ec5e912"}}
                                    6 --> 26{{"ELIDED<br>9b3d4785"}}
                                    6 --> 27(["ASSERTION<br>caf5ced3"])
                                        27 -- pred --> 28["&quot;subject&quot;<br>8e4e62eb"]
                                        27 -- obj --> 29["&quot;RF and Microwave Eng…&quot;<br>202c10ef"]
                                    6 --> 30(["ASSERTION<br>d3e0cc15"])
                                        30 -- pred --> 31[/"'issuer'<br>6dd16ba3"/]
                                        30 -- obj --> 32["&quot;Example Electrical E…&quot;<br>f8489ac1"]
                            4 --> 33(["ASSERTION<br>46a02aaf"])
                                33 -- pred --> 34[/"'signed'<br>d0e39e78"/]
                                33 -- obj --> 35["Signature<br>34c14941"]
                            4 --> 36(["ASSERTION<br>e6d7fca0"])
                                36 -- pred --> 37[/"'note'<br>0fcd6a39"/]
                                36 -- obj --> 38["&quot;Signed by Example El…&quot;<br>f106bad1"]
                    2 --> 39(["ASSERTION<br>4c159c16"])
                        39 -- pred --> 40["&quot;employeeHiredDate&quot;<br>e1ae011e"]
                        39 -- obj --> 41["2022-01-01<br>13b5a817"]
                    2 --> 42(["ASSERTION<br>e071508b"])
                        42 -- pred --> 43["&quot;employeeStatus&quot;<br>d03e7352"]
                        42 -- obj --> 44["&quot;active&quot;<br>1d7a790d"]
            0 --> 45(["ASSERTION<br>874aa7e1"])
                45 -- pred --> 46[/"'note'<br>0fcd6a39"/]
                45 -- obj --> 47["&quot;Signed by Employer C…&quot;<br>f59806d2"]
            0 --> 48(["ASSERTION<br>d21d2033"])
                48 -- pred --> 49[/"'signed'<br>d0e39e78"/]
                48 -- obj --> 50["Signature<br>5ba600c9"]
        style 0 stroke:red,stroke-width:4px
        style 1 stroke:blue,stroke-width:4px
        style 2 stroke:red,stroke-width:4px
        style 3 stroke:blue,stroke-width:4px
        style 4 stroke:red,stroke-width:4px
        style 5 stroke:blue,stroke-width:4px
        style 6 stroke:red,stroke-width:4px
        style 7 stroke:teal,stroke-width:4px
        style 8 stroke:gray,stroke-width:4px
        style 9 stroke:green,stroke-width:4px
        style 10 stroke:teal,stroke-width:4px
        style 11 stroke:teal,stroke-width:4px
        style 12 stroke:green,stroke-width:4px
        style 13 stroke:teal,stroke-width:4px
        style 14 stroke:teal,stroke-width:4px
        style 15 stroke:gray,stroke-width:4px
        style 16 stroke:green,stroke-width:4px
        style 17 stroke:goldenrod,stroke-width:4px
        style 18 stroke:teal,stroke-width:4px
        style 19 stroke:gray,stroke-width:4px
        style 20 stroke:gray,stroke-width:4px
        style 21 stroke:green,stroke-width:4px
        style 22 stroke:teal,stroke-width:4px
        style 23 stroke:teal,stroke-width:4px
        style 24 stroke:gray,stroke-width:4px
        style 25 stroke:gray,stroke-width:4px
        style 26 stroke:gray,stroke-width:4px
        style 27 stroke:green,stroke-width:4px
        style 28 stroke:teal,stroke-width:4px
        style 29 stroke:teal,stroke-width:4px
        style 30 stroke:green,stroke-width:4px
        style 31 stroke:goldenrod,stroke-width:4px
        style 32 stroke:teal,stroke-width:4px
        style 33 stroke:green,stroke-width:4px
        style 34 stroke:goldenrod,stroke-width:4px
        style 35 stroke:teal,stroke-width:4px
        style 36 stroke:green,stroke-width:4px
        style 37 stroke:goldenrod,stroke-width:4px
        style 38 stroke:teal,stroke-width:4px
        style 39 stroke:green,stroke-width:4px
        style 40 stroke:teal,stroke-width:4px
        style 41 stroke:teal,stroke-width:4px
        style 42 stroke:green,stroke-width:4px
        style 43 stroke:teal,stroke-width:4px
        style 44 stroke:teal,stroke-width:4px
        style 45 stroke:green,stroke-width:4px
        style 46 stroke:goldenrod,stroke-width:4px
        style 47 stroke:teal,stroke-width:4px
        style 48 stroke:green,stroke-width:4px
        style 49 stroke:goldenrod,stroke-width:4px
        style 50 stroke:teal,stroke-width:4px
        linkStyle 0 stroke:red,stroke-width:2px
        linkStyle 1 stroke:blue,stroke-width:2px
        linkStyle 2 stroke:red,stroke-width:2px
        linkStyle 3 stroke:blue,stroke-width:2px
        linkStyle 4 stroke:red,stroke-width:2px
        linkStyle 5 stroke:blue,stroke-width:2px
        linkStyle 6 stroke:red,stroke-width:2px
        linkStyle 7 stroke-width:2px
        linkStyle 8 stroke-width:2px
        linkStyle 9 stroke:cyan,stroke-width:2px
        linkStyle 10 stroke:magenta,stroke-width:2px
        linkStyle 11 stroke-width:2px
        linkStyle 12 stroke:cyan,stroke-width:2px
        linkStyle 13 stroke:magenta,stroke-width:2px
        linkStyle 14 stroke-width:2px
        linkStyle 15 stroke-width:2px
        linkStyle 16 stroke:cyan,stroke-width:2px
        linkStyle 17 stroke:magenta,stroke-width:2px
        linkStyle 18 stroke-width:2px
        linkStyle 19 stroke-width:2px
        linkStyle 20 stroke-width:2px
        linkStyle 21 stroke:cyan,stroke-width:2px
        linkStyle 22 stroke:magenta,stroke-width:2px
        linkStyle 23 stroke-width:2px
        linkStyle 24 stroke-width:2px
        linkStyle 25 stroke-width:2px
        linkStyle 26 stroke-width:2px
        linkStyle 27 stroke:cyan,stroke-width:2px
        linkStyle 28 stroke:magenta,stroke-width:2px
        linkStyle 29 stroke-width:2px
        linkStyle 30 stroke:cyan,stroke-width:2px
        linkStyle 31 stroke:magenta,stroke-width:2px
        linkStyle 32 stroke-width:2px
        linkStyle 33 stroke:cyan,stroke-width:2px
        linkStyle 34 stroke:magenta,stroke-width:2px
        linkStyle 35 stroke-width:2px
        linkStyle 36 stroke:cyan,stroke-width:2px
        linkStyle 37 stroke:magenta,stroke-width:2px
        linkStyle 38 stroke-width:2px
        linkStyle 39 stroke:cyan,stroke-width:2px
        linkStyle 40 stroke:magenta,stroke-width:2px
        linkStyle 41 stroke-width:2px
        linkStyle 42 stroke:cyan,stroke-width:2px
        linkStyle 43 stroke:magenta,stroke-width:2px
        linkStyle 44 stroke-width:2px
        linkStyle 45 stroke:cyan,stroke-width:2px
        linkStyle 46 stroke:magenta,stroke-width:2px
        linkStyle 47 stroke-width:2px
        linkStyle 48 stroke:cyan,stroke-width:2px
        linkStyle 49 stroke:magenta,stroke-width:2px
    "#}.trim();
    assert_actual_expected!(actual, expected);

    let actual = warranty.mermaid_format_opt(
        &MermaidFormatOpts::default()
            .monochrome(true)
            .theme(MermaidTheme::Forest)
            .orientation(MermaidOrientation::TopToBottom)
            .hide_nodes(true),
    );
    // expected-text-output-rubric:
    #[rustfmt::skip]
    let expected = indoc! {r#"
        %%{ init: { 'theme': 'forest', 'flowchart': { 'curve': 'basis' } } }%%
        graph TB
        0[/"WRAPPED"\]
            0 -- subj --> 1[/"WRAPPED"\]
                1 -- subj --> 2[/"WRAPPED"\]
                    2 -- subj --> 3["ARID(4676635a)"]
                        3 --> 4{{"ELIDED"}}
                        3 --> 5(["ASSERTION"])
                            5 -- pred --> 6["&quot;expirationDate&quot;"]
                            5 -- obj --> 7["2028-01-01"]
                        3 --> 8(["ASSERTION"])
                            8 -- pred --> 9["&quot;lastName&quot;"]
                            8 -- obj --> 10["&quot;Maxwell&quot;"]
                        3 --> 11{{"ELIDED"}}
                        3 --> 12(["ASSERTION"])
                            12 -- pred --> 13[/"'isA'"/]
                            12 -- obj --> 14["&quot;Certificate of Compl…&quot;"]
                        3 --> 15{{"ELIDED"}}
                        3 --> 16{{"ELIDED"}}
                        3 --> 17(["ASSERTION"])
                            17 -- pred --> 18["&quot;firstName&quot;"]
                            17 -- obj --> 19["&quot;James&quot;"]
                        3 --> 20{{"ELIDED"}}
                        3 --> 21{{"ELIDED"}}
                        3 --> 22{{"ELIDED"}}
                        3 --> 23(["ASSERTION"])
                            23 -- pred --> 24["&quot;subject&quot;"]
                            23 -- obj --> 25["&quot;RF and Microwave Eng…&quot;"]
                        3 --> 26(["ASSERTION"])
                            26 -- pred --> 27[/"'issuer'"/]
                            26 -- obj --> 28["&quot;Example Electrical E…&quot;"]
                    2 --> 29(["ASSERTION"])
                        29 -- pred --> 30[/"'signed'"/]
                        29 -- obj --> 31["Signature"]
                    2 --> 32(["ASSERTION"])
                        32 -- pred --> 33[/"'note'"/]
                        32 -- obj --> 34["&quot;Signed by Example El…&quot;"]
                1 --> 35(["ASSERTION"])
                    35 -- pred --> 36["&quot;employeeHiredDate&quot;"]
                    35 -- obj --> 37["2022-01-01"]
                1 --> 38(["ASSERTION"])
                    38 -- pred --> 39["&quot;employeeStatus&quot;"]
                    38 -- obj --> 40["&quot;active&quot;"]
            0 --> 41(["ASSERTION"])
                41 -- pred --> 42[/"'note'"/]
                41 -- obj --> 43["&quot;Signed by Employer C…&quot;"]
            0 --> 44(["ASSERTION"])
                44 -- pred --> 45[/"'signed'"/]
                44 -- obj --> 46["Signature"]
        style 0 stroke-width:4px
        style 1 stroke-width:4px
        style 2 stroke-width:4px
        style 3 stroke-width:4px
        style 4 stroke-width:4px
        style 5 stroke-width:4px
        style 6 stroke-width:4px
        style 7 stroke-width:4px
        style 8 stroke-width:4px
        style 9 stroke-width:4px
        style 10 stroke-width:4px
        style 11 stroke-width:4px
        style 12 stroke-width:4px
        style 13 stroke-width:4px
        style 14 stroke-width:4px
        style 15 stroke-width:4px
        style 16 stroke-width:4px
        style 17 stroke-width:4px
        style 18 stroke-width:4px
        style 19 stroke-width:4px
        style 20 stroke-width:4px
        style 21 stroke-width:4px
        style 22 stroke-width:4px
        style 23 stroke-width:4px
        style 24 stroke-width:4px
        style 25 stroke-width:4px
        style 26 stroke-width:4px
        style 27 stroke-width:4px
        style 28 stroke-width:4px
        style 29 stroke-width:4px
        style 30 stroke-width:4px
        style 31 stroke-width:4px
        style 32 stroke-width:4px
        style 33 stroke-width:4px
        style 34 stroke-width:4px
        style 35 stroke-width:4px
        style 36 stroke-width:4px
        style 37 stroke-width:4px
        style 38 stroke-width:4px
        style 39 stroke-width:4px
        style 40 stroke-width:4px
        style 41 stroke-width:4px
        style 42 stroke-width:4px
        style 43 stroke-width:4px
        style 44 stroke-width:4px
        style 45 stroke-width:4px
        style 46 stroke-width:4px
        linkStyle 0 stroke-width:2px
        linkStyle 1 stroke-width:2px
        linkStyle 2 stroke-width:2px
        linkStyle 3 stroke-width:2px
        linkStyle 4 stroke-width:2px
        linkStyle 5 stroke-width:2px
        linkStyle 6 stroke-width:2px
        linkStyle 7 stroke-width:2px
        linkStyle 8 stroke-width:2px
        linkStyle 9 stroke-width:2px
        linkStyle 10 stroke-width:2px
        linkStyle 11 stroke-width:2px
        linkStyle 12 stroke-width:2px
        linkStyle 13 stroke-width:2px
        linkStyle 14 stroke-width:2px
        linkStyle 15 stroke-width:2px
        linkStyle 16 stroke-width:2px
        linkStyle 17 stroke-width:2px
        linkStyle 18 stroke-width:2px
        linkStyle 19 stroke-width:2px
        linkStyle 20 stroke-width:2px
        linkStyle 21 stroke-width:2px
        linkStyle 22 stroke-width:2px
        linkStyle 23 stroke-width:2px
        linkStyle 24 stroke-width:2px
        linkStyle 25 stroke-width:2px
        linkStyle 26 stroke-width:2px
        linkStyle 27 stroke-width:2px
        linkStyle 28 stroke-width:2px
        linkStyle 29 stroke-width:2px
        linkStyle 30 stroke-width:2px
        linkStyle 31 stroke-width:2px
        linkStyle 32 stroke-width:2px
        linkStyle 33 stroke-width:2px
        linkStyle 34 stroke-width:2px
        linkStyle 35 stroke-width:2px
        linkStyle 36 stroke-width:2px
        linkStyle 37 stroke-width:2px
        linkStyle 38 stroke-width:2px
        linkStyle 39 stroke-width:2px
        linkStyle 40 stroke-width:2px
        linkStyle 41 stroke-width:2px
        linkStyle 42 stroke-width:2px
        linkStyle 43 stroke-width:2px
        linkStyle 44 stroke-width:2px
        linkStyle 45 stroke-width:2px
    "#}.trim();
    assert_actual_expected!(actual, expected);
}