xref: /xiu/protocol/rtmp/src/handshake/errors.rs (revision ff1f1192)
1 
2 use byteorder::{BigEndian, ByteOrder, LittleEndian, WriteBytesExt};
3 use bytes::BytesMut;
4 use hmac::{Hmac, Mac};
5 use rand;
6 use rand::Rng;
7 use sha2::Sha256;
8 use std::convert::TryInto;
9 use std::io::{Cursor, Write};
10 use std::{collections::HashMap, ops::BitOr};
11 use tokio_util::codec::{BytesCodec, Framed};
12 
13 use liverust_lib::netio::{
14     bytes_errors::{BytesReadError, BytesWriteError},
15     //bytes_reader::NetworkReader,
16     bytes_reader::BytesReader,
17     bytes_writer::AsyncBytesWriter,
18     netio::NetworkIO,
19 };
20 
21 use tokio::prelude::*;
22 
23 use std::rc::Rc;
24 use std::cell::{RefCell, RefMut};
25 use std::time::{SystemTime, SystemTimeError};
26 
27 pub enum HandshakeErrorValue {
28     BytesReadError(BytesReadError),
29     BytesWriteError(BytesWriteError),
30     SysTimeError(SystemTimeError),
31     DigestNotFound,
32     S0VersionNotCorrect,
33 }
34 
35 pub struct HandshakeError {
36     pub value: HandshakeErrorValue,
37 }
38 
39 impl From<HandshakeErrorValue> for HandshakeError {
40     fn from(val: HandshakeErrorValue) -> Self {
41         HandshakeError { value: val }
42     }
43 }
44 
45 impl From<BytesReadError> for HandshakeError {
46     fn from(error: BytesReadError) -> Self {
47         HandshakeError {
48             value: HandshakeErrorValue::BytesReadError(error),
49         }
50     }
51 }
52 
53 impl From<BytesWriteError> for HandshakeError {
54     fn from(error: BytesWriteError) -> Self {
55         HandshakeError {
56             value: HandshakeErrorValue::BytesWriteError(error),
57         }
58     }
59 }
60 
61 impl From<SystemTimeError> for HandshakeError {
62     fn from(error: SystemTimeError) -> Self {
63         HandshakeError {
64             value: HandshakeErrorValue::SysTimeError(error),
65         }
66     }
67 }