bee2-rs 0.2.1

Bindings for cryptographic library Bee2
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
@echo off
rem ===========================================================================
rem \brief Testing command-line interface
rem \project bee2evp/cmd
rem \created 2022.06.24
rem \version 2025.05.05
rem \pre The working directory contains zed.cert, zed.csr, zed,sk
rem ===========================================================================

for /F "tokens=*" %%a in ('where /R . bee2cmd') do set bee2cmd=%%a

rem ===========================================================================
rem  bee2cmd/ver
rem ===========================================================================

echo ****** Testing bee2cmd/ver...

bee2cmd
if %ERRORLEVEL% equ 0 goto Error

bee2cmd ver
if %ERRORLEVEL% neq 0 goto Error

bee2cmd ver ver
if %ERRORLEVEL% equ 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/bsum
rem ===========================================================================

echo ****** Testing bee2cmd/bsum...

del /q check32 check256 -c 2> nul

bee2cmd bsum
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -bash31 %bee2cmd%
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -bash32 %bee2cmd% test.cmd > check32
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -bash32 -c check32
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum %bee2cmd% test.cmd > check256
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -belt-hash -c check256
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -c check32
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -bash-prg-hash2561 %bee2cmd% test.cmd > -c
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -bash-prg-hash2561 -c
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -bash-prg-hash2561 -- -c
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -bash-prg-hash2561 -c -- -c
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -bash-prg-hash2562 -c -- -c
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -c -bash-prg-hash2561 -- -c
if %ERRORLEVEL% neq 0 goto Error

bee2cmd bsum -c -bash-prg-hash2561 -c -- -c
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -c -belt-hash -bash-prg-hash2561 -- -c
if %ERRORLEVEL% equ 0 goto Error

bee2cmd bsum -b -c -- -c
if %ERRORLEVEL% equ 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/pwd
rem ===========================================================================

echo ****** Testing bee2cmd/pwd...

del /q s1 s2 s3 s4 s5 2> nul

bee2cmd pwd
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen pass:zed
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val pass:zed
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val pass:"zed"
if %ERRORLEVEL% neq 0 goto Error

for /f %%i in ('bee2cmd pwd print pass:zed') do (
  if "%%i" neq "zed" goto Error
)

bee2cmd pwd gen env:BEE2_CMD_TEST
if %ERRORLEVEL% equ 0 goto Error

set BEE2_CMD_TEST=

bee2cmd pwd val env:BEE2_CMD_TEST
if %ERRORLEVEL% equ 0 goto Error

set BEE2_CMD_TEST=zed

bee2cmd pwd val env:BEE2_CMD_TEST
if %ERRORLEVEL% neq 0 goto Error

for /f %%i in ('bee2cmd pwd print env:BEE2_CMD_TEST') do (
  if "%%i" neq "zed" goto Error
)

bee2cmd pwd gen share:"-t2 -t3 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-t3 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-l -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-l12 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-l128 -l -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-l128 -l256 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-l128 -t3 -crc -pass pass:zed s1 s2 s3 s4 s5"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd gen share:"-l256 -t3 -crc -pass pass:zed s1 s2 s3 s4 s5"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val share:"-t3 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-l -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-l12 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-l128 -l -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-l128 -l256 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-l128 -pass pass:zed s1 s2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-l256 -pass pass:zed s1 s2 s3"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val share:"-l256 -crc -pass pass:zed s1 s2 s3"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val share:"-pass pass:zed s2 s3 s4 s5"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val share:"-pass pass:zed -crc s2 s3 s4 s5"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd print share:"-l128 -pass pass:zed s5 s1 s3"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd print share:"-l256 -pass pass:zed s2 s1 s5 s3"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd print share:"-pass pass:zed s1 s2 s3 s4 s5"
if %ERRORLEVEL% neq 0 goto Error

del /q ss1 ss2 ss3 2> nul

bee2cmd pwd gen share:"-l192 -pass share:\"-pass pass:zed s1 s2 s3\" ss1 ss2 ss3"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val share:"-pass share:\"-pass pass:zed s1 s2 s2\" ss1 ss2"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-pass share:\"-pass pass:zed s1 s2 s3\" ss1 ss1"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd pwd val share:"-pass share:\"-pass pass:zed s1 s2 s3\" ss2 ss3"
if %ERRORLEVEL% neq 0 goto Error

