-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseald_sdk.h
2063 lines (1794 loc) · 98.7 KB
/
seald_sdk.h
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
#ifndef LIB_SEALD_SDK_H
#define LIB_SEALD_SDK_H
// Version
/**
* The version of the Seald SDK.
*/
char* SealdSdk_Version();
// Helper SealdError
/**
* SealdError represents an error that happened during an operation.
* Not all fields are necessarily filled.
*/
typedef struct {
/** If the error is returned by the Seald server, the HTTP status code. */
int Status;
/** The error code, which is a machine-readable string that represents this error. */
char* Code;
/** The error ID, which is a unique string for the precise place this error was thrown from. */
char* Id;
/** A human-readable description of the error. */
char* Description;
/** Details about the error. */
char* Details;
/** The raw underlying error. */
char* Raw;
/** The call stack in Seald native code. */
char* NativeStack;
} SealdError;
/**
* SealdError_Free frees the memory allocated for the SealdError and all its fields.
*
* @param err The SealdError to free.
*/
void SealdError_Free(SealdError* err);
// Helper SealdStringArray
/**
* SealdStringArray holds an array of strings.
*/
typedef struct SealdStringArray SealdStringArray;
/**
* SealdStringArray_New instantiates a new SealdStringArray.
*
* @return The newly created SealdStringArray.
*/
SealdStringArray* SealdStringArray_New();
/**
* SealdStringArray_Free frees the memory allocated for the SealdStringArray itself, and all strings contained therein.
*
* @param array The SealdStringArray to free.
*/
void SealdStringArray_Free(SealdStringArray* array);
/**
* SealdStringArray_Add adds a given string to the array.
* SealdStringArray_Add does *not* take ownership of the given strings. It creates a copy for itself.
*
* @param array The SealdStringArray to add a string to.
* @param s The string to add.
*/
void SealdStringArray_Add(SealdStringArray* array, char* s);
/**
* SealdStringArray_Get returns the string at position i.
* The caller is responsible for calling `free` on this returned string when no longer necessary.
*
* @param array The SealdStringArray from which to retrieve an element.
* @param i The position from which we want to retrieve the string.
* @return The string at position i.
*/
char* SealdStringArray_Get(SealdStringArray* array, int i);
/**
* SealdStringArray_Size returns the size of the given SealdStringArray.
*
* @param array The SealdStringArray for which to retrieve the size.
* @return The size of the given SealdStringArray.
*/
int SealdStringArray_Size(SealdStringArray* array);
// Helper SealdActionStatus
/**
* SealdActionStatus represents the status of an operation on single user/device
*/
typedef struct {
/** The ID of the user/device concerned by the action */
char* Id;
/** The status of the action: 1 if succeeded, 0 otherwise. */
int Success;
/** A human readable error if applicable */
char* ErrorCode;
/** The result of the action */
char* Result;
} SealdActionStatus;
/**
* SealdActionStatus_Free frees the memory allocated for the SealdActionStatus itself, and all fields within.
*
* @param d The SealdActionStatus to free.
*/
void SealdActionStatus_Free(SealdActionStatus* d);
// Helper SealdActionStatusArray
/**
* SealdActionStatusArray holds an array of SealdActionStatus instances.
*/
typedef struct SealdActionStatusArray SealdActionStatusArray;
/**
* SealdActionStatusArray instantiates a new SealdActionStatusArray.
*
* @return The newly created SealdActionStatusArray.
*/
SealdActionStatusArray* SealdActionStatusArray_New();
/**
* SealdActionStatusArray_Add adds a given SealdActionStatus instance to the array.
* SealdActionStatusArray_Add *takes ownership* of the given SealdActionStatus.
* The caller *must not* use it anymore, and must not call `free` on it.
*
* @param array The SealdActionStatusArray to add a SealdActionStatus instance to.
* @param d The SealdActionStatus instance to add.
*/
void SealdActionStatusArray_Add(SealdActionStatusArray* array, SealdActionStatus* d);
/**
* SealdActionStatusArray_Free frees the memory allocated for the SealdActionStatusArray itself, and all SealdActionStatus instances contained therein.
*
* @param array The SealdActionStatusArray to free.
*/
void SealdActionStatusArray_Free(SealdActionStatusArray* array);
/**
* SealdActionStatusArray_Size returns the size of the given SealdActionStatusArray.
*
* @param array The SealdActionStatusArray for which to retrieve the size.
* @return The size of the given SealdActionStatusArray.
*/
int SealdActionStatusArray_Size(SealdActionStatusArray* array);
/**
* SealdActionStatusArray_Get returns a reference to the SealdActionStatus instance at position i.
* The caller *must not* call `free` on it.
*
* @param array The SealdActionStatusArray from which to retrieve an element.
* @param i The position from which we want to retrieve the SealdActionStatus instance.
* @return The SealdActionStatus instance at position i.
*/
SealdActionStatus* SealdActionStatusArray_Get(SealdActionStatusArray* array, int i);
// Helper SealdRevokeResult
/**
* SealdRevokeResult represents the result of a revocation operation.
*/
typedef struct {
/** The Seald recipients the revocation operation acted on */
SealdActionStatusArray* Recipients;
/** The proxy sessions the revocation operation acted on */
SealdActionStatusArray* ProxySessions;
} SealdRevokeResult;
/**
* SealdRevokeResult_Free frees the memory allocated for the SealdRevokeResult itself, and all fields within.
*
* @param d The SealdRevokeResult to free.
*/
void SealdRevokeResult_Free(SealdRevokeResult* d);
// Helper SealdClearFile
/**
* SealdClearFile represents a decrypted file.
*/
typedef struct {
/** The filename of the decrypted file */
char* Filename;
/** The ID of the EncryptionSession to which this file belongs */
char* SessionId;
/** The content of the decrypted file */
unsigned char* FileContent;
/** The length of FileContent */
int FileContentLen;
} SealdClearFile;
/**
* SealdClearFile_Free is a helper to free a SealdClearFile instance and all fields within.
*
* @param cf The SealdClearFile to free.
*/
void SealdClearFile_Free(SealdClearFile* cf);
// Helper SealdTmrAccessesRetrievalFilters
/**
* SealdTmrAccessesRetrievalFilters holds the tmr accesses filters used when retrieving an EncryptionSession.
*/
typedef struct {
/** SealdId of the user who created the TMR access. */
char* CreatedById;
/** Id of the TMR access to use. */
char* TmrAccessId;
} SealdTmrAccessesRetrievalFilters;
/**
* SealdTmrAccessesRetrievalFilters_Free is a helper to free a SealdTmrAccessesRetrievalFilters instance and all fields within.
*
* @param filters The SealdTmrAccessesRetrievalFilters to free.
*/
void SealdTmrAccessesRetrievalFilters_Free(SealdTmrAccessesRetrievalFilters* filters);
// Helper SealdTmrAccessesConvertFilters
/**
* SealdTmrAccessesConvertFilters holds the tmr accesses filters used when converting TMR accesses.
*/
typedef struct {
/** Id of the session with the TMR access to convert. */
char* SessionId;
/** SealdId of the user who created the TMR accesses to convert. */
char* CreatedById;
/** Id of the TMR access to convert. */
char* TmrAccessId;
} SealdTmrAccessesConvertFilters;
/**
* SealdTmrAccessesConvertFilters_Free is a helper to free a SealdTmrAccessesConvertFilters instance and all fields within.
*
* @param filters The SealdTmrAccessesConvertFilters to free.
*/
void SealdTmrAccessesConvertFilters_Free(SealdTmrAccessesConvertFilters* filters);
// Helper SealdConvertTmrAccessesResult
/**
* SealdConvertTmrAccessesResult is returned when calling SealdSdk_ConvertTmrAccesses,
* containing the result of conversion
*/
typedef struct {
/** Status of the conversion `ok` or `ko`. */
char* Status;
/** IDs of the accesses that were fully converted. */
SealdStringArray* Converted;
/** The number of conversions that succeeded. */
int Succeeded;
/** The number of conversions that failed. */
int Errored;
} SealdConvertTmrAccessesResult;
/**
* SealdConvertTmrAccessesResult_Free is a helper to free a SealdConvertTmrAccessesResult instance and all fields within.
*
* @param result The SealdConvertTmrAccessesResult to free.
*/
void SealdConvertTmrAccessesResult_Free(SealdConvertTmrAccessesResult* result);
// Helper SealdAccountInfo
/**
* SealdAccountInfo is returned when calling SealdSdk_createAccount or SealdSdk_getCurrentAccountInfo,
* containing information about the local account.
*/
typedef struct {
/** The ID of the current user for this SDK instance. */
char* UserId;
/** The ID of the current device for this SDK instance. */
char* DeviceId;
/** The date at which the current device keys expire, as a Unix timestamp in seconds. For continued operation, renew your device keys before this date. `0` if it is not known locally: use SealdSdk_UpdateCurrentDevice to retrieve it. */
long long DeviceExpires;
} SealdAccountInfo;
/**
* SealdAccountInfo_Free is a helper to free a SealdAccountInfo instance and all fields within.
*
* @param info The SealdAccountInfo to free.
*/
void SealdAccountInfo_Free(SealdAccountInfo* info);
// Helper SealdInitializeOptions
/**
* SealdInitializeOptions is the main options object for initializing the SDK instance
*/
typedef struct {
/** ApiURL is the Seald server for this instance to use. This value is given on your Seald dashboard. */
char* ApiURL;
/** AppId is the ID given by the Seald server to your app. This value is given on your Seald dashboard. */
char* AppId;
/** KeySize is the Asymmetric key size for newly generated keys. Defaults to 4096. Warning: for security, it is extremely not recommended to lower this value. For advanced use only. */
int KeySize;
/** DatabasePath is the path where to store the local Seald database. If `NULL` or empty, uses an in-memory only database. */
char* DatabasePath;
/** DatabaseEncryptionKey is the encryption key with which to encrypt the local Seald database. Required when passing `DatabasePath`. This **must** be a cryptographically random buffer of 64 bytes. */
unsigned char* DatabaseEncryptionKey;
/** DatabaseEncryptionKeyLen The length of DatabaseEncryptionKey. */
int DatabaseEncryptionKeyLen;
/** EncryptionSessionCacheTTL is the duration of cache lifetime in Milliseconds. `-1` to cache forever. `0` for no cache. */
long long EncryptionSessionCacheTTL;
/** LogLevel is the minimum level of logs you want. All logs of this level or above will be displayed. `-1`: Trace; `0`: Debug; `1`: Info; `2`: Warn; `3`: Error; `4`: Fatal; `5`: Panic; `6`: NoLevel; `7`: Disabled. */
signed char LogLevel;
/** LogNoColor should be set to `0` if you want to enable colors in the log output, `1` if you don't. */
int LogNoColor;
/** InstanceName is an arbitrary name to give to this Seald instance. Can be useful for debugging when multiple instances are running in parallel, as it is added to logs. */
char* InstanceName;
/** Platform is a name that references the platform on which the SDK is running. */
char* Platform;
} SealdInitializeOptions;
// Helper SealdCreateSubIdentityResponse
/**
* SealdCreateSubIdentityResponse represents a newly created sub identity.
*/
typedef struct {
/** The ID of the newly created device. */
char* DeviceId;
/** The identity export of the newly created sub-identity. */
unsigned char* BackupKey;
/** The length of BackupKey. */
int BackupKeyLen;
} SealdCreateSubIdentityResponse;
/**
* SealdCreateSubIdentityResponse_Free is a helper to free a SealdCreateSubIdentityResponse instance and all fields within.
*
* @param resp The SealdCreateSubIdentityResponse to free.
*/
void SealdCreateSubIdentityResponse_Free(SealdCreateSubIdentityResponse* resp);
// Helper SealdConnector
/**
* SealdConnector represents all details about a connector.
*/
typedef struct {
char* SealdId;
char* Type;
char* Value;
char* Id;
char* State;
} SealdConnector;
/**
* SealdConnector_Free is a helper to free a SealdConnector instance and all fields within.
*
* @param c The SealdConnector to free.
*/
void SealdConnector_Free(SealdConnector* c);
// Helper SealdConnectorsArray
/**
* SealdConnectorsArray holds an array of SealdConnector instances.
*/
typedef struct SealdConnectorsArray SealdConnectorsArray;
/**
* SealdConnectorsArray_New instantiates a new SealdConnectorsArray.
*
* @return The newly created SealdConnectorsArray.
*/
SealdConnectorsArray* SealdConnectorsArray_New();
/**
* SealdConnectorsArray_Free frees the memory allocated for the SealdConnectorsArray itself, and all SealdConnector instances contained therein.
*
* @param array The SealdConnectorsArray to free.
*/
void SealdConnectorsArray_Free(SealdConnectorsArray* array);
/**
* SealdConnectorsArray_Add adds a given SealdConnector instance to the array.
* SealdConnectorsArray_Add *takes ownership* of the given SealdConnector.
* The caller *must not* use it anymore, and must not call `free` on it.
*
* @param array The SealdConnectorsArray to add a SealdConnector instance to.
* @param c The SealdConnector instance to add.
*/
void SealdConnectorsArray_Add(SealdConnectorsArray* array, SealdConnector* c);
/**
* SealdConnectorsArray_Get returns a reference to the SealdConnector instance at position i.
* The caller *must not* call `free` on it.
*
* @param array The SealdConnectorsArray from which to retrieve an element.
* @param i The position from which we want to retrieve the SealdConnector instance.
* @return The SealdConnector instance at position i.
*/
SealdConnector* SealdConnectorsArray_Get(SealdConnectorsArray* array, int i);
/**
* SealdConnectorsArray_Size returns the size of the given SealdConnectorsArray.
*
* @param array The SealdConnectorsArray for which to retrieve the size.
* @return The size of the given SealdConnectorsArray.
*/
int SealdConnectorsArray_Size(SealdConnectorsArray* array);
// Helper SealdConnectorTypeValueArray
/**
* SealdConnectorTypeValueArray holds an array of connector type-value pairs.
*/
typedef struct SealdConnectorTypeValueArray SealdConnectorTypeValueArray;
/**
* SealdConnectorTypeValueArray_New instantiates a new SealdConnectorTypeValueArray.
*
* @return The newly created SealdConnectorTypeValueArray.
*/
SealdConnectorTypeValueArray* SealdConnectorTypeValueArray_New();
/**
* SealdConnectorTypeValueArray_Free frees the memory allocated for the SealdConnectorTypeValueArray itself, and all connector type-value pairs contained therein.
*
* @param array The SealdConnectorTypeValueArray to free.
*/
void SealdConnectorTypeValueArray_Free(SealdConnectorTypeValueArray* array);
/**
* SealdConnectorTypeValueArray_Add adds a given connector type-value pair to the array.
* SealdConnectorTypeValueArray_Add *does not take ownership* of the given strings. It creates copies for itself.
*
* @param array The SealdConnectorTypeValueArray to add a connector type-value pair to.
* @param connectorType The connector type to add.
* @param connectorValue The connector value to add.
*/
void SealdConnectorTypeValueArray_Add(SealdConnectorTypeValueArray* array, char* connectorType, char* connectorValue);
/**
* SealdConnectorTypeValueArray_Get returns the connector type-value pair at position i.
* The caller is responsible for calling `free` on the returned type and value when no longer necessary.
*
* @param array The SealdConnectorTypeValueArray from which to retrieve a connector type-value pair.
* @param i The position from which we want to retrieve the connector type-value pair.
* @param connectorType A pointer to which to write the connector type at position i.
* @param connectorValue A pointer to which to write the connector value at position i.
*/
void SealdConnectorTypeValueArray_Get(SealdConnectorTypeValueArray* array, int i, char** connectorType, char** connectorValue);
/**
* SealdConnectorTypeValueArray_Size returns the size of the given SealdConnectorTypeValueArray.
*
* @param array The SealdConnectorTypeValueArray for which to retrieve the size.
* @return The size of the given SealdConnectorTypeValueArray.
*/
int SealdConnectorTypeValueArray_Size(SealdConnectorTypeValueArray* array);
// Helper SealdRecipientsWithRightsArray
/**
* SealdRecipientsWithRightsArray holds an array of recipients with rights.
*/
typedef struct SealdRecipientsWithRightsArray SealdRecipientsWithRightsArray;
/**
* SealdRecipientsWithRightsArray_New instantiates a new SealdRecipientsWithRightsArray.
*
* @return The newly created SealdRecipientsWithRightsArray.
*/
SealdRecipientsWithRightsArray* SealdRecipientsWithRightsArray_New();
/**
* SealdRecipientsWithRightsArray_Free frees the memory allocated for the SealdRecipientsWithRightsArray itself, and all SealdRecipientsWithRights contained therein.
*
* @param array The SealdRecipientsWithRightsArray to free.
*/
void SealdRecipientsWithRightsArray_Free(SealdRecipientsWithRightsArray* array);
/**
* SealdRecipientsWithRightsArray_Add adds a recipient with its associated rights to the array.
* SealdRecipientsWithRightsArray_Add *does not take ownership* of the given strings and booleans. It creates copies for itself.
*
* @param array The SealdRecipientsWithRightsArray to add the recipients-rights pair to.
* @param sealdId Internal Seald IDs. Returned for users with SealdSdk_getCurrentAccountInfo, for groups when creating them.
* @param readRight The right to read the message.
* @param forwardRight The right to forward the message to another user.
* @param revokeRight The right to revoke another user from a message, or to remove rights from them.
*/
void SealdRecipientsWithRightsArray_Add(SealdRecipientsWithRightsArray* array, char* sealdId, int readRight, int forwardRight, int revokeRight);
/**
* SealdRecipientsWithRightsArray_AddWithDefaultRights adds a recipient with default rights.
* Default rights are: read: true, forward: true, revoke: false
* Default rights for the current user when creating an encryptionSession are read: true, forward: true, revoke: true
*
* @param array The SealdRecipientsWithRightsArray to add the recipients-rights pair to.
* @param sealdId Internal Seald IDs. Returned for users with SealdSdk_getCurrentAccountInfo, for groups when creating them.
*/
void SealdRecipientsWithRightsArray_AddWithDefaultRights(SealdRecipientsWithRightsArray* array, char* sealdId);
/**
* SealdRecipientsWithRightsArray_Get returns the user and its associated rights at position i.
* For rights, returns -1 if rights are not set (using default rights).
* The caller is responsible for calling `free` on the returned recipientId when no longer necessary.
*
* @param array The SealdRecipientsWithRightsArray from which to retrieve the recipients-rights pair.
* @param i The position from which we want to retrieve the recipients-rights pair.
* @param recipientId A pointer to which to write the recipient id at position i.
* @param recipientRightRead A pointer to which to write the read right value at position i.
* @param recipientRightForward A pointer to which to write the forward right value at position i.
* @param recipientRightRevoke A pointer to which to write the revoke right value at position i.
*/
void SealdRecipientsWithRightsArray_Get(SealdRecipientsWithRightsArray* array, int i, char** recipientId, int* recipientRightRead, int* recipientRightForward, int* recipientRightRevoke);
/**
* SealdRecipientsWithRightsArray_Size returns the size of the given SealdRecipientsWithRightsArray.
*
* @param array The SealdRecipientsWithRightsArray for which to retrieve the size.
* @return The size of the given SealdRecipientsWithRightsArray.
*/
int SealdRecipientsWithRightsArray_Size(SealdRecipientsWithRightsArray* array);
// Helper SealdTmrRecipientsWithRightsArray
/**
* SealdTmrRecipientsWithRightsArray holds an array of TMR recipients with associated rights.
*/
typedef struct SealdTmrRecipientsWithRightsArray SealdTmrRecipientsWithRightsArray;
/**
* SealdTmrRecipientsWithRightsArray_New instantiates a new SealdTmrRecipientsWithRightsArray.
*
* @return The newly created SealdTmrRecipientsWithRightsArray.
*/
SealdTmrRecipientsWithRightsArray* SealdTmrRecipientsWithRightsArray_New();
/**
* SealdTmrRecipientsWithRightsArray_Free frees the memory allocated for the SealdTmrRecipientsWithRightsArray itself, and all SealdTmrRecipientWithRights contained therein.
*
* @param array The SealdTmrRecipientsWithRightsArray to free.
*/
void SealdTmrRecipientsWithRightsArray_Free(SealdTmrRecipientsWithRightsArray* array);
/**
* SealdTmrRecipientsWithRightsArray_Add adds a tmr recipient with its associated rights to the array.
* SealdTmrRecipientsWithRightsArray_Add *does not take ownership* of the given strings and booleans. It creates copies for itself.
*
* @param array The SealdTmrRecipientsWithRightsArray to add the recipients-rights pair to.
* @param authFactorType The type of authentication factor. 'EM' or 'SMS'
* @param authFactorValue The value of authentication factor.
* @param overEncryptionKey The TMR over-encryption key. This *MUST* be a cryptographically random buffer of 64 bytes.
* @param overEncryptionKeyLen The length of overEncryptionKey.
* @param readRight The right to read the message.
* @param forwardRight The right to forward the message to another user.
* @param revokeRight The right to revoke another user from a message, or to remove rights from them.
* @param error A pointer to a SealdError* where details will be stored in case of error.
*/
void SealdTmrRecipientsWithRightsArray_Add(SealdTmrRecipientsWithRightsArray* array, char* authFactorType, char* authFactorValue, unsigned char* overEncryptionKey, int overEncryptionKeyLen, int readRight, int forwardRight, int revokeRight);
/**
* SealdTmrRecipientsWithRightsArray_AddWithDefaultRights adds a recipient with default rights.
* SealdTmrRecipientsWithRightsArray_AddWithDefaultRights *does not take ownership* of the given strings and booleans. It creates copies for itself.
* Default rights are: read: true, forward: true, revoke: false
*
* @param array The SealdTmrRecipientsWithRightsArray to add the recipients-rights pair to.
* @param authFactorType The type of authentication factor. 'EM' or 'SMS'
* @param authFactorValue The value of authentication factor.
* @param overEncryptionKey The TMR over-encryption key. This *MUST* be a cryptographically random buffer of 64 bytes.
* @param overEncryptionKeyLen The length of overEncryptionKey.
*/
void SealdTmrRecipientsWithRightsArray_AddWithDefaultRights(SealdTmrRecipientsWithRightsArray* array, char* authFactorType, char* authFactorValue, unsigned char* overEncryptionKey, int overEncryptionKeyLen);
/**
* SealdTmrRecipientsWithRightsArray_Get returns the TMR recipient and its associated rights at position i.
* The caller is responsible for calling `free` on the returned char** when no longer necessary.
*
* @param array The SealdTmrRecipientsWithRightsArray from which to retrieve the recipients-rights pair.
* @param i The position from which we want to retrieve the recipients-rights pair.
* @param authFactorType A pointer to which to write the recipient authentication factor type at position i.
* @param authFactorValue A pointer to which to write the recipient authentication factor value at position i.
* @param overEncryptionKey The TMR over-encryption key. This *MUST* be a cryptographically random buffer of 64 bytes.
* @param overEncryptionKeyLen The length of overEncryptionKey.
* @param recipientRightRead A pointer to which to write the read right value at position i.
* @param recipientRightForward A pointer to which to write the forward right value at position i.
* @param recipientRightRevoke A pointer to which to write the revoke right value at position i.
*/
void SealdTmrRecipientsWithRightsArray_Get(SealdTmrRecipientsWithRightsArray* array, int i, char** authFactorType, char** authFactorValue, unsigned char** overEncryptionKey, int* overEncryptionKeyLen, int* recipientRightRead, int* recipientRightForward, int* recipientRightRevoke);
/**
* SealdTmrRecipientsWithRightsArray_Size returns the size of the given SealdTmrRecipientsWithRightsArray.
*
* @param array The SealdTmrRecipientsWithRightsArray for which to retrieve the size.
* @return The size of the given SealdTmrRecipientsWithRightsArray.
*/
int SealdTmrRecipientsWithRightsArray_Size(SealdTmrRecipientsWithRightsArray* array);
// Helper SealdPreValidationToken
/**
* SealdPreValidationToken represents a way for your server to authorize the adding of a connector.
*/
typedef struct {
char* DomainValidationKeyId;
char* Nonce;
char* Token;
} SealdPreValidationToken;
/**
* SealdPreValidationToken_Free is a helper to free a SealdPreValidationToken instance and all fields within.
*
* @param t The SealdPreValidationToken to free.
*/
void SealdPreValidationToken_Free(SealdPreValidationToken* t);
// Helper SealdMassReencryptOptions
/**
* SealdMassReencryptOptions represents options for SealdSdk_MassReencrypt.
*/
typedef struct {
/** Number of times to retry. Defaults to 3. */
int Retries;
/** Default to 1000. */
int RetrieveBatchSize;
/** Time to wait between retries, in Milliseconds. Defaults to 3 seconds. */
long long WaitBetweenRetries;
/** Whether to wait for provisioning (new behaviour) or not. `1` to wait, `0` to not wait. Defaults to `1`. */
int WaitProvisioning; // bool
/** Time to wait if device is not provisioned on the server yet, in Milliseconds. The actual wait time will be increased on subsequent tries, by `WaitProvisioningTimeStep`, up to `WaitProvisioningTimeMax`. Defaults to 5 seconds. */
long long WaitProvisioningTime;
/** Maximum time to wait if device is not provisioned on the server yet, in Milliseconds. Defaults to 10 seconds. */
long long WaitProvisioningTimeMax;
/** Amount to increase the time to wait if device is not provisioned on the server yet, in Milliseconds. Defaults to 1 second. */
long long WaitProvisioningTimeStep;
/** Maximum number of tries to check if the device is provisioned yet. Defaults to 100. */
int WaitProvisioningRetries;
/** Whether to update the local account before trying the reencryption. `1` to update, `0` to not update. Defaults to `0`. */
int ForceLocalAccountUpdate; // bool
} SealdMassReencryptOptions;
/**
* Initialize a SealdMassReencryptOptions instance with default values.
*/
SealdMassReencryptOptions SealdMassReencryptOptions_Defaults();
// Helper SealdMassReencryptResponse
/**
* SealdMassReencryptResponse represents the results of a call to [SealdSdk.massReencrypt].
*/
typedef struct {
/** The number of session keys that were reencrypted for the given device. */
int Reencrypted;
/** The number of session keys that could not be reencrypted for the given device. */
int Failed;
} SealdMassReencryptResponse;
// Helper SealdDeviceMissingKeys
/**
* SealdDeviceMissingKeys represents a device of the current account which is missing some keys,
* and for which you probably want to call SealdSdk_MassReencrypt.
*/
typedef struct {
/** The ID of the device which is missing some keys. */
char* DeviceId;
} SealdDeviceMissingKeys;
/**
* SealdDeviceMissingKeys_Free frees the memory allocated for the SealdDeviceMissingKeys itself, and all fields within.
*
* @param d The SealdDeviceMissingKeys to free.
*/
void SealdDeviceMissingKeys_Free(SealdDeviceMissingKeys* d);
// Helper SealdDeviceMissingKeysArray
/**
* SealdDeviceMissingKeysArray holds an array of SealdDeviceMissingKeys instances.
*/
typedef struct SealdDeviceMissingKeysArray SealdDeviceMissingKeysArray;
/**
* SealdDeviceMissingKeysArray_New instantiates a new SealdDeviceMissingKeysArray.
*
* @return The newly created SealdDeviceMissingKeysArray.
*/
SealdDeviceMissingKeysArray* SealdDeviceMissingKeysArray_New();
/**
* SealdDeviceMissingKeysArray_Free frees the memory allocated for the SealdDeviceMissingKeysArray itself, and all SealdDeviceMissingKeys instances contained therein.
*
* @param array The SealdDeviceMissingKeysArray to free.
*/
void SealdDeviceMissingKeysArray_Free(SealdDeviceMissingKeysArray* array);
/**
* SealdDeviceMissingKeysArray_Add adds a given SealdDeviceMissingKeys instance to the array.
* SealdDeviceMissingKeysArray_Add *takes ownership* of the given SealdDeviceMissingKeys.
* The caller *must not* use it anymore, and must not call `free` on it.
*
* @param array The SealdDeviceMissingKeysArray to add a SealdDeviceMissingKeys instance to.
* @param d The SealdDeviceMissingKeys instance to add.
*/
void SealdDeviceMissingKeysArray_Add(SealdDeviceMissingKeysArray* array, SealdDeviceMissingKeys* d);
/**
* SealdDeviceMissingKeysArray_Get returns a reference to the SealdDeviceMissingKeys instance at position i.
* The caller *must not* call `free` on it.
*
* @param array The SealdDeviceMissingKeysArray from which to retrieve an element.
* @param i The position from which we want to retrieve the SealdDeviceMissingKeys instance.
* @return The SealdDeviceMissingKeys instance at position i.
*/
SealdDeviceMissingKeys* SealdDeviceMissingKeysArray_Get(SealdDeviceMissingKeysArray* array, int i);
/**
* SealdDeviceMissingKeysArray_Size returns the size of the given SealdDeviceMissingKeysArray.
*
* @param array The SealdDeviceMissingKeysArray for which to retrieve the size.
* @return The size of the given SealdDeviceMissingKeysArray.
*/
int SealdDeviceMissingKeysArray_Size(SealdDeviceMissingKeysArray* array);
// Helper SealdEncryptionSessionRetrievalFlow
/**
* SealdEncryptionSessionRetrievalFlow represents the way the session was retrieved : as a direct recipient, as member of a group, or through a proxy session
*/
typedef enum {
/** The session was created locally. */
SealdEncryptionSessionRetrievalCreated, // 0
/** The session was retrieved as a direct recipient. */
SealdEncryptionSessionRetrievalDirect, // 1
/** The session was retrieved as a member of a group. */
SealdEncryptionSessionRetrievalViaGroup, // 2
/** The session was retrieved through a proxy session. */
SealdEncryptionSessionRetrievalViaProxy, // 3
/** The session was retrieved through a TMR access. */
SealdEncryptionSessionRetrievalViaTmrAccess // 4
} SealdEncryptionSessionRetrievalFlow;
// Helper SealdEncryptionSessionRetrievalDetails
/**
* SealdEncryptionSessionRetrievalDetails represents the details of how an Encryption Session was retrieved.
*/
typedef struct {
/** The way the session was retrieved : as a direct recipient, as member of a group, or through a proxy session. */
SealdEncryptionSessionRetrievalFlow Flow;
/** If the session was retrieved as member of a group, the ID of the group in question. */
char* GroupId;
/** If the session was retrieved through a proxy session, the ID of this proxy session. */
char* ProxySessionId;
/** Indicates if this session was retrieved from the cache. 0 for False. 1 for True. */
int FromCache; // bool
} SealdEncryptionSessionRetrievalDetails;
/**
* SealdEncryptionSessionRetrievalDetails_Free frees the memory allocated for the SealdEncryptionSessionRetrievalDetails itself, and all its fields.
*
* @param details The SealdEncryptionSessionRetrievalDetails to free.
*/
void SealdEncryptionSessionRetrievalDetails_Free(SealdEncryptionSessionRetrievalDetails* details);
// Helper SealdGetSigchainResponse
/**
* SealdGetSigchainResponse is returned when calling SealdSdk_GetSigchainHash,
* containing the hash value and the position of the hash in the sigchain.
*/
typedef struct {
/** The sigchain hash. */
char* Hash;
/** The position of the associated hash in the sigchain */
int Position;
} SealdGetSigchainResponse;
/**
* SealdGetSigchainResponse_Free frees the memory allocated for the SealdGetSigchainResponse itself, and all its fields.
*
* @param sigchainInfo The SealdGetSigchainResponse to free.
*/
void SealdGetSigchainResponse_Free(SealdGetSigchainResponse* sigchainInfo);
// Helper SealdCheckSigchainResponse
/**
* SealdCheckSigchainResponse is returned when calling SealdSdk_CheckSigchainHash,
* containing if the hash was found in the sigchain or not.
*
* If the hash was found, it also contain at which position it was found. Empty pointers otherwise.
*/
typedef struct {
/** Whether or not the hash was found in the user's sigchain. `1` for True, `0` for False. */
int Found;
/** The position in the sigchain where the expected hash was found */
int Position;
/** The number of transaction in the sigchain */
int LastPosition;
} SealdCheckSigchainResponse;
// Class Encryption Session
/**
* SealdEncryptionSession represents an encryption session, with which you can then encrypt / decrypt multiple messages.
* This should not be created directly, and should be retrieved with SealdSdk_RetrieveEncryptionSession
* or SealdSdk_RetrieveEncryptionSessionFromMessage.
*/
typedef struct SealdEncryptionSession SealdEncryptionSession;
/**
* SealdEncryptionSession_Free frees the memory allocated for the SealdEncryptionSession.
*
* @param es The Encryption Session to free
*/
void SealdEncryptionSession_Free(SealdEncryptionSession* es);
/**
* SealdEncryptionSession_Id returns the session ID of this encryption session.
*
* @param es The encryption session instance for which to return the session ID.
* @return The session ID of the given encryption session instance. The caller must call `free` on this when no longer needed.
*/
char* SealdEncryptionSession_Id(SealdEncryptionSession* es);
/**
* SealdEncryptionSession_RetrievalDetails returns the retrieval details of this encryption session.
*
* @param es The encryption session instance for which to return the retrieval details.
* @return The retrieval details of the given encryption session instance. The caller must call [SealdEncryptionSessionRetrievalDetails_Free] on this when no longer needed.
*/
SealdEncryptionSessionRetrievalDetails* SealdEncryptionSession_RetrievalDetails(SealdEncryptionSession* es);
/**
* Add a proxy session as a recipient of this session.
* Any recipient of the proxy session will also be able to retrieve this session.
* The current user has to be a direct recipient of the proxy session.
*
* @param es The SealdEncryptionSession instance.
* @param proxySessionId The ID of the session to add as proxy.
* @param readRight The read right to assign to this proxy.
* @param forwardRight The forward right to assign to this proxy.
* @param revokeRight The revoke right to assign to this proxy.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_AddProxySession(SealdEncryptionSession* es, char* proxySessionId, int readRight, int forwardRight, int revokeRight, SealdError** error);
/**
* Revoke some recipients or proxy sessions from this session.
* If you want to revoke all recipients, see SealdEncryptionSession_RevokeAll instead.
* If you want to revoke all recipients besides yourself, see SealdEncryptionSession_RevokeOthers.
*
* @param es The SealdEncryptionSession instance.
* @param recipientsIds The Seald IDs of users to revoke from this session.
* @param proxySessionsIds The IDs of proxy sessions to revoke from this session.
* @param result A pointer to which to write the response.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_RevokeRecipients(SealdEncryptionSession* es, SealdStringArray* recipientsIds, SealdStringArray* proxySessionsIds, SealdRevokeResult** result, SealdError** error);
/**
* Revoke this session entirely.
*
* @param es The SealdEncryptionSession instance.
* @param result A pointer to which to write the response.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_RevokeAll(SealdEncryptionSession* es, SealdRevokeResult** result, SealdError** error);
/**
* Revoke all recipients besides yourself from this session.
*
* @param es The SealdEncryptionSession instance.
* @param result A pointer to which to write the response.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_RevokeOthers(SealdEncryptionSession* es, SealdRevokeResult** result, SealdError** error);
/**
* Add new recipients to this session.
* These recipients will be able to read all encrypted messages of this session.
*
* To add a user as recipient, the SDK need to add every device associated with the user.
* The returned SealdActionStatusArray instance includes a SealdActionStatus for every DEVICES that needs to be added.
* The `id` field in each SealdActionStatus correspond to the deviceIds of those devices
*
* @param es The SealdEncryptionSession instance.
* @param recipients The Seald IDs of users to add to this session.
* @param result A pointer to which to write the response.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_AddRecipients(SealdEncryptionSession* es, SealdRecipientsWithRightsArray* recipients, SealdActionStatusArray** result, SealdError** error);
/**
* Encrypt a clear-text string into an encrypted message, for the recipients of this session.
*
* @param es The SealdEncryptionSession instance.
* @param clearMessage The message to encrypt.
* @param result A pointer to which to write the resulting encrypted message.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_EncryptMessage(SealdEncryptionSession* es, char* clearMessage, char** result, SealdError** error);
/**
* Decrypt an encrypted message string into the corresponding clear-text string.
*
* @param es The SealdEncryptionSession instance.
* @param encryptedMessage The encrypted message to decrypt.
* @param result A pointer to which to write the resulting decrypted message.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_DecryptMessage(SealdEncryptionSession* es, char* encryptedMessage, char** result, SealdError** error);
/**
* Encrypt a clear-text file into an encrypted file, for the recipients of this session.
*
* @param es The SealdEncryptionSession instance.
* @param clearFile An array of bytes of the clear-text content of the file to encrypt.
* @param clearFileLen The length of clearFile.
* @param filename The name of the file to encrypt.
* @param result A pointer to which to write the resulting encrypted file.
* @param resultLen A pointer to which to write the length of result.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_EncryptFile(SealdEncryptionSession* es, unsigned char* clearFile, int clearFileLen, char* filename, unsigned char** result, int* resultLen, SealdError** error);
/**
* Decrypts an encrypted file into the corresponding clear-text file.
*
* @param es The SealdEncryptionSession instance.
* @param encryptedFile An array of bytes of the content of the encrypted file to decrypt.
* @param encryptedFileLen The length of encryptedFile.
* @param result A pointer to a SealdClearFile* to store the resulting decrypted file.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_DecryptFile(SealdEncryptionSession* es, unsigned char* encryptedFile, int encryptedFileLen, SealdClearFile** result, SealdError** error);
/**
* Encrypt a clear-text file into an encrypted file, for the recipients of this session.
*
* @param es The SealdEncryptionSession instance.
* @param clearFilePath The path of the file to encrypt.
* @param result A pointer to a char pointer where the path of the encrypted file will be stored.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_EncryptFileFromPath(SealdEncryptionSession* es, char* clearFilePath, char** result, SealdError** error);
/**
* Decrypts an encrypted file into the corresponding clear-text file.
*
* @param es The SealdEncryptionSession instance.
* @param encryptedFilePath The path of the file to encrypted file to decrypt.
* @param result A pointer to a char pointer where the path of the decrypted file will be stored.
* @param error A pointer to a SealdError* where details will be stored in case of error.
* @return Error code: `-1` if an error happened, `0` for success.
*/
int SealdEncryptionSession_DecryptFileFromPath(SealdEncryptionSession* es, char* encryptedFilePath, char** result, SealdError** error);
/**
* Add a TMR access to this session for the given authentication factor.
*