EncryptionWrapper.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Encryption;
  24. use OC\Memcache\ArrayCache;
  25. use OC\Files\Filesystem;
  26. use OC\Files\Storage\Wrapper\Encryption;
  27. use OCP\Files\Mount\IMountPoint;
  28. use OC\Files\View;
  29. use OCP\Files\Storage;
  30. use OCP\ILogger;
  31. /**
  32. * Class EncryptionWrapper
  33. *
  34. * applies the encryption storage wrapper
  35. *
  36. * @package OC\Encryption
  37. */
  38. class EncryptionWrapper {
  39. /** @var ArrayCache */
  40. private $arrayCache;
  41. /** @var Manager */
  42. private $manager;
  43. /** @var ILogger */
  44. private $logger;
  45. /**
  46. * EncryptionWrapper constructor.
  47. *
  48. * @param ArrayCache $arrayCache
  49. * @param Manager $manager
  50. * @param ILogger $logger
  51. */
  52. public function __construct(ArrayCache $arrayCache,
  53. Manager $manager,
  54. ILogger $logger
  55. ) {
  56. $this->arrayCache = $arrayCache;
  57. $this->manager = $manager;
  58. $this->logger = $logger;
  59. }
  60. /**
  61. * Wraps the given storage when it is not a shared storage
  62. *
  63. * @param string $mountPoint
  64. * @param Storage $storage
  65. * @param IMountPoint $mount
  66. * @return Encryption|Storage
  67. */
  68. public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) {
  69. $parameters = [
  70. 'storage' => $storage,
  71. 'mountPoint' => $mountPoint,
  72. 'mount' => $mount
  73. ];
  74. if (!$storage->instanceOfStorage(Storage\IDisableEncryptionStorage::class)) {
  75. $user = \OC::$server->getUserSession()->getUser();
  76. $mountManager = Filesystem::getMountManager();
  77. $uid = $user ? $user->getUID() : null;
  78. $fileHelper = \OC::$server->getEncryptionFilesHelper();
  79. $keyStorage = \OC::$server->getEncryptionKeyStorage();
  80. $util = new Util(
  81. new View(),
  82. \OC::$server->getUserManager(),
  83. \OC::$server->getGroupManager(),
  84. \OC::$server->getConfig()
  85. );
  86. $update = new Update(
  87. new View(),
  88. $util,
  89. Filesystem::getMountManager(),
  90. $this->manager,
  91. $fileHelper,
  92. $uid
  93. );
  94. return new Encryption(
  95. $parameters,
  96. $this->manager,
  97. $util,
  98. $this->logger,
  99. $fileHelper,
  100. $uid,
  101. $keyStorage,
  102. $update,
  103. $mountManager,
  104. $this->arrayCache
  105. );
  106. } else {
  107. return $storage;
  108. }
  109. }
  110. }