|
18 | 18 | import abc |
19 | 19 | import tempfile |
20 | 20 | from datetime import datetime, timedelta |
21 | | -from typing import Any, ClassVar, Dict, List, Mapping, Optional, Tuple, Type |
| 21 | +from typing import ( |
| 22 | + Any, |
| 23 | + ClassVar, |
| 24 | + Dict, |
| 25 | + List, |
| 26 | + Mapping, |
| 27 | + Optional, |
| 28 | + OrderedDict, |
| 29 | + Tuple, |
| 30 | + Type, |
| 31 | +) |
22 | 32 |
|
23 | 33 | from securesystemslib.keys import verify_signature |
24 | 34 | from securesystemslib.signer import Signature, Signer |
@@ -48,11 +58,13 @@ class Metadata: |
48 | 58 | signed: A subclass of Signed, which has the actual metadata payload, |
49 | 59 | i.e. one of Targets, Snapshot, Timestamp or Root. |
50 | 60 |
|
51 | | - signatures: A dict of keyids to Securesystemslib Signature objects, |
52 | | - each signing the canonical serialized representation of 'signed'. |
| 61 | + signatures: An ordered dictionary of keyids to Signature objects, each |
| 62 | + signing the canonical serialized representation of 'signed'. |
53 | 63 | """ |
54 | 64 |
|
55 | | - def __init__(self, signed: "Signed", signatures: Dict[str, Signature]): |
| 65 | + def __init__( |
| 66 | + self, signed: "Signed", signatures: OrderedDict[str, Signature] |
| 67 | + ): |
56 | 68 | self.signed = signed |
57 | 69 | self.signatures = signatures |
58 | 70 |
|
@@ -89,7 +101,7 @@ def from_dict(cls, metadata: Dict[str, Any]) -> "Metadata": |
89 | 101 | raise ValueError(f'unrecognized metadata type "{_type}"') |
90 | 102 |
|
91 | 103 | # Make sure signatures are unique |
92 | | - signatures: Dict[str, Signature] = {} |
| 104 | + signatures = OrderedDict[str, Signature]() |
93 | 105 | for sig_dict in metadata.pop("signatures"): |
94 | 106 | sig = Signature.from_dict(sig_dict) |
95 | 107 | if sig.keyid in signatures: |
@@ -249,7 +261,9 @@ def sign( |
249 | 261 | if append: |
250 | 262 | self.signatures[signature.keyid] = signature |
251 | 263 | else: |
252 | | - self.signatures = {signature.keyid: signature} |
| 264 | + self.signatures = OrderedDict[str, Signature]( |
| 265 | + {signature.keyid: signature} |
| 266 | + ) |
253 | 267 |
|
254 | 268 | return signature |
255 | 269 |
|
|
0 commit comments