@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * Trivial example of a file storage format for at-rest encryption.
5 *
6 * This format applies ROT13 encoding to file data as it is stored and
7 * reverses it on the way out. This encoding is trivially reversible. This
8 * format is for testing, developing, and understanding encoding formats and
9 * is not intended for production use.
10 */
11final class PhabricatorFileROT13StorageFormat
12 extends PhabricatorFileStorageFormat {
13
14 const FORMATKEY = 'rot13';
15
16 public function getStorageFormatName() {
17 return pht('Encoded (ROT13)');
18 }
19
20 public function newReadIterator($raw_iterator) {
21 $file = $this->getFile();
22 $iterations = $file->getStorageProperty('iterations', 1);
23
24 $value = $file->loadDataFromIterator($raw_iterator);
25 for ($ii = 0; $ii < $iterations; $ii++) {
26 $value = str_rot13($value);
27 }
28
29 return array($value);
30 }
31
32 public function newWriteIterator($raw_iterator) {
33 return $this->newReadIterator($raw_iterator);
34 }
35
36 public function newStorageProperties() {
37 // For extreme security, repeatedly encode the data using a random (odd)
38 // number of iterations.
39 return array(
40 'iterations' => (mt_rand(1, 3) * 2) - 1,
41 );
42 }
43
44}