lib_um_crypto_rust/um_crypto/ncm/src/lib.rs

38 lines
1.2 KiB
Rust
Raw Normal View History

2024-09-14 00:33:32 +00:00
pub mod content_key;
pub mod header;
pub mod metadata;
use cipher::block_padding::UnpadError;
use thiserror::Error;
use umc_utils::base64;
#[derive(Error, Debug)]
pub enum NetEaseCryptoError {
#[error("Header need at least {0} more bytes")]
HeaderTooSmall(usize),
#[error("Not a NCM file")]
NotNCMFile,
#[error("Invalid NCM checksum. Expected {expected:08x}, actual: {expected:08x}")]
ChecksumInvalid { expected: u32, actual: u32 },
#[error("Unsupported cover image version: {0}")]
UnsupportedCoverImageVersion(u8),
#[error("Cover image: Frame size is less than image 1. frame_size:{frame_size}, image1_size:{image1_size}")]
InvalidCoverImage2Size {
frame_size: usize,
image1_size: usize,
},
#[error("ContentKey: AES PKCS#7 Decode Error")]
ContentKeyDecryptError(UnpadError),
#[error("ContentKey: Invalid key prefix: {0}")]
ContentKeyWrongPrefix(String),
#[error("Metadata: Invalid prefix while decoding: {0}")]
MetadataWrongPrefix(String),
#[error("Metadata: AES PKCS#7 Decode Error")]
MetadataDecryptError(UnpadError),
#[error("Metadata: Decode metadata failed: {0}")]
MetadataDecodeError(base64::DecodeError),
}