bee2cmd pwd val share:"-pass -crc share:\"-pass pass:zed s1 s2 s3\" ss2 ss3"
if %ERRORLEVEL% equ 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/kg
rem ===========================================================================

echo ****** Testing bee2cmd/kg...

del /q privkey0 privkey1 privkey2 privkey3 pubkey0 pubkey2 pubkey3 2> nul

bee2cmd kg
if %ERRORLEVEL% equ 0 goto Error

bee2cmd kg gen -l256 -pass share:"-pass pass:zed s2 s3 s4"
if %ERRORLEVEL% equ 0 goto Error

bee2cmd kg gen -l256 -pass share:"-pass pass:zed s2 s3 s4" -pass pass:zed
if %ERRORLEVEL% equ 0 goto Error

bee2cmd kg gen -l256 -l192 -pass share:"-pass pass:zed s2 s3 s4" privkey0
if %ERRORLEVEL% equ 0 goto Error

bee2cmd kg gen -l256 -pass share:"-pass pass:zed s2 s3 s4" privkey0
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg val -pass share:"-pass pass:zed s1 s2 s4" privkey0
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg chp -passin share:"-pass pass:zed s3 s1 s4" -passout pass:"root" privkey0
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg gen -pass pass:trent -l192 privkey1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg print -pass pass:trent privkey1 > pubkey1
if %ERRORLEVEL% neq 0 goto Error

for /f "tokens=1" %%A in (pubkey1) do @echo|set /p="%%A" > pubkey1
for %%A in (pubkey1) do set pubkey1_len=%%~zA
if %pubkey1_len% neq 192 goto Error

bee2cmd kg gen -pass pass:alice privkey2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg extr -pass pass:alice privkey2 pubkey2
if %ERRORLEVEL% neq 0 goto Error

for %%A in (pubkey2) do set pubkey2_len=%%~zA
if %pubkey2_len% neq 64 goto Error

bee2cmd kg gen -l96 -pass pass:bob privkey3
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg extr -pass pass:bob privkey3 pubkey3
if %ERRORLEVEL% neq 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/cvc
rem ===========================================================================

echo ****** Testing bee2cmd/cvc...

del /q cert0 req1 cert1 pubkey1 req2 req21 cert2 req3 cert3 2> nul

bee2cmd cvc
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc root -authority BYCA0000 -from 220707 -until 990707 ^
  -pass pass:root -eid EEEEEEEEEE -esign 7777 privkey0 cert0
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc print cert0
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc req -authority BYCA0000 -holder BYCA1000 -from 220711 ^
  -until 221231 -pass pass:trent -eid FFFFFFFFFF -esign 7777 privkey1 req1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc print req1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc iss -authority BYCA0000 -pass pass:root privkey0 cert0 req1 cert1
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc iss -from 220712 -until 221130 -holder BYCA1023 ^
  -eid DDDDDDDDDD -esign BBBB -pass pass:root privkey0 cert0 req1 cert1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc print cert1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc extr cert1 pubkey1
if %ERRORLEVEL% neq 0 goto Error

for %%A in (pubkey1) do set pubkey1_len=%%~zA
if %pubkey1_len% neq 96 goto Error

bee2cmd cvc req -authority BYCA1023 -holder "590082394654" -from 220712 ^
  -until 391231 -pass pass:alice -eid 8888888888 -esign 1111 privkey2 req2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc req -authority BYCA1023 -holder "590082394654" -from 000000 ^
  -until 000000 -pass pass:alice privkey2 req21
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc iss -pass pass:trent privkey1 cert1 req2 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc match -pass pass:alice privkey2 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc match -pass pass:alisa privkey2 cert2
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc print cert2
if %ERRORLEVEL% neq 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd cvc print -from cert1`) do (
  set from=%%F
)
if "%from%" neq "220712" goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd cvc print -until cert1`) do (
  set until=%%F
)
if "%until%" neq "221130" goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd cvc print -eid cert1`) do (
  set eid=%%F
)
if "%eid%" neq "DDDDDDDDDD" goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd cvc print -esign cert1`) do (
  set esign=%%F
)
if "%esign%" neq "3333" goto Error

