2022-10-21 08:29:54 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2022 SatoshiLabs and contributors
|
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
2022-09-06 09:18:05 +00:00
|
|
|
import typing as t
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
from typing_extensions import Protocol
|
|
|
|
|
|
|
|
|
|
|
|
class FirmwareIntegrityError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class InvalidSignatureError(FirmwareIntegrityError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Unsigned(FirmwareIntegrityError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class DigestCalculator(Protocol):
|
2024-02-28 14:11:47 +00:00
|
|
|
def update(self, __data: bytes) -> None: ...
|
2022-09-06 09:18:05 +00:00
|
|
|
|
2024-02-28 14:11:47 +00:00
|
|
|
def digest(self) -> bytes: ...
|
2022-09-06 09:18:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
Hasher = t.Callable[[bytes], DigestCalculator]
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class FirmwareHashParameters:
|
|
|
|
hash_function: Hasher
|
|
|
|
chunk_size: int
|
|
|
|
padding_byte: t.Optional[bytes]
|