forked from PSPReverse/PSPTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
64 lines (47 loc) · 2.3 KB
/
errors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# PSPTool - Display, extract and manipulate PSP firmware inside UEFI images
# Copyright (C) 2021 Christian Werling, Robert Buhren, Hans Niklas Jacob
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from .crypto import PublicKey
class NoCertifyingKey(Exception):
def __init__(self, signed_entity):
self.signed_entity = signed_entity
def __str__(self):
key_id = self.signed_entity.certifying_key
return f'There is no key with id {key_id.as_string()}, so {self.signed_entity} could not be verified!'
class SignatureInvalid(Exception):
def __init__(self, signed_entity, pubkey: PublicKey):
self.signed_entity = signed_entity
self.pubkey = pubkey
def __str__(self):
return f'Signature for {self.signed_entity} is not signed by {self.pubkey}!'
class SignatureInconsistent(SignatureInvalid):
def __str__(self):
return f'Signature for {self.signed_entity} was verified successfully at least once, but could not be ' \
f'verified by {self.pubkey}!'
class NonUniqueSignedEntity(Exception):
def __init__(self, existing, new):
self.existing = existing
self.new = new
def __str__(self):
start = self.existing.body.get_address()
end = start + self.existing.body.buffer_size
return f'There was anlready a SignedEntity at {hex(start)}:{hex(end)} (existing={self.existing}, new={self.new})!'
class NonUniquePublicKeyEntity(Exception):
def __init__(self, existing, new):
self.existing = existing
self.new = new
def __str__(self):
start = self.existing.key_id.get_address()
return f'There was anlready a PublicKeyEntity with key_id at {hex(start)} (existing={self.existing}, new={self.new})!'