bee2cmd cvc val cert0 cert0
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc val -date 220707 cert0 cert1 
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc val -date 220712 cert0 cert1 
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc val -date 220707 cert0 cert1 cert2
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc val -date 220712 cert0 cert1 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc val -date 220712 cert0 cert1 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc val -date 221201 cert0 cert1 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc val -date 400101 cert0 cert1 cert2
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc val -date cert0 cert1 cert2
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvc val cert0 cert1 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc shorten -pass pass:trent -until 391230 privkey1 cert1 cert2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc val cert0 cert1 cert2
if %ERRORLEVEL% neq 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd cvc print -until cert2`) do (
  set until=%%F
)
if "%until%" neq "391230" goto Error

bee2cmd cvc req -authority BYCA1023 -from 221030 -until 391231 ^
  -holder 590082394655 -pass pass:bob privkey3 req3
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc print req3
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvc iss -pass pass:trent privkey1 cert1 req3 cert3
if %ERRORLEVEL% neq 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/sig
rem ===========================================================================

echo ****** Testing bee2cmd/sig...

del /q ff ss cert01 cert11 cert21 body sig 2> nul

echo test> ff
echo sig> ss

bee2cmd sig
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig val -pubkey pubkey2 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig val -anchor cert0 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig val -anchor cert2 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig val -pubkey pubkey2 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig val -anchor cert0 ff
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig val -anchor cert2 ff
if %ERRORLEVEL% equ 0 goto Error

del /q ss 1> nul

bee2cmd sig sign -certs "cert1 cert2" -date 400101 -pass pass:alice ^
  privkey2 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig sign -certs "cert1 cert2" -date 230526 -pass pass:alice ^
  privkey2 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -pubkey pubkey2 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert2 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert1 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert0 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig sign -certs "cert0 cert1 cert2" -pass pass:alice privkey2 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -pubkey pubkey2 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert2 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert1 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert0 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig extr -cert0 ff cert01
if %ERRORLEVEL% neq 0 goto Error

fc /b cert01 cert0 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig extr -cert1 ff cert11
if %ERRORLEVEL% neq 0 goto Error

fc /b cert1 cert11 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig extr -cert2 ff cert21
if %ERRORLEVEL% neq 0 goto Error

fc /b cert2 cert21 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig extr -body ff body
if %ERRORLEVEL% neq 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`type body`) do (
  set body=%%F
)
if "%body%" neq "test" goto Error

bee2cmd sig extr -sig ff sig
if %ERRORLEVEL% neq 0 goto Error

del /q ss body 2> nul

bee2cmd sig sign -certs cert2 -pass pass:alice privkey2 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -pubkey pubkey2 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert2 ff ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert1 ff ss
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig extr -body ss body
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig sign -pass pass:alice -date 230526 privkey2 ff ff
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig sign -pass pass:alice -date 230526 privkey2 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -pubkey pubkey2 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert2 ff
if %ERRORLEVEL% equ 0 goto Error

bee2cmd sig print ss
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig print ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig print -date ss
if %ERRORLEVEL% equ 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd sig print -certc ss`) do (
  set certc=%%F
)
if "%certc%" neq "1" goto Error

bee2cmd sig sign -pass pass:bob -certs "cert1 cert3" privkey3 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -pubkey pubkey3 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert1 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert3 ff
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert3 ff ff
if %ERRORLEVEL% equ 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/cvr
rem ===========================================================================

echo ****** Testing bee2cmd/cvr...

del /q ring2 cert21 cert31 2> nul

bee2cmd cvr
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvr init -pass pass:alice privkey2 cert2 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr add -pass pass:alice privkey2 cert2 cert3 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr add -pass pass:alice privkey2 cert2 cert3 ring2
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvr val cert2 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig val -anchor cert2 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr find ring2 cert3
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr find ring2 cert2
if %ERRORLEVEL% equ 0 goto Error

bee2cmd cvr extr -cert0 ring2 cert31
if %ERRORLEVEL% neq 0 goto Error

fc /b cert31 cert3 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig extr -cert0 ring2 cert21
if %ERRORLEVEL% neq 0 goto Error

