mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-07 20:19:51 +00:00
fix: address clippy warnings
This commit is contained in:
@@ -48,7 +48,7 @@ impl ArgsKGM {
|
||||
let mut file_input = File::open(&self.input)?;
|
||||
let mut header = [0u8; 0x40];
|
||||
file_input.read_exact(&mut header)?;
|
||||
let kgm_header = Header::from_buffer(&mut header)?;
|
||||
let kgm_header = Header::from_buffer(header)?;
|
||||
let decipher = Decipher::new(&kgm_header)?;
|
||||
file_input.seek(SeekFrom::Start(kgm_header.offset_to_data as u64))?;
|
||||
|
||||
|
||||
@@ -13,16 +13,16 @@ pub mod xmly;
|
||||
#[derive(Subcommand)]
|
||||
pub enum Commands {
|
||||
#[command(name = "ncm")]
|
||||
NCM(ncm::ArgsNCM),
|
||||
Ncm(ncm::ArgsNCM),
|
||||
|
||||
#[command(name = "kgm")]
|
||||
KGM(kgm::ArgsKGM),
|
||||
Kgm(kgm::ArgsKGM),
|
||||
|
||||
#[command(name = "mg3d")]
|
||||
Migu3D(mg3d::ArgsMigu3D),
|
||||
|
||||
#[command(name = "joox")]
|
||||
JOOX(joox::ArgsJoox),
|
||||
Joox(joox::ArgsJoox),
|
||||
|
||||
#[command(name = "qmc1")]
|
||||
QMCv1(qmc1::ArgsQMCv1),
|
||||
@@ -30,11 +30,11 @@ pub enum Commands {
|
||||
QMCv2(qmc2::ArgsQMCv2),
|
||||
|
||||
#[command(name = "qtfm")]
|
||||
QTFM(qtfm::ArgsQingTingFM),
|
||||
QtFM(qtfm::ArgsQingTingFM),
|
||||
|
||||
#[command(name = "xiami")]
|
||||
Xiami(xiami::ArgsXiami),
|
||||
|
||||
#[command(name = "xmly")]
|
||||
XMLY(xmly::ArgsXimalaya),
|
||||
Xmly(xmly::ArgsXimalaya),
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ impl ArgsNCM {
|
||||
fn write_cover(&self, cli: &Cli, ncm: &NCMFile) -> anyhow::Result<()> {
|
||||
if let Some(cover_path) = &self.cover {
|
||||
if let Some(cover) = &ncm.image1 {
|
||||
File::create(cover_path)?.write_all(&cover)?;
|
||||
File::create(cover_path)?.write_all(cover)?;
|
||||
if cli.verbose {
|
||||
let cover_path = cover_path.display();
|
||||
let len = cover.len();
|
||||
|
||||
@@ -48,8 +48,8 @@ impl ArgsQingTingFM {
|
||||
let iv = make_decipher_iv(&file_name)?;
|
||||
if cli.verbose {
|
||||
eprintln!(" file_name: {}", file_name);
|
||||
eprintln!("device_key: {}", hex::encode(&device_key));
|
||||
eprintln!(" file_iv: {}", hex::encode(&iv));
|
||||
eprintln!("device_key: {}", hex::encode(device_key));
|
||||
eprintln!(" file_iv: {}", hex::encode(iv));
|
||||
}
|
||||
|
||||
let decipher = Decipher::new(&device_key, &iv);
|
||||
|
||||
@@ -28,15 +28,15 @@ pub struct Cli {
|
||||
|
||||
fn run_command(cli: &Cli) -> Result<i32> {
|
||||
match &cli.command {
|
||||
Some(Commands::JOOX(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::KGM(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::Migu3D(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::NCM(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::QMCv1(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::QMCv2(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::QTFM(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::Xiami(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::XMLY(cmd)) => cmd.run(&cli),
|
||||
Some(Commands::Joox(cmd)) => cmd.run(cli),
|
||||
Some(Commands::Kgm(cmd)) => cmd.run(cli),
|
||||
Some(Commands::Migu3D(cmd)) => cmd.run(cli),
|
||||
Some(Commands::Ncm(cmd)) => cmd.run(cli),
|
||||
Some(Commands::QMCv1(cmd)) => cmd.run(cli),
|
||||
Some(Commands::QMCv2(cmd)) => cmd.run(cli),
|
||||
Some(Commands::QtFM(cmd)) => cmd.run(cli),
|
||||
Some(Commands::Xiami(cmd)) => cmd.run(cli),
|
||||
Some(Commands::Xmly(cmd)) => cmd.run(cli),
|
||||
None => {
|
||||
// https://github.com/clap-rs/clap/issues/3857#issuecomment-1161796261
|
||||
todo!("implement a sensible default command, similar to um/cli");
|
||||
|
||||
@@ -23,7 +23,7 @@ impl JooxDecipher for Header {
|
||||
|
||||
let (buffer, _) = buffer
|
||||
.split_at_mut_checked(buffer_size)
|
||||
.ok_or_else(|| JooxError::OutputBufferTooSmall(buffer_size))?;
|
||||
.ok_or(JooxError::OutputBufferTooSmall(buffer_size))?;
|
||||
|
||||
let result = (&self.aes_engine)
|
||||
.decrypt_padded_mut::<Pkcs7>(buffer)
|
||||
|
||||
@@ -96,9 +96,9 @@ impl Header {
|
||||
}
|
||||
|
||||
fn get_challenge_data(magic_header: &[u8; 0x10]) -> Result<[u8; 0x10], KugouError> {
|
||||
match magic_header {
|
||||
&KGM_HEADER => Ok(KGM_TEST_DATA),
|
||||
&VPR_HEADER => Ok(VPR_TEST_DATA),
|
||||
match *magic_header {
|
||||
KGM_HEADER => Ok(KGM_TEST_DATA),
|
||||
VPR_HEADER => Ok(VPR_TEST_DATA),
|
||||
_ => Err(KugouError::NotKGMFile)?,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ pub struct DecipherV2 {
|
||||
impl DecipherV2 {
|
||||
pub fn new(header: &Header) -> Result<Self, KugouError> {
|
||||
let mut key = [0u8; 4];
|
||||
key.copy_from_slice(get_slot_key(&header)?);
|
||||
key.copy_from_slice(get_slot_key(header)?);
|
||||
Ok(Self { key })
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ impl MetadataParser for PcV1Legacy {
|
||||
let ekey = payload
|
||||
.iter()
|
||||
.take_while(|&&b| b != 0)
|
||||
.map(|&b| b)
|
||||
.copied()
|
||||
.collect::<Vec<_>>();
|
||||
let ekey = String::from_utf8_lossy(ekey.as_slice());
|
||||
if !is_base64(ekey.as_bytes()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
mod constants;
|
||||
mod des;
|
||||
mod des_impl;
|
||||
mod utils;
|
||||
|
||||
pub use des::{DESMode, QrcDes};
|
||||
pub use des_impl::{DESMode, QrcDes};
|
||||
|
||||
@@ -28,7 +28,7 @@ pub fn make_device_secret<S: AsRef<[u8]>>(
|
||||
let device_id_hash_code_hex = device_id_hash_code_hex.as_bytes();
|
||||
|
||||
let mut device_key = [0u8; 0x10];
|
||||
device_key[..device_id_hash_code_hex.len()].copy_from_slice(&device_id_hash_code_hex);
|
||||
device_key[..device_id_hash_code_hex.len()].copy_from_slice(device_id_hash_code_hex);
|
||||
for (key, salt) in device_key.iter_mut().zip(DEVICE_KEY_SALT) {
|
||||
*key = salt.wrapping_add(*key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user