|
5 | 5 | from pycose.keys import CoseKey, EC2Key |
6 | 6 | from pycose.messages import Sign1Message |
7 | 7 |
|
8 | | -from typing import Union |
| 8 | +from typing import Union, Any |
9 | 9 |
|
10 | 10 | from pymdoccbor.exceptions import ( |
11 | 11 | MsoX509ChainNotFound, |
@@ -75,15 +75,31 @@ def payload_as_dict(self): |
75 | 75 | ) |
76 | 76 |
|
77 | 77 | @property |
78 | | - def raw_public_keys(self) -> bytes: |
| 78 | + def raw_public_keys(self) -> list[Any]: |
79 | 79 | """ |
80 | 80 | it returns the public key extract from x509 certificates |
81 | 81 | looking to both phdr and uhdr |
82 | 82 | """ |
83 | | - _mixed_heads = self.object.phdr.items() | self.object.uhdr.items() |
| 83 | + # _mixed_heads = self.object.phdr.items() | self.object.uhdr.items() |
| 84 | + |
| 85 | + merged = self.object.phdr.copy() |
| 86 | + merged.update(self.object.uhdr) |
| 87 | + _mixed_heads = merged.items() |
84 | 88 | for h, v in _mixed_heads: |
85 | 89 | if h.identifier == 33: |
86 | | - return list(self.object.uhdr.values()) |
| 90 | + # return list(self.object.uhdr.values()) |
| 91 | + if isinstance(v, bytes): |
| 92 | + return [v] |
| 93 | + elif isinstance(v, list): |
| 94 | + return v |
| 95 | + elif isinstance(v, dict): |
| 96 | + return [v] |
| 97 | + else: |
| 98 | + logger.warning( |
| 99 | + f"Unexpected type for public key: {type(v)}. " |
| 100 | + "Expected bytes, list or dict." |
| 101 | + ) |
| 102 | + continue |
87 | 103 |
|
88 | 104 | raise MsoX509ChainNotFound( |
89 | 105 | "I can't find any valid X509certs, identified by label number 33, " |
|
0 commit comments