fc /b cert21 cert2 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr print ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr print -certc ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd sig print ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr add -pass pass:alice privkey2 cert2 cert0 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr add -pass pass:alice privkey2 cert2 cert1 ring2
if %ERRORLEVEL% neq 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd cvr print -certc ring2`) do (
  set certc=%%F
)
if "%certc%" neq "3" goto Error

bee2cmd cvr del -pass pass:alice privkey2 cert2 cert1 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr del -pass pass:alice privkey2 cert2 cert0 ring2
if %ERRORLEVEL% neq 0 goto Error

bee2cmd cvr del -pass pass:alice privkey2 cert2 cert0 ring2
if %ERRORLEVEL% equ 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/csr
rem ===========================================================================

echo ****** Testing bee2cmd/csr...

del /q zed.sk1 zed.csr1 2> nul

bee2cmd csr
if %ERRORLEVEL% equ 0 goto Error

bee2cmd csr val zed.csr
if %ERRORLEVEL% neq 0 goto Error

bee2cmd kg gen -pass pass:zed1 zed.sk1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd csr rewrap -pass pass:zed1 zed.sk1 zed.csr zed.csr1
if %ERRORLEVEL% neq 0 goto Error

bee2cmd csr val zed.csr1
if %ERRORLEVEL% neq 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/stamp
rem ===========================================================================

echo ****** Testing bee2cmd/stamp...

del /q body stamp 2> nul

echo body> body

bee2cmd stamp
if %ERRORLEVEL% equ 0 goto Error

bee2cmd stamp val body
if %ERRORLEVEL% equ 0 goto Error

bee2cmd stamp gen body body
if %ERRORLEVEL% equ 0 goto Error

bee2cmd stamp gen body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd stamp val body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd stamp val body body
if %ERRORLEVEL% equ 0 goto Error

bee2cmd stamp gen body stamp
if %ERRORLEVEL% neq 0 goto Error

bee2cmd stamp val body stamp
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix append body stamp
if %ERRORLEVEL% neq 0 goto Error

bee2cmd stamp val body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd stamp val body stamp
if %ERRORLEVEL% equ 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/es
rem ===========================================================================

echo ****** Testing bee2cmd/es...

del /q dd 2> nul

bee2cmd es
if %ERRORLEVEL% equ 0 goto Error

bee2cmd es print
if %ERRORLEVEL% neq 0 goto Error

bee2cmd es read sys 1 dd
if %ERRORLEVEL% neq 0 goto Error

for %%A in (dd) do set dd_len=%%~zA
if %dd_len% neq 1024 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/st
rem ===========================================================================

echo ****** Testing bee2cmd/st...

bee2cmd st
if %ERRORLEVEL% equ 0 goto Error

bee2cmd st alg
if %ERRORLEVEL% neq 0 goto Error

bee2cmd st rng
if %ERRORLEVEL% neq 0 goto Error

bee2cmd st stamp
if %ERRORLEVEL% neq 0 goto Error

bee2cmd st crc
if %ERRORLEVEL% neq 0 goto Error

bee2cmd st crc 123
if %ERRORLEVEL% neq 0 goto Error

echo ****** OK

rem ===========================================================================
rem  bee2cmd/affix
rem ===========================================================================

echo ****** Testing bee2cmd/affix...

del /q body body1 stamp p1 p10 s0 2> nul

echo body> body
echo body> body1

bee2cmd affix
if %ERRORLEVEL% equ 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd affix print -sc body`) do (
  set sc=%%F
)
if "%sc%" neq "0" goto Error

bee2cmd stamp gen body stamp
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix prepend body zed.cert
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix prepend body zed.cert
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix append body stamp
if %ERRORLEVEL% neq 0 goto Error

for /f "tokens=* USEBACKQ" %%F in (`bee2cmd affix print -pc body`) do (
  set pc=%%F
)
if "%pc%" neq "2" goto Error

bee2cmd affix print body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix extr -p1 body p1
if %ERRORLEVEL% neq 0 goto Error

fc /b p1 zed.cert 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix extr -p10 body p10
if %ERRORLEVEL% equ 0 goto Error

bee2cmd affix extr -s0 body s0
if %ERRORLEVEL% neq 0 goto Error

fc /b s0 stamp 1> nul
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix behead body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix behead body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix behead body
if %ERRORLEVEL% equ 0 goto Error

bee2cmd affix drop body
if %ERRORLEVEL% neq 0 goto Error

bee2cmd affix drop body
if %ERRORLEVEL% equ 0 goto Error

echo body> body1

fc /b body body1 1> nul
if %ERRORLEVEL% neq 0 goto Error

echo ****** OK

rem ===========================================================================
rem  exit
rem ===========================================================================

goto End

if %ERRORLEVEL% equ 0 goto Error

:Error
echo ****** Failed

:End