1
0

EncryptionWrapper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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('OCA\Files_Sharing\SharedStorage')
  75. && !$storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')
  76. && !$storage->instanceOfStorage('OC\Files\Storage\OwnCloud')) {
  77. $user = \OC::$server->getUserSession()->getUser();
  78. $mountManager = Filesystem::getMountManager();
  79. $uid = $user ? $user->getUID() : null;
  80. $fileHelper = \OC::$server->getEncryptionFilesHelper();
  81. $keyStorage = \OC::$server->getEncryptionKeyStorage();
  82. $util = new Util(
  83. new View(),
  84. \OC::$server->getUserManager(),
  85. \OC::$server->getGroupManager(),
  86. \OC::$server->getConfig()
  87. );
  88. $update = new Update(
  89. new View(),
  90. $util,
  91. Filesystem::getMountManager(),
  92. $this->manager,
  93. $fileHelper,
  94. $uid
  95. );
  96. return new Encryption(
  97. $parameters,
  98. $this->manager,
  99. $util,
  100. $this->logger,
  101. $fileHelper,
  102. $uid,
  103. $keyStorage,
  104. $update,
  105. $mountManager,
  106. $this->arrayCache
  107. );
  108. } else {
  109. return $storage;
  110. }
  111. }
  112. }