Algorithm.php 747 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Util\HttpSignatures;
  3. abstract class Algorithm
  4. {
  5. /**
  6. * @param string $name
  7. *
  8. * @return HmacAlgorithm
  9. *
  10. * @throws Exception
  11. */
  12. public static function create($name)
  13. {
  14. switch ($name) {
  15. case 'hmac-sha1':
  16. return new HmacAlgorithm('sha1');
  17. break;
  18. case 'hmac-sha256':
  19. return new HmacAlgorithm('sha256');
  20. break;
  21. case 'rsa-sha1':
  22. return new RsaAlgorithm('sha1');
  23. break;
  24. case 'rsa-sha256':
  25. return new RsaAlgorithm('sha256');
  26. break;
  27. default:
  28. throw new AlgorithmException("No algorithm named '$name'");
  29. break;
  30. }
  31. }
  32. }