|
| 1 | +# |
| 2 | +# |
| 3 | +--- a/src/Metadata/MetadataBase.php |
| 4 | ++++ b/src/Metadata/MetadataBase.php (date 1688224003871) |
| 5 | +@@ -51,19 +51,6 @@ |
| 6 | + { |
| 7 | + } |
| 8 | + |
| 9 | +- /** |
| 10 | +- * Returns a normalized array version of this object for JSON encoding. |
| 11 | +- * |
| 12 | +- * @see ::toCanonicalJson() |
| 13 | +- * |
| 14 | +- * @return array |
| 15 | +- * A normalized array representation of this object. |
| 16 | +- */ |
| 17 | +- protected function toNormalizedArray(): array |
| 18 | +- { |
| 19 | +- return $this->getSigned(); |
| 20 | +- } |
| 21 | +- |
| 22 | + /** |
| 23 | + * Returns a canonical JSON representation of this metadata object. |
| 24 | + * |
| 25 | +@@ -72,7 +59,7 @@ |
| 26 | + */ |
| 27 | + public function toCanonicalJson(): string |
| 28 | + { |
| 29 | +- return static::encodeJson($this->toNormalizedArray()); |
| 30 | ++ return static::encodeJson($this->getSigned()); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + |
| 35 | + |
| 36 | +--- a/src/Metadata/TargetsMetadata.php |
| 37 | ++++ b/src/Metadata/TargetsMetadata.php (date 1688224236309) |
| 38 | +@@ -67,26 +67,32 @@ |
| 39 | + |
| 40 | + /** |
| 41 | + * {@inheritDoc} |
| 42 | ++ * Returns a canonical JSON representation of this metadata object. |
| 43 | ++ * |
| 44 | ++ * @return string |
| 45 | ++ * The canonical JSON representation of this object. |
| 46 | + */ |
| 47 | +- protected function toNormalizedArray(): array |
| 48 | ++ public function toCanonicalJson(): string |
| 49 | + { |
| 50 | +- $normalized = parent::toNormalizedArray(); |
| 51 | ++ $metadata = $this->getSigned(); |
| 52 | + |
| 53 | +- foreach ($normalized['targets'] as $path => $target) { |
| 54 | ++ // Apply sorting |
| 55 | ++ self::sortKeys($metadata); |
| 56 | ++ |
| 57 | ++ foreach ($metadata['targets'] as $path => $target) { |
| 58 | + // Custom target info should always encode to an object, even if |
| 59 | + // it's empty. |
| 60 | + if (array_key_exists('custom', $target)) { |
| 61 | +- $normalized['targets'][$path]['custom'] = (object) $target['custom']; |
| 62 | ++ $metadata['targets'][$path]['custom'] = (object) $target['custom']; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + // Ensure that these will encode as objects even if they're empty. |
| 67 | +- $normalized['targets'] = (object) $normalized['targets']; |
| 68 | +- if (array_key_exists('delegations', $normalized)) { |
| 69 | +- $normalized['delegations']['keys'] = (object) $normalized['delegations']['keys']; |
| 70 | ++ $metadata['targets'] = (object) $metadata['targets']; |
| 71 | ++ if (array_key_exists('delegations', $metadata)) { |
| 72 | ++ $metadata['delegations']['keys'] = (object)$metadata['delegations']['keys']; |
| 73 | + } |
| 74 | +- |
| 75 | +- return $normalized; |
| 76 | ++ return static::encodeJson($metadata); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + |
| 81 | + |
| 82 | +--- a/src/CanonicalJsonTrait.php |
| 83 | ++++ b/src/CanonicalJsonTrait.php (date 1688223879893) |
| 84 | +@@ -53,7 +53,7 @@ |
| 85 | + * @throws \RuntimeException |
| 86 | + * Thrown if sorting the array fails. |
| 87 | + */ |
| 88 | +- private static function sortKeys(array &$data): void |
| 89 | ++ protected static function sortKeys(array &$data): void |
| 90 | + { |
| 91 | + // If $data is numerically indexed, the keys are already sorted, by |
| 92 | + // definition. |
0 commit comments