session.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Sam Tuke
  6. * @copyright 2012 Sam Tuke samtuke@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OCA\Encryption;
  23. /**
  24. * Class for handling encryption related session data
  25. */
  26. class Session {
  27. /**
  28. * @brief Sets user private key to session
  29. * @return bool
  30. *
  31. */
  32. public function setPrivateKey( $privateKey ) {
  33. $_SESSION['privateKey'] = $privateKey;
  34. return true;
  35. }
  36. /**
  37. * @brief Gets user private key from session
  38. * @returns string $privateKey The user's plaintext private key
  39. *
  40. */
  41. public function getPrivateKey() {
  42. if (
  43. isset( $_SESSION['privateKey'] )
  44. && !empty( $_SESSION['privateKey'] )
  45. ) {
  46. return $_SESSION['privateKey'];
  47. } else {
  48. return false;
  49. }
  50. }
  51. /**
  52. * @brief Sets user legacy key to session
  53. * @return bool
  54. *
  55. */
  56. public function setLegacyKey( $legacyKey ) {
  57. if ( $_SESSION['legacyKey'] = $legacyKey ) {
  58. return true;
  59. }
  60. }
  61. /**
  62. * @brief Gets user legacy key from session
  63. * @returns string $legacyKey The user's plaintext legacy key
  64. *
  65. */
  66. public function getLegacyKey() {
  67. if (
  68. isset( $_SESSION['legacyKey'] )
  69. && !empty( $_SESSION['legacyKey'] )
  70. ) {
  71. return $_SESSION['legacyKey'];
  72. } else {
  73. return false;
  74. }
  75. }
  76. }