refactor: ekey decrypt now return Vec<u8>
instead.
This commit is contained in:
parent
e1ed4ba6cf
commit
7502b310d2
@ -42,7 +42,7 @@ fn make_simple_key<const N: usize>() -> [u8; N] {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn decrypt_v1(ekey: &[u8]) -> Result<Box<[u8]>> {
|
||||
pub fn decrypt_v1(ekey: &[u8]) -> Result<Vec<u8>> {
|
||||
if ekey.len() < 12 {
|
||||
Err(EKeyDecryptError::EKeyTooShort)?;
|
||||
}
|
||||
@ -58,10 +58,10 @@ pub fn decrypt_v1(ekey: &[u8]) -> Result<Box<[u8]>> {
|
||||
.collect_vec();
|
||||
|
||||
let plaintext = tc_tea::decrypt(cipher, tea_key).map_err(EKeyDecryptError::FailDecryptV1)?;
|
||||
Ok([header, &plaintext].concat().into())
|
||||
Ok([header, &plaintext].concat())
|
||||
}
|
||||
|
||||
pub fn decrypt_v2(ekey: &[u8]) -> Result<Box<[u8]>> {
|
||||
pub fn decrypt_v2(ekey: &[u8]) -> Result<Vec<u8>> {
|
||||
let ekey = base64::decode(ekey)?;
|
||||
let ekey = tc_tea::decrypt(ekey, EKEY_V2_KEY1).map_err(EKeyDecryptError::FailDecryptV2)?;
|
||||
let ekey = tc_tea::decrypt(ekey, EKEY_V2_KEY2).map_err(EKeyDecryptError::FailDecryptV2)?;
|
||||
@ -70,7 +70,7 @@ pub fn decrypt_v2(ekey: &[u8]) -> Result<Box<[u8]>> {
|
||||
decrypt_v1(&ekey)
|
||||
}
|
||||
|
||||
pub fn decrypt<T: AsRef<[u8]>>(ekey: T) -> Result<Box<[u8]>> {
|
||||
pub fn decrypt<T: AsRef<[u8]>>(ekey: T) -> Result<Vec<u8>> {
|
||||
let ekey = ekey.as_ref();
|
||||
match ekey.strip_prefix(EKEY_V2_PREFIX) {
|
||||
Some(v2_ekey) => decrypt_v2(v2_ekey),
|
||||
|
Loading…
Reference in New Issue
Block a user