You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
2.5 KiB

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Security\Signature\Model;
  8. use JsonSerializable;
  9. use NCU\Security\Signature\ISignatureManager;
  10. use NCU\Security\Signature\Model\IOutgoingSignedRequest;
  11. /**
  12. * extends ISignedRequest to add info requested at the generation of the signature
  13. *
  14. * @see ISignatureManager for details on signature
  15. * @since 31.0.0
  16. */
  17. class OutgoingSignedRequest extends SignedRequest implements
  18. IOutgoingSignedRequest,
  19. JsonSerializable {
  20. private string $host = '';
  21. private array $headers = [];
  22. private string $clearSignature = '';
  23. private string $algorithm;
  24. /**
  25. * @inheritDoc
  26. *
  27. * @param string $host
  28. * @return IOutgoingSignedRequest
  29. * @since 31.0.0
  30. */
  31. public function setHost(string $host): IOutgoingSignedRequest {
  32. $this->host = $host;
  33. return $this;
  34. }
  35. /**
  36. * @inheritDoc
  37. *
  38. * @return string
  39. * @since 31.0.0
  40. */
  41. public function getHost(): string {
  42. return $this->host;
  43. }
  44. /**
  45. * @inheritDoc
  46. *
  47. * @param string $key
  48. * @param string|int|float|bool|array $value
  49. *
  50. * @return IOutgoingSignedRequest
  51. * @since 31.0.0
  52. */
  53. public function addHeader(string $key, string|int|float|bool|array $value): IOutgoingSignedRequest {
  54. $this->headers[$key] = $value;
  55. return $this;
  56. }
  57. /**
  58. * @inheritDoc
  59. *
  60. * @return array
  61. * @since 31.0.0
  62. */
  63. public function getHeaders(): array {
  64. return $this->headers;
  65. }
  66. /**
  67. * @inheritDoc
  68. *
  69. * @param string $estimated
  70. *
  71. * @return IOutgoingSignedRequest
  72. * @since 31.0.0
  73. */
  74. public function setClearSignature(string $estimated): IOutgoingSignedRequest {
  75. $this->clearSignature = $estimated;
  76. return $this;
  77. }
  78. /**
  79. * @inheritDoc
  80. *
  81. * @return string
  82. * @since 31.0.0
  83. */
  84. public function getClearSignature(): string {
  85. return $this->clearSignature;
  86. }
  87. /**
  88. * @inheritDoc
  89. *
  90. * @param string $algorithm
  91. *
  92. * @return IOutgoingSignedRequest
  93. * @since 31.0.0
  94. */
  95. public function setAlgorithm(string $algorithm): IOutgoingSignedRequest {
  96. $this->algorithm = $algorithm;
  97. return $this;
  98. }
  99. /**
  100. * @inheritDoc
  101. *
  102. * @return string
  103. * @since 31.0.0
  104. */
  105. public function getAlgorithm(): string {
  106. return $this->algorithm;
  107. }
  108. public function jsonSerialize(): array {
  109. return array_merge(
  110. parent::jsonSerialize(),
  111. [
  112. 'headers' => $this->headers,
  113. 'host' => $this->getHost(),
  114. 'clearSignature' => $this->getClearSignature(),
  115. ]
  116. );
  117. }
  118. }