4 * Trivial example of a file storage format for at-rest encryption.
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.
11 final class PhabricatorFileROT13StorageFormat
12 extends PhabricatorFileStorageFormat
{
14 const FORMATKEY
= 'rot13';
16 public function getStorageFormatName() {
17 return pht('Encoded (ROT13)');
20 public function newReadIterator($raw_iterator) {
21 $file = $this->getFile();
22 $iterations = $file->getStorageProperty('iterations', 1);
24 $value = $file->loadDataFromIterator($raw_iterator);
25 for ($ii = 0; $ii < $iterations; $ii++
) {
26 $value = str_rot13($value);
32 public function newWriteIterator($raw_iterator) {
33 return $this->newReadIterator($raw_iterator);
36 public function newStorageProperties() {
37 // For extreme security, repeatedly encode the data using a random (odd)
38 // number of iterations.
40 'iterations' => (mt_rand(1, 3) * 2) - 1,