-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVault.php
More file actions
1601 lines (1346 loc) · 63.8 KB
/
Copy pathVault.php
File metadata and controls
1601 lines (1346 loc) · 63.8 KB
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
<?php
declare(strict_types=1);
namespace Revault;
use FFI\CData;
/**
* Entry point for encrypted lockboxes, cryptographic keys, local vault
* metadata, the Session Agent, and the platform credential store.
*
* Create one when the application starts, then use it to open lockboxes and
* manage keys and local services. Release disposable values promptly and use
* callback-scoped secret accessors to avoid retaining plaintext. See the
* repository README for installation and examples:
* https://github.com/onepub-dev/reVault#readme
*/
/**
* Loads the reVault engine and provides archive, key, Vault, agent, and
* platform operations.
*
* Loading the engine does not open a Vault or Lockbox. Most applications
* should call load() once, then use the Vault and Lockbox classes shown in the
* package README.
*/
final class Revault
{
private readonly BindingOperations $operations;
private readonly Agent $agent;
private readonly Platform $platform;
/** Loads the bundled native library, or the explicit library path when supplied. */
public function __construct(?string $nativeLibraryPath = null)
{
if ($nativeLibraryPath === '') {
throw new \InvalidArgumentException('nativeLibraryPath must not be empty');
}
$inherited = getenv('REVAULT_LIBRARY');
$selected = $nativeLibraryPath
?? (is_string($inherited) && $inherited !== '' ? $inherited : null)
?? self::nativeLibrary();
$this->operations = BindingOperations::load($selected);
$this->agent = new Agent($this->operations); $this->platform = new Platform($this->operations);
}
private static function nativeLibrary(): string
{
$arch = strtolower(php_uname('m'));
$cpu = match ($arch) {
'x86_64', 'amd64' => 'x86_64',
'aarch64', 'arm64' => 'aarch64',
default => throw new \RuntimeException("unsupported reVault architecture: $arch"),
};
[$target, $file] = match (PHP_OS_FAMILY) {
'Windows' => ["windows-$cpu-msvc", 'revault_api.dll'],
'Darwin' => ["macos-$cpu", 'librevault_api.dylib'],
'Linux' => ["linux-$cpu-gnu", 'librevault_api.so'],
default => throw new \RuntimeException('unsupported reVault operating system: '.PHP_OS_FAMILY),
};
$bundled = dirname(__DIR__)."/native/$target/$file";
if (!is_file($bundled)) { throw new \RuntimeException("revault-api native library is missing for $target; install the matching platform package"); }
return $bundled;
}
/** Returns the optional session agent controller without starting the agent. */
public function agent(): Agent { return $this->agent; }
/** Returns the operating system credential store facade. */
public function platform(): Platform { return $this->platform; }
public static function load(?string $nativeLibraryPath = null): self
{ return new self($nativeLibraryPath); }
public static function runtime(): self { return new self(); }
public static function agentSession(): AgentSession
{ $runtime = new self(); return new AgentSession($runtime->operations); }
/** Returns the last error. */
public function lastError(): string { return $this->operations->lastErrorMessage(); }
/** Returns the last error details. */
public function lastErrorDetails(): object { return $this->operations->bufferLastErrorDetails(); }
/** Returns the newest Lockbox archive format version supported by this engine. */
public function lockboxFormatVersion(): int
{
return $this->operations->lockboxFormatVersion();
}
/** Reads the format version from serialized Lockbox bytes without opening them. */
public function lockboxProbeFormatVersion(string $bytes): int
{
return $this->operations->lockboxProbeFormatVersion($bytes);
}
/** Creates an in memory Lockbox protected by a 32 byte content key. */
public function lockboxCreate(string $key): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreate($key));
}
/** Creates a lockbox with explicit cache capacity, workload, worker policy, and job count. */
public function lockboxCreateWithOptions(string $key, string $cacheMode, int $cacheBytes, string $workload, string $worker, int $jobs): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreateWithOptions($key, $cacheMode, $cacheBytes, $workload, $worker, $jobs));
}
/** Creates an in memory Lockbox protected by the supplied password. */
public function lockboxCreatePassword(string $password): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreatePassword($password));
}
/** Creates a password-protected Lockbox whose first commit establishes
* the supplied profile signing key; close the returned handle after use. */
public function lockboxCreatePasswordWithSigningKey(string $password, OwnedHandle $signingKey): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreatePasswordWithSigningKey($password, $signingKey->nativeHandle()));
}
/** Creates an in memory Lockbox that the supplied contact can open. */
public function lockboxCreateContact(OwnedHandle $contact): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreateContact($contact->nativeHandle()));
}
/** Creates a contact-protected Lockbox whose first commit establishes
* the supplied profile signing key; close the returned handle after use. */
public function lockboxCreateContactWithSigningKey(OwnedHandle $contact, OwnedHandle $signingKey): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreateContactWithSigningKey($contact->nativeHandle(), $signingKey->nativeHandle()));
}
/** Creates an in memory Lockbox and assigns its profile signing key. */
public function lockboxCreateWithSigningKey(string $contentKey, OwnedHandle $signingKey): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxCreateWithSigningKey($contentKey, $signingKey->nativeHandle()));
}
/** Opens serialized Lockbox bytes with a 32 byte content key. */
public function lockboxOpen(string $archive, string $key): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxOpen($archive, $key));
}
/** Opens a lockbox with explicit cache capacity, workload, worker policy, and job count. */
public function lockboxOpenWithOptions(string $archive, string $key, string $cacheMode, int $cacheBytes, string $workload, string $worker, int $jobs): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxOpenWithOptions($archive, $key, $cacheMode, $cacheBytes, $workload, $worker, $jobs));
}
/** Opens serialized Lockbox bytes with the supplied password. */
public function lockboxOpenPassword(string $archive, string $password): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxOpenPassword($archive, $password));
}
/** Opens serialized Lockbox bytes with the supplied contact private key. */
public function lockboxOpenContact(string $archive, OwnedHandle $contact): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxOpenContact($archive, $contact->nativeHandle()));
}
/** Reads public header, signature, and access slot metadata from a Lockbox file. */
public function lockboxInspectFile(string $path): \Revault\FileInspection
{
return $this->operations->lockboxInspectFile($path);
}
/** Scans a damaged Lockbox file with its 32 byte content key. */
public function lockboxRecoveryScanPath(string $path, string $key): \Revault\RecoveryReport
{
return $this->operations->lockboxRecoveryScanPath($path, $key);
}
/** Scans damaged serialized Lockbox bytes with their 32 byte content key. */
public function lockboxRecoveryScan(string $bytes, string $key): \Revault\RecoveryReport
{
return $this->operations->lockboxRecoveryScan($bytes, $key);
}
/** Builds a new Lockbox from recoverable records without changing the source. */
public function lockboxRecoverySalvage(string $bytes, string $key, OwnedHandle $signingKey): Lockbox
{
return new Lockbox($this->operations, $this->operations->lockboxRecoverySalvage($bytes, $key, $signingKey->nativeHandle()));
}
/** Generates a contact encryption key pair using secure random data. */
public function keyContactGenerate(): ContactKeyPair
{
return new ContactKeyPair($this->operations, $this->operations->keyContactGenerate());
}
/** Imports a contact key pair from its private binary record. */
public function keyContactFromPrivate(string $bytes): ContactKeyPair
{
return new ContactKeyPair($this->operations, $this->operations->keyContactFromPrivate($bytes));
}
/** Imports a contact public key from its binary representation. */
public function keyContactPublicFromBytes(string $bytes): ContactPublicKey
{
return new ContactPublicKey($this->operations, $this->operations->keyContactPublicFromBytes($bytes));
}
/** Generates a profile signing key pair using secure random data. */
public function generateProfileSigningKeyPair(): ProfileSigningKeyPair
{
return new ProfileSigningKeyPair($this->operations, $this->operations->keySigningGenerate());
}
/** Imports a profile signing key pair from its private binary record. */
public function profileSigningKeyPairFromPrivate(string $bytes): ProfileSigningKeyPair
{
return new ProfileSigningKeyPair($this->operations, $this->operations->keySigningFromPrivate($bytes));
}
/** Imports a profile signing public key from its binary representation. */
public function profileSigningPublicKeyFromBytes(string $bytes): ProfileSigningPublicKey
{
return new ProfileSigningPublicKey($this->operations, $this->operations->keySigningPublicFromBytes($bytes));
}
/** Exports a private key in the requested KeyExportFormat. */
public function vaultKeyExportPrivate(OwnedHandle $key, string $format): string
{
return $this->operations->vaultKeyExportPrivate($key->nativeHandle(), $format);
}
/** Exports a public key in the requested KeyExportFormat. */
public function vaultKeyExportPublic(OwnedHandle $key, string $format): string
{
return $this->operations->vaultKeyExportPublic($key->nativeHandle(), $format);
}
/** Imports a private contact key from a detected supported encoding. */
public function vaultKeyImportPrivate(string $bytes): ContactKeyPair
{
return new ContactKeyPair($this->operations, $this->operations->vaultKeyImportPrivate($bytes));
}
/** Imports a public contact key from a detected supported encoding. */
public function vaultKeyImportPublic(string $bytes): ContactPublicKey
{
return new ContactPublicKey($this->operations, $this->operations->vaultKeyImportPublic($bytes));
}
/** Returns the stable fingerprint used to verify a public key. */
public function vaultKeyFingerprint(OwnedHandle $key): string
{
return $this->operations->vaultKeyFingerprint($key->nativeHandle());
}
/** Encodes key bytes as hexadecimal text. */
public function vaultKeyFormatHex(string $bytes): string
{
return $this->operations->vaultKeyFormatHex($bytes);
}
/** Decodes hexadecimal key text and rejects malformed input. */
public function vaultKeyDecodeHex(string $text): string
{
return $this->operations->vaultKeyDecodeHex($text);
}
/** Encodes key bytes using Crockford Base32. */
public function vaultKeyFormatCrockford(string $bytes): string
{
return $this->operations->vaultKeyFormatCrockford($bytes);
}
/** Groups a Crockford code for easier reading and transcription. */
public function vaultKeyFormatCrockfordReading(string $code): string
{
return $this->operations->vaultKeyFormatCrockfordReading($code);
}
/** Decodes Crockford Base32 key text and rejects malformed input. */
public function vaultKeyDecodeCrockford(string $code): string
{
return $this->operations->vaultKeyDecodeCrockford($code);
}
/** Encodes arbitrary bytes as hexadecimal text. */
public function vaultKeyHexEncode(string $bytes): string
{
return $this->operations->vaultKeyHexEncode($bytes);
}
/** Decodes arbitrary hexadecimal text and rejects malformed input. */
public function vaultKeyHexDecode(string $text): string
{
return $this->operations->vaultKeyHexDecode($text);
}
/** Opens an existing Vault directory with its passphrase. */
public function vaultDirectoryOpen(string $root, string $password): Vault
{
return new Vault($this->operations, $this->operations->vaultDirectoryOpen($root, $password));
}
/** Returns the newest Vault structure version supported by this engine. */
public function vaultStructureVersionCurrent(): int
{
return $this->operations->vaultStructureVersionCurrent();
}
/** Reads an existing Vault structure version without changing it. */
public function vaultDirectoryProbeStructureVersion(string $root, string $password): int
{
return $this->operations->vaultDirectoryProbeStructureVersion($root, $password);
}
/** Opens or creates the default Vault without replacing existing state. */
public function vaultDirectoryOpenOrCreateDefault(string $password): Vault
{
return new Vault($this->operations, $this->operations->vaultDirectoryOpenOrCreateDefault($password));
}
/** Replaces the default Vault and all persistent data it contains. */
public function vaultDirectoryReplaceDefault(string $password): Vault
{
return new Vault($this->operations, $this->operations->vaultDirectoryReplaceDefault($password));
}
/** Changes the passphrase for an existing Vault at root. */
public function vaultDirectoryChangePassword(string $root, string $oldPassword, string $newPassword): bool
{
return $this->operations->vaultDirectoryChangePassword($root, $oldPassword, $newPassword);
}
/** Changes the passphrase for the default Vault. */
public function vaultDirectoryChangeDefaultPassword(string $oldPassword, string $newPassword): bool
{
return $this->operations->vaultDirectoryChangeDefaultPassword($oldPassword, $newPassword);
}
/** Replaces the Vault at root and all persistent data it contains. */
public function vaultDirectoryReplace(string $root, string $password): Vault
{
return new Vault($this->operations, $this->operations->vaultDirectoryReplace($root, $password));
}
/** Opens the Vault at root, creating it only when absent. */
public function vaultDirectoryOpenOrCreate(string $root, string $password): Vault
{
return new Vault($this->operations, $this->operations->vaultDirectoryOpenOrCreate($root, $password));
}
/** Writes a backup of the default Vault to path. */
public function vaultBackupDefault(string $path, bool $overwrite): \Revault\VaultBackupManifest
{
return $this->operations->vaultBackupDefault($path, $overwrite);
}
/** Restores the default Vault from a backup at path. */
public function vaultRestoreDefault(string $path, bool $overwrite): \Revault\VaultBackupManifest
{
return $this->operations->vaultRestoreDefault($path, $overwrite);
}
/** Opens an existing Vault metadata view that cannot load private keys. */
public function vaultReadOnlyOpen(string $root, string $password): ReadOnlyVault
{
return new ReadOnlyVault($this->operations, $this->operations->vaultReadOnlyOpen($root, $password));
}
/** Opens the default Vault metadata view without loading private keys. */
public function vaultReadOnlyOpenDefault(string $password): ReadOnlyVault
{
return new ReadOnlyVault($this->operations, $this->operations->vaultReadOnlyOpenDefault($password));
}
/** Returns the platform default Vault directory. */
public function vaultDefaultDirectory(): string
{
return $this->operations->vaultDefaultDirectory();
}
/** Returns the path of the default Vault file. */
public function vaultDefaultPath(): string
{
return $this->operations->vaultDefaultPath();
}
/** Returns the session agent log path. */
public function vaultAgentLogPath(): string
{
return $this->operations->vaultAgentLogPath();
}
/** Returns the configured session agent log destination. */
public function vaultAgentLogDestination(): string
{
return $this->operations->vaultAgentLogDestination();
}
}
/** Base type for disposable API values; applications use its concrete subclasses. */
abstract class OwnedHandle
{
/** Adopts an owned native handle; application code uses concrete subclasses. */
public function __construct(protected readonly BindingOperations $operations, protected CData $handle) {}
final public function nativeHandle(): CData { return $this->handle; }
/** Release native memory; concrete handles implement free(). */
public function close(): void { if (method_exists($this, 'free')) $this->free(); }
}
/**
* An open Lockbox containing files, variables, and forms.
*
* Create or open a Lockbox with exactly one password, content key, or contact.
* Mutations remain pending until commit(). Call close() in a finally block to
* release the content key held by this process. See the package README and
* bindings/e2e/php/conformance.php for complete examples.
*/
class Lockbox extends OwnedHandle
{
/** Host path for handles returned by the path factory; null for bytes-only handles. */
private ?string $backingPath = null;
/** Create an in-memory archive protected by exactly one credential. */
public static function createInMemory(?string $password = null, ?string $contentKey = null, ?OwnedHandle $contact = null, ?OwnedHandle $signingKey = null, ?array $options = null): self
{
if (count(array_filter([$password, $contentKey, $contact], static fn($value) => $value !== null)) !== 1) {
throw new \InvalidArgumentException('Supply exactly one of password, contentKey, or contact.');
}
$runtime = Revault::runtime();
$box = $password !== null ? ($signingKey === null ? $runtime->lockboxCreatePassword($password) : $runtime->lockboxCreatePasswordWithSigningKey($password, $signingKey))
: ($contact !== null ? ($signingKey === null ? $runtime->lockboxCreateContact($contact) : $runtime->lockboxCreateContactWithSigningKey($contact, $signingKey))
: ($options !== null ? $runtime->lockboxCreateWithOptions($contentKey, $options['cacheMode'], $options['cacheBytes'] ?? 0, $options['workload'], $options['worker'], $options['jobs'] ?? 0)
: $runtime->lockboxCreate($contentKey)));
if ($signingKey !== null && $password === null && $contact === null) $box->setOwnerSigningKey($signingKey);
return $box;
}
/** Open serialized archive bytes without consulting the Session Agent. */
public static function openBytes(string $archive, ?string $password = null, ?string $contentKey = null, ?OwnedHandle $contact = null, ?array $options = null): self
{
if (count(array_filter([$password, $contentKey, $contact], static fn($value) => $value !== null)) !== 1) {
throw new \InvalidArgumentException('Supply exactly one of password, contentKey, or contact.');
}
$runtime = Revault::runtime();
if ($password !== null) return $runtime->lockboxOpenPassword($archive, $password);
if ($contact !== null) return $runtime->lockboxOpenContact($archive, $contact);
return $options === null ? $runtime->lockboxOpen($archive, $contentKey) : $runtime->lockboxOpenWithOptions($archive, $contentKey, $options['cacheMode'], $options['cacheBytes'] ?? 0, $options['workload'], $options['worker'], $options['jobs'] ?? 0);
}
/** Create a host archive file and return its process-local handle. */
public static function create(string $path, ?string $password = null, ?string $contentKey = null, ?OwnedHandle $contact = null, ?OwnedHandle $signingKey = null, ?array $options = null, bool $overwrite = false): self
{
if (is_file($path) && !$overwrite) throw new \RuntimeException("Lockbox already exists: $path");
$box = self::createInMemory($password, $contentKey, $contact, $signingKey, $options);
file_put_contents($path, $box->toBytes());
$box->backingPath = $path;
return $box;
}
/** Open a host archive file without consulting the Session Agent. */
public static function open(string $path, ?string $password = null, ?string $contentKey = null, ?OwnedHandle $contact = null, ?array $options = null): self
{
$box = self::openBytes(file_get_contents($path), $password, $contentKey, $contact, $options);
$box->backingPath = $path;
return $box;
}
/** Stages a file at the Lockbox path; replace controls an existing entry. */
public function addFile(string $path, string $data, bool $replace): bool
{
return $this->operations->lockboxAddFile($this->handle, $path, $data, $replace);
}
/** Stages a file and its portable Unix permission bits. */
public function addFileWithPermissions(string $path, string $data, int $permissions, bool $replace): bool
{
return $this->operations->lockboxAddFileWithPermissions($this->handle, $path, $data, $permissions, $replace);
}
/** Reads the complete file stored at the Lockbox path. */
public function getFile(string $path): string
{
return $this->operations->lockboxGetFile($this->handle, $path);
}
/** Writes one Lockbox file to the host filesystem. */
public function extractFile(string $source, string $destination, bool $replace): bool
{
return $this->operations->lockboxExtractFile($this->handle, $source, $destination, $replace);
}
/** Extracts the Lockbox with explicit size, count, link, and permission limits. */
public function extractDirectory(string $destination, int $maxFileBytes, int $maxTotalBytes, int $maxFiles, bool $restoreSymlinks, bool $restorePermissions, bool $overwrite): bool
{
return $this->operations->lockboxExtractDirectory($this->handle, $destination, $maxFileBytes, $maxTotalBytes, $maxFiles, $restoreSymlinks, $restorePermissions, $overwrite);
}
/** Lists logical or physical content chunks for streaming diagnostics. */
public function streamContent(bool $physical): \Revault\StreamChunkList
{
return $this->operations->lockboxStreamContent($this->handle, $physical);
}
/** Returns cache statistics for this lockbox. */
public function cacheStats(): \Revault\CacheStats
{
return $this->operations->lockboxCacheStats($this->handle);
}
/** Returns import statistics for this lockbox. */
public function importStats(): \Revault\ImportStats
{
return $this->operations->lockboxImportStats($this->handle);
}
/** Updates import stats. */
public function resetImportStats(): bool
{
return $this->operations->lockboxResetImportStats($this->handle);
}
/** Returns page metadata for diagnostics without exposing plaintext secrets. */
public function pageInspection(): \Revault\PageInspectionList
{
return $this->operations->lockboxPageInspection($this->handle);
}
/** Scans the open archive and returns its structured recovery report. */
public function recoveryReport(): \Revault\RecoveryReport
{
return $this->operations->lockboxRecoveryReport($this->handle);
}
/** Renders the recovery report for a person, capped at maxEntries. */
public function recoveryReportRender(bool $verbose, int $maxEntries): string
{
return $this->operations->lockboxRecoveryReportRender($this->handle, $verbose, $maxEntries);
}
/** Returns the current serialized archive size in bytes. */
public function storageLen(): int
{
return $this->operations->lockboxStorageLen($this->handle);
}
/** Selects the predefined workload policy for later operations. */
public function setWorkloadProfile(string $profile): bool
{
return $this->operations->lockboxSetWorkloadProfile($this->handle, $profile);
}
/** Selects worker scheduling and the maximum job count. */
public function setWorkerPolicy(string $mode, int $jobs): bool
{
return $this->operations->lockboxSetWorkerPolicy($this->handle, $mode, $jobs);
}
/** Returns the cache, workload, and worker settings used by this Lockbox. */
public function runtimeOptions(): \Revault\RuntimeOptions
{
return $this->operations->lockboxRuntimeOptions($this->handle);
}
/** Authenticates and publishes the staged changes. */
public function commit(): bool
{
$committed = $this->operations->lockboxCommit($this->handle);
if ($this->backingPath !== null) file_put_contents($this->backingPath, $this->toBytes());
return $committed;
}
/** Stages a directory entry and optionally creates missing parents. */
public function createDir(string $path, bool $createParents): bool
{
return $this->operations->lockboxCreateDir($this->handle, $path, $createParents);
}
/** Stages removal of a file, link, or empty directory at path. */
public function delete(string $path): bool
{
return $this->operations->lockboxDelete($this->handle, $path);
}
/** Stages removal of a directory, optionally including its descendants. */
public function removeDir(string $path, bool $recursive): bool
{
return $this->operations->lockboxRemoveDir($this->handle, $path, $recursive);
}
/** Stages every missing parent directory for path. */
public function createParentDirs(string $path): bool
{
return $this->operations->lockboxCreateParentDirs($this->handle, $path);
}
/** Stages an atomic move from one Lockbox path to another. */
public function rename(string $from, string $to): bool
{
return $this->operations->lockboxRename($this->handle, $from, $to);
}
/** Lists entries below path, optionally including descendants. */
public function list(string $path, bool $recursive): \Revault\LockboxEntryList
{
return $this->operations->lockboxList($this->handle, $path, $recursive);
}
/** Lists entries using glob, type, recursion, and result limit filters. */
public function listWithOptions(string $path, string $glob, bool $recursive, bool $includeFiles, bool $includeSymlinks, bool $includeDirectories, int $limit): \Revault\LockboxEntryList
{
return $this->operations->lockboxListWithOptions($this->handle, $path, $glob, $recursive, $includeFiles, $includeSymlinks, $includeDirectories, $limit);
}
/** Returns metadata for the selected lockbox entry. */
public function stat(string $path): \Revault\OptionalLockboxEntry
{
return $this->operations->lockboxStat($this->handle, $path);
}
/** Stages a plain text variable; call commit() to publish the change. */
public function setVariable(string $name, string $value): bool
{
return $this->operations->lockboxSetVariable($this->handle, $name, $value);
}
/** Stores a secret variable from binary-safe PHP string bytes. */
public function setSecretVariable(string $name, string $value): bool
{
return $this->operations->lockboxSetSecretVariable($this->handle, $name, $value);
}
/** Returns a plain variable, or null when it is absent. */
public function getVariable(string $name): ?string
{
$value = $this->operations->lockboxGetVariable($this->handle, $name);
return $value->getPresent() ? $value->getValue() : null;
}
/** Returns the encrypted Lockbox description, or null when unset. Example: set it, commit, then print `$box->description()`. */
public function description(): ?string
{
return $this->getVariable('/.revault/description');
}
/** Stages encrypted description text; call commit() to publish it. Example: `$box->setDescription('Production credentials'); $box->commit();`. */
public function setDescription(string $description): bool
{
return $this->setVariable('/.revault/description', $description);
}
/** Stages removal of the encrypted description; call commit(). Example: `$box->clearDescription(); $box->commit();`. */
public function clearDescription(): bool
{
return $this->deleteVariable('/.revault/description');
}
/** Invokes the callback with temporary secret bytes, then wipes the native transfer. */
public function withSecretVariable(string $name, callable $callback): mixed
{
return $this->operations->lockboxWithSecretVariable($this->handle, $name, $callback);
}
/** Stages removal of a variable. */
public function deleteVariable(string $name): bool
{
return $this->operations->lockboxDeleteVariable($this->handle, $name);
}
/** Atomically renames variables using source and destination path pairs. */
public function moveVariables(array $moves): bool
{
return $this->operations->lockboxMoveVariables($this->handle, DomainCodec::encodePathMoves($moves));
}
/** Lists variable names and metadata without exposing secret values. */
public function listVariables(): \Revault\VariableList
{
return $this->operations->lockboxListVariables($this->handle);
}
/** Returns whether a variable is plain or secret. */
public function variableSensitivity(string $name): \Revault\OptionalString
{
return $this->operations->lockboxVariableSensitivity($this->handle, $name);
}
/** Stages a symbolic link with its stored target text. */
public function addSymlink(string $path, string $target, bool $replace): bool
{
return $this->operations->lockboxAddSymlink($this->handle, $path, $target, $replace);
}
/** Returns the target text stored for a symbolic link. */
public function getSymlinkTarget(string $path): string
{
return $this->operations->lockboxGetSymlinkTarget($this->handle, $path);
}
/** Returns the stable public identifier stored in the Lockbox header. */
public function id(): string
{
return $this->operations->lockboxId($this->handle);
}
/** Reports whether an entry exists at path. */
public function exists(string $path): bool
{
return $this->operations->lockboxExists($this->handle, $path);
}
/** Reports whether path names a directory entry. */
public function isDir(string $path): bool
{
return $this->operations->lockboxIsDir($this->handle, $path);
}
/** Returns the portable Unix permission bits stored for path. */
public function permissions(string $path): int
{
return $this->operations->lockboxPermissions($this->handle, $path);
}
/** Stages portable Unix permission bits for path. */
public function setPermissions(string $path, int $permissions): bool
{
return $this->operations->lockboxSetPermissions($this->handle, $path, $permissions);
}
/** Reads len bytes from a file starting at its logical offset. */
public function readRange(string $path, int $offset, int $len): string
{
return $this->operations->lockboxReadRange($this->handle, $path, $offset, $len);
}
/** Adds a password access slot and returns its slot identifier. */
public function addPassword(string $password): int
{
return $this->operations->lockboxAddPassword($this->handle, $password);
}
/** Grants a named contact access and returns the new slot identifier. */
public function addContact(OwnedHandle $contact, string $name): int
{
return $this->operations->lockboxAddContact($this->handle, $contact->nativeHandle(), $name);
}
/** Removes an access slot; at least one usable slot must remain. */
public function deleteKey(int $id): bool
{
return $this->operations->lockboxDeleteKey($this->handle, $id);
}
/** Lists public access slot metadata without returning credentials. */
public function listKeySlots(): \Revault\KeySlotList
{
return $this->operations->lockboxListKeySlots($this->handle);
}
/** Assigns a profile signing key to the Lockbox owner role. */
public function setOwnerSigningKey(OwnedHandle $key): bool
{
return $this->operations->lockboxSetOwnerSigningKey($this->handle, $key->nativeHandle());
}
/** Returns public signing and ownership metadata for the current revision. */
public function ownerInspection(): \Revault\OwnerInspection
{
return $this->operations->lockboxOwnerInspection($this->handle);
}
/** Defines a reusable, versioned form from the supplied field definitions. */
public function defineForm(string $alias, string $name, string $description, array $fields): \Revault\FormDefinition
{
return $this->operations->lockboxDefineForm($this->handle, $alias, $name, $description, DomainCodec::encodeFormFields($fields));
}
/** Lists the form definitions stored in this Lockbox. */
public function listFormDefinitions(): \Revault\FormDefinitionList
{
return $this->operations->lockboxListFormDefinitions($this->handle);
}
/** Resolves a form alias, type identifier, or revision. */
public function resolveForm(string $reference): \Revault\FormDefinition
{
return $this->operations->lockboxResolveForm($this->handle, $reference);
}
/** Lists every stored revision for a form type identifier. */
public function listFormRevisions(string $typeId): \Revault\FormDefinitionList
{
return $this->operations->lockboxListFormRevisions($this->handle, $typeId);
}
/** Stages a form record at path using the referenced definition. */
public function createFormRecord(string $path, string $typeReference, string $name): \Revault\FormRecord
{
return $this->operations->lockboxCreateFormRecord($this->handle, $path, $typeReference, $name);
}
/** Stages a plain field value in a form record. */
public function setFormField(string $path, string $field, string $value): bool
{
return $this->operations->lockboxSetFormField($this->handle, $path, $field, $value);
}
/** Stores a secret form field from binary-safe PHP string bytes. */
public function setSecretFormField(string $path, string $field, string $value): bool
{
return $this->operations->lockboxSetSecretFormField($this->handle, $path, $field, $value);
}
/** Lists form records without exposing secret field values. */
public function listFormRecords(): \Revault\FormRecordList
{
return $this->operations->lockboxListFormRecords($this->handle);
}
/** Returns a form record when path exists. */
public function getFormRecord(string $path): \Revault\OptionalFormRecord
{
return $this->operations->lockboxGetFormRecord($this->handle, $path);
}
/** Stages removal of a form record. */
public function deleteFormRecord(string $path): bool
{
return $this->operations->lockboxDeleteFormRecord($this->handle, $path);
}
/** Atomically renames form records using source and destination path pairs. */
public function moveFormRecords(array $moves): bool
{
return $this->operations->lockboxMoveFormRecords($this->handle, DomainCodec::encodePathMoves($moves));
}
/** Returns a plain form field when it exists. */
public function getFormField(string $path, string $field): \Revault\OptionalFormValue
{
return $this->operations->lockboxGetFormField($this->handle, $path, $field);
}
/** Invokes the callback with temporary field bytes, then wipes the native transfer. */
public function withSecretFormField(string $path, string $field, callable $callback): mixed
{
return $this->operations->lockboxWithSecretFormField($this->handle, $path, $field, $callback);
}
/** Serializes the current Lockbox, including committed changes. */
public function toBytes(): string
{
return $this->operations->lockboxToBytes($this->handle);
}
/** Releases the native resources held by this object. */
public function free(): void
{
$this->operations->lockboxFree($this->handle);
}
}
/** A profile's contact-encryption identity used to decrypt content keys addressed to it. */
class ContactKeyPair extends OwnedHandle
{
/** Returns the canonical public bytes paired with this identity. */
public function publicBytes(): string
{
return $this->operations->keyContactPublic($this->handle);
}
/** Returns the private signing-key record for secure binary backup. */
public function privateRecord(): string
{
return $this->operations->keyContactPrivate($this->handle);
}
/** Releases the native resources held by this object. */
public function free(): void
{
$this->operations->keyContactFree($this->handle);
}
/** Decrypts a wrapped content key for this contact. */
public function decrypt(OwnedHandle $wrapped): string
{
return $this->operations->keyContactDecrypt($this->handle, $wrapped->nativeHandle());
}
}
/** A recipient's shareable encryption identity used when granting lockbox access. */
class ContactPublicKey extends OwnedHandle
{
/** Releases this public contact key. */
public function publicFree(): void
{
$this->operations->keyContactPublicFree($this->handle);
}
/** Encrypts a content key for the selected contact. */
public function encrypt(string $contentKey): WrappedContactKey
{
return new WrappedContactKey($this->operations, $this->operations->keyContactEncrypt($this->handle, $contentKey));
}
}
/** A content key encrypted for one contact and recoverable only by its matching key pair. */
class WrappedContactKey extends OwnedHandle
{
/** Returns the ephemeral public key stored in this wrapped key. */
public function public(): string
{
return $this->operations->keyContactWrappedPublic($this->handle);
}
/** Returns the encrypted content key bytes. */
public function ciphertext(): string
{
return $this->operations->keyContactWrappedCiphertext($this->handle);
}
/** Returns the complete wrapped key record for storage or transport. */
public function encrypted(): string
{
return $this->operations->keyContactWrappedEncrypted($this->handle);
}
/** Releases the native resources held by this object. */
public function free(): void
{
$this->operations->keyContactWrappedFree($this->handle);
}
}
/** A Vault Profile signing identity used to authorize mutable Lockbox revisions. */
class ProfileSigningKeyPair extends OwnedHandle
{
/** Returns the canonical public bytes for this signing identity. */
public function public(): string
{
return $this->operations->keySigningPublic($this->handle);
}
/** Returns the private signing key record for secure backup. */
public function private(): string
{
return $this->operations->keySigningPrivate($this->handle);
}
/** Creates an independently owned public verification-key handle. */
public function publicKey(): ProfileSigningPublicKey
{
return new ProfileSigningPublicKey(
$this->operations,
$this->operations->keySigningPublicFromBytes($this->public()),
);
}
/** Releases the native resources held by this object. */
public function free(): void
{
$this->operations->keySigningFree($this->handle);
}
}
/** The public half of a Vault Profile signing identity. */
class ProfileSigningPublicKey extends OwnedHandle
{
/** Releases the native resources held by this object. */
public function free(): void
{
$this->operations->keySigningPublicFree($this->handle);
}
}
/** Password-protected storage for Profile keys, contacts, forms, backups, and known lockbox paths. */
class VaultStore extends OwnedHandle
{
/** Returns the canonical root directory of this Vault. */
public function root(): string
{
return $this->operations->vaultDirectoryRoot($this->handle);
}
/** Returns the persistent structure version of this Vault. */
public function structureVersion(): int
{
return $this->operations->vaultDirectoryStructureVersion($this->handle);
}
/** Lists private keys. */
public function listPrivateKeys(): \Revault\StringList
{
return $this->operations->vaultDirectoryListPrivateKeys($this->handle);
}