KeyValidator.php 764 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Protocol validator
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. declare(strict_types=1);
  9. namespace Magento\Framework\Encryption;
  10. use Magento\Framework\Config\ConfigOptionsListConstants;
  11. /**
  12. * Encryption Key Validator
  13. */
  14. class KeyValidator
  15. {
  16. /**
  17. * Validate encryption key
  18. *
  19. * Validate that encryption key is exactly 32 characters long and has
  20. * no trailing spaces, no invisible characters (tabs, new lines, etc.)
  21. *
  22. * @param string $value
  23. * @return bool
  24. */
  25. public function isValid($value) : bool
  26. {
  27. return strlen($value) === ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE
  28. && preg_match('/^\S+$/', $value);
  29. }
  30. }