From 8eb54ab96153dd9b8f15ffe30b7560d80d59254e Mon Sep 17 00:00:00 2001 From: NinjaCheetah <58050615+NinjaCheetah@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:13:24 -0500 Subject: [PATCH] Fully documented remaining files --- src/libWiiPy/commonkeys.py | 14 +++++- src/libWiiPy/crypto.py | 18 ++++++- src/libWiiPy/ticket.py | 98 +++++++++++++++++++++++++++++++++----- src/libWiiPy/tmd.py | 5 ++ 4 files changed, 120 insertions(+), 15 deletions(-) diff --git a/src/libWiiPy/commonkeys.py b/src/libWiiPy/commonkeys.py index c0a6048..b1fd7d2 100644 --- a/src/libWiiPy/commonkeys.py +++ b/src/libWiiPy/commonkeys.py @@ -9,9 +9,19 @@ vwii_key = '30bfc76e7c19afbb23163330ced7c28d' def get_common_key(common_key_index): - """ - Returns the specified Wii Common Key based on the index provided. + """Gets the specified Wii Common Key based on the index provided. + Possible values for common_key_index: 0: Common Key, 1: Korean Key, 2: vWii Key + + Parameters + ---------- + common_key_index : int + The index of the common key to be returned. + + Returns + ------- + bytes + The specified common key, in binary format. """ match common_key_index: case 0: diff --git a/src/libWiiPy/crypto.py b/src/libWiiPy/crypto.py index d8a7451..44a4a8f 100644 --- a/src/libWiiPy/crypto.py +++ b/src/libWiiPy/crypto.py @@ -8,9 +8,23 @@ from Crypto.Cipher import AES def decrypt_title_key(title_key_enc, common_key_index, title_id): - """ - Returns the decrypted version of the encrypted Title Key provided. + """Gets the decrypted version of the encrypted Title Key provided. + Requires the index of the common key to use, and the Title ID of the title that the Title Key is for. + + Parameters + ---------- + title_key_enc : bytes + The encrypted Title Key. + common_key_index : int + The index of the common key to be returned. + title_id : bytes + The title ID of the tite that the key is for. + + Returns + ------- + bytes + The decrypted Title Key. """ # Load the correct common key for the title. common_key = get_common_key(common_key_index) diff --git a/src/libWiiPy/ticket.py b/src/libWiiPy/ticket.py index cf31c8f..637352f 100644 --- a/src/libWiiPy/ticket.py +++ b/src/libWiiPy/ticket.py @@ -11,7 +11,15 @@ from typing import List @dataclass class TitleLimit: - """Creates a TitleLimit object that contains the type of restriction and the limit.""" + """Creates a TitleLimit object that contains the type of restriction and the limit. + + Attributes: + ---------- + limit_type : int + The type of play limit applied. + maximum_usage : int + The maximum value for the type of play limit applied. + """ # The type of play limit applied. The following types exist: # 0 = None, 1 = Time Limit, 3 = None, 4 = Launch Count limit_type: int @@ -105,40 +113,102 @@ class Ticket: self.title_limits_list.append(TitleLimit(limit_type, limit_value)) def get_signature(self): - """Returns the signature of the ticket.""" + """Gets the signature of the ticket. + + Returns + ------- + bytes + The signature. + """ return self.signature def get_ticket_version(self): - """Returns the version of the ticket.""" + """Gets the version of the ticket. + + Returns + ------- + int + The version. + """ return self.ticket_version def get_title_key_enc(self): - """Returns the title key contained in the ticket, in encrypted form.""" + """Gets the Title Key contained in the ticket, in encrypted form. + + Returns + ------- + bytes + The encrypted Title Key. + """ return self.title_key_enc def get_ticket_id(self): - """Returns the ID of the ticket.""" + """Gets the ID of the ticket. + + Returns + ------- + bytes + The ID of the ticket. + """ return self.ticket_id def get_console_id(self): - """Returns the ID of the console this ticket is designed for, if the ticket is console-specific.""" + """Gets the ID of the console this ticket is designed for, if the ticket is console-specific. + + Returns + ------- + bytes + The ID of the console. + """ return self.console_id def get_title_id(self): - """Returns the Title ID of the ticket's associated title.""" + """Gets the Title ID of the ticket's associated title. + + Returns + ------- + str + The Title ID of the title. + """ title_id_str = str(self.title_id.decode()) return title_id_str def get_title_version(self): - """Returns the version of the ticket's associated title that this ticket is designed for.""" + """Gets the version of the ticket's associated title that this ticket is designed for. + + Returns + ------- + int + The version of the title. + """ return self.title_version def get_common_key_index(self): - """Returns the index of the common key used to encrypt the Title Key contained in the ticket.""" + """Gets the index of the common key used to encrypt the Title Key contained in the ticket. + + Returns + ------- + int + The index of the common key required. + + See Also + -------- + commonkeys.get_common_key + """ return self.common_key_index def get_common_key_type(self): - """Returns the name of the common key used to encrypt the Title Key contained in the ticket.""" + """Gets the name of the common key used to encrypt the Title Key contained in the ticket. + + Returns + ------- + str + The name of the common key required. + + See Also + -------- + commonkeys.get_common_key + """ match self.common_key_index: case 0: return "Common" @@ -148,7 +218,13 @@ class Ticket: return "vWii" def get_title_key(self): - """Returns the decrypted title key contained in the ticket.""" + """Gets the decrypted title key contained in the ticket. + + Returns + ------- + bytes + The decrypted title key. + """ title_key = decrypt_title_key(self.title_key_enc, self.common_key_index, self.title_id) return title_key diff --git a/src/libWiiPy/tmd.py b/src/libWiiPy/tmd.py index 4e577bb..d9e62df 100644 --- a/src/libWiiPy/tmd.py +++ b/src/libWiiPy/tmd.py @@ -290,6 +290,11 @@ class TMD: def get_content_record(self, record): """Gets the content record at the specified index. + Parameters + ---------- + record : int + The content record to be retrieved. + Returns ------- ContentRecord