Skip to main content

Cipher

Struct Cipher 

Source
pub struct Cipher { /* private fields */ }

Implementations§

Source§

impl Cipher

Source

pub fn aes_128_cbc() -> Cipher

Examples found in repository?
examples/m3u8_down.rs (line 79)
64    fn download(&mut self) -> Result<(), HlsError> {
65        self.req.set_url(self.index_url.as_str())?;
66        let body = self.req.send_check(Method::GET)?.text()?;
67        // println!("{}", body);
68        for line in body.split("\n") {
69            if line.starts_with("#EXT-X-MEDIA-SEQUENCE:") {
70                self.sequence = line.trim().replace("#EXT-X-MEDIA-SEQUENCE:", "").parse()?;
71                continue;
72            }
73            if line.starts_with("#EXT-X-KEY") {
74                let pos = line.find("URI=\"");
75                if let Some(pos) = pos {
76                    self.key_url = line[pos + 4..].trim().replace("\"", "");
77                }
78                if line.contains("=AES-128,") {
79                    self.cipher = Cipher::aes_128_cbc();
80                }
81                continue;
82            }
83            if line.starts_with("http") {
84                self.ts_urls.push(line.trim().to_string());
85            }
86        }
87        let mut timeout = Timeout::new();
88        timeout.set_read(5000);
89        timeout.set_write(5000);
90        timeout.set_connect(5000);
91        timeout.set_handle(30000);
92        timeout.set_handle_times(10);
93        self.req.set_timeout(timeout);
94        if !self.key_url.is_empty() { self.get_key()?; }
95        self.down_ts()?;
96        Ok(())
97    }
Source

pub fn aes_192_cbc() -> Cipher

Source

pub fn aes_256_cbc() -> Cipher

Source

pub fn aes_128_ecb() -> Cipher

Examples found in repository?
examples/m3u8_down.rs (line 40)
15    fn new(index: impl ToString) -> M3u8DownEngine {
16        let mut req = ScReq::new().with_alpn(ALPN::Http20); //.with_proxy(Proxy::new_http_plain("127.0.0.1", 10809));
17        req.set_headers_json(json::object! {
18            "Host": "",
19            "sec-ch-ua-platform": "Android",
20            "user-agent": "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36",
21            "sec-ch-ua": r#""Android WebView";v="135", "Not-A.Brand";v="8", "Chromium";v="135""#,
22            "sec-ch-ua-mobile": "?1",
23            "accept": "*/*",
24            "origin": "",
25            "x-requested-with": "mark.via",
26            "sec-fetch-site": "cross-site",
27            "sec-fetch-mode": "cors",
28            "sec-fetch-dest": "empty",
29            "referer": "",
30            "accept-encoding": "gzip, deflate, br, zstd",
31            "accept-language": "en,zh-CN;q=0.9,zh;q=0.8,en-US;q=0.7",
32            "priority": "u=1, i"
33        }).unwrap();
34        M3u8DownEngine {
35            req,
36            index_url: index.to_string(),
37            sequence: 0,
38            key_url: "".to_string(),
39            ts_urls: vec![],
40            cipher: Cipher::aes_128_ecb(),
41        }
42    }
Source

pub fn aes_192_ecb() -> Cipher

Source

pub fn aes_256_ecb() -> Cipher

Source

pub fn aes_128_ctr() -> Cipher

Source

pub fn aes_192_ctr() -> Cipher

Source

pub fn aes_256_ctr() -> Cipher

Source

pub fn aes_128_gcm() -> Cipher

Source

pub fn aes_192_gcm() -> Cipher

Source

pub fn aes_256_gcm() -> Cipher

Source

pub fn aes_128_ofb() -> Cipher

Source

pub fn aes_192_ofb() -> Cipher

Source

pub fn aes_256_ofb() -> Cipher

Source

pub fn des_cbc() -> Cipher

Source

pub fn des_ecb() -> Cipher

Source

pub fn rc4() -> Cipher

Source

pub fn with_secret_key<T>(self, key: T, iv: Option<T>) -> Cipher
where T: Into<Vec<u8>>,

Source

pub fn set_secret_key<T>(&mut self, key: T, iv: Option<T>)
where T: Into<Vec<u8>>,

Examples found in repository?
examples/m3u8_down.rs (line 60)
55    fn get_key(&mut self) -> Result<(), HlsError> {
56        println!("key url: {}", self.key_url);
57        self.req.set_url(self.key_url.as_str())?;
58        let key = self.req.send_check(Method::GET)?.text()?;
59        println!("key: {}; sequence: {}", key, self.sequence);
60        self.cipher.set_secret_key(key.into_bytes(), Some(self.sequence.to_be_bytes().to_vec()));
61        Ok(())
62    }
Source

pub fn encrypt(&self, context: impl AsRef<[u8]>) -> Result<Vec<u8>, RlsError>

Source

pub fn decrypt(&self, context: impl Into<Vec<u8>>) -> Result<Vec<u8>, RlsError>

Examples found in repository?
examples/m3u8_down.rs (line 50)
44    fn down_ts(&mut self) -> Result<(), HlsError> {
45        let mut file = File::create("4.mp4")?;
46        for (index, ts_url) in self.ts_urls.iter().enumerate() {
47            println!("Downloading: {:3}/{}; url:{}", index, self.ts_urls.len(), ts_url);
48            self.req.set_url(ts_url)?;
49            let body = self.req.get()?.bytes()?;
50            file.write_all(&if self.key_url.is_empty() { body } else { self.cipher.decrypt(body)? })?;
51        }
52        Ok(())
53    }

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.