mirror of
https://github.com/NinjaCheetah/rustii.git
synced 2026-03-17 06:47:49 -04:00
Ported wad convert command from WiiPy
This commit is contained in:
@@ -14,6 +14,7 @@ use crate::title::crypto::decrypt_title_key;
|
||||
pub enum TicketError {
|
||||
UnsupportedVersion,
|
||||
CannotFakesign,
|
||||
IssuerTooLong,
|
||||
IOError(std::io::Error),
|
||||
}
|
||||
|
||||
@@ -22,6 +23,7 @@ impl fmt::Display for TicketError {
|
||||
let description = match *self {
|
||||
TicketError::UnsupportedVersion => "The provided Ticket is not a supported version (only v0 is supported).",
|
||||
TicketError::CannotFakesign => "The Ticket data could not be fakesigned.",
|
||||
TicketError::IssuerTooLong => "Signature issuer length must not exceed 64 characers.",
|
||||
TicketError::IOError(_) => "The provided Ticket data was invalid.",
|
||||
};
|
||||
f.write_str(description)
|
||||
@@ -232,4 +234,15 @@ impl Ticket {
|
||||
pub fn signature_issuer(&self) -> String {
|
||||
String::from_utf8_lossy(&self.signature_issuer).trim_end_matches('\0').to_owned()
|
||||
}
|
||||
|
||||
/// Sets a new name for the certificate used to sign a Ticket.
|
||||
pub fn set_signature_issuer(&mut self, signature_issuer: String) -> Result<(), TicketError> {
|
||||
if signature_issuer.len() > 64 {
|
||||
return Err(TicketError::IssuerTooLong);
|
||||
}
|
||||
let mut issuer = signature_issuer.into_bytes();
|
||||
issuer.resize(64, 0);
|
||||
self.signature_issuer = issuer.try_into().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use sha1::{Sha1, Digest};
|
||||
#[derive(Debug)]
|
||||
pub enum TMDError {
|
||||
CannotFakesign,
|
||||
IssuerTooLong,
|
||||
InvalidContentType(u16),
|
||||
IOError(std::io::Error),
|
||||
}
|
||||
@@ -21,6 +22,7 @@ impl fmt::Display for TMDError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let description = match *self {
|
||||
TMDError::CannotFakesign => "The TMD data could not be fakesigned.",
|
||||
TMDError::IssuerTooLong => "Signature issuer length must not exceed 64 characters.",
|
||||
TMDError::InvalidContentType(_) => "The TMD contains content with an invalid type.",
|
||||
TMDError::IOError(_) => "The provided TMD data was invalid.",
|
||||
};
|
||||
@@ -350,4 +352,20 @@ impl TMD {
|
||||
pub fn signature_issuer(&self) -> String {
|
||||
String::from_utf8_lossy(&self.signature_issuer).trim_end_matches('\0').to_owned()
|
||||
}
|
||||
|
||||
/// Sets a new name for the certificate used to sign a TMD.
|
||||
pub fn set_signature_issuer(&mut self, signature_issuer: String) -> Result<(), TMDError> {
|
||||
if signature_issuer.len() > 64 {
|
||||
return Err(TMDError::IssuerTooLong);
|
||||
}
|
||||
let mut issuer = signature_issuer.into_bytes();
|
||||
issuer.resize(64, 0);
|
||||
self.signature_issuer = issuer.try_into().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets whether this TMD describes a vWii title or not.
|
||||
pub fn is_vwii(&self) -> bool {
|
||||
self.is_vwii == 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user