-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(copymanga): search not working (#664)
* fix: update searching url * chore: bump version * refactor: rewrite enum `Url` * fix: remove unsed constant `DOMAIN` * fix: not to panic! * refactor: extract duplicate code to function * refactor: replace `let-else` with `ok_or_else`
- Loading branch information
Showing
8 changed files
with
170 additions
and
112 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
use crate::helper::to_aidoku_error; | ||
use aes::{ | ||
cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit}, | ||
Aes128, | ||
}; | ||
use aidoku::std::String; | ||
use aidoku::{error::Result, std::String}; | ||
use core::marker::Sized; | ||
|
||
type Aes128CbcDec = cbc::Decryptor<Aes128>; | ||
|
||
const KEY: &[u8] = b"xxxmanga.woo.key"; | ||
|
||
pub trait EncryptedString { | ||
fn decrypt(self) -> String; | ||
fn decrypt(self) -> Result<Self> | ||
where | ||
Self: Sized; | ||
} | ||
|
||
impl EncryptedString for String { | ||
fn decrypt(self) -> String { | ||
fn decrypt(self) -> Result<Self> { | ||
let encrypted_data = self.as_bytes(); | ||
let iv = &encrypted_data[..16]; | ||
let mut ciphertext = | ||
hex::decode(&encrypted_data[16..]).expect("Failed to hex-decode ciphertext."); | ||
let iv = encrypted_data | ||
.get(..16) | ||
.ok_or_else(|| to_aidoku_error("Failed to get `iv` from `encrypted_data`"))?; | ||
let hex_ciphertext = encrypted_data.get(16..).ok_or_else(|| { | ||
to_aidoku_error("Failed to get `hex_ciphertext` from `encrypted_data`") | ||
})?; | ||
let mut ciphertext = hex::decode(hex_ciphertext).map_err(to_aidoku_error)?; | ||
|
||
let plaintext = Aes128CbcDec::new(KEY.into(), iv.into()) | ||
.decrypt_padded_mut::<Pkcs7>(&mut ciphertext) | ||
.expect("Failed to decrypt chapter list"); | ||
String::from_utf8_lossy(plaintext).into() | ||
.map_err(to_aidoku_error)?; | ||
Ok(Self::from_utf8_lossy(plaintext).into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use aidoku::{ | ||
error::{AidokuError, AidokuErrorKind, Result}, | ||
prelude::println, | ||
}; | ||
use core::fmt::Display; | ||
use regex::Regex as OriginalRegex; | ||
|
||
pub struct Regex; | ||
|
||
impl Regex { | ||
#[allow(clippy::new_ret_no_self)] | ||
pub fn new<S: AsRef<str>>(pat: S) -> Result<OriginalRegex> { | ||
OriginalRegex::new(pat.as_ref()).map_err(to_aidoku_error) | ||
} | ||
} | ||
|
||
pub fn to_aidoku_error<E: Display>(err: E) -> AidokuError { | ||
println!("{err}"); | ||
|
||
AidokuError { | ||
reason: AidokuErrorKind::Unimplemented, | ||
} | ||
} |
Oops, something went wrong.