mirror of https://github.com/ctz/rustls
Improve msgs::message coverage
This commit is contained in:
parent
39175e7252
commit
1803e8e7ad
|
@ -105,7 +105,6 @@ impl Codec for Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum MessageError {
|
pub enum MessageError {
|
||||||
TooShortForHeader,
|
TooShortForHeader,
|
||||||
TooShortForLength,
|
TooShortForLength,
|
||||||
|
@ -162,10 +161,6 @@ impl Message {
|
||||||
|
|
||||||
pub fn is_handshake_type(&self, hstyp: HandshakeType) -> bool {
|
pub fn is_handshake_type(&self, hstyp: HandshakeType) -> bool {
|
||||||
// Bit of a layering violation, but OK.
|
// Bit of a layering violation, but OK.
|
||||||
if !self.is_content_type(ContentType::Handshake) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let MessagePayload::Handshake(ref hsp) = self.payload {
|
if let MessagePayload::Handshake(ref hsp) = self.payload {
|
||||||
hsp.typ == hstyp
|
hsp.typ == hstyp
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,7 +252,6 @@ impl<'a> Message {
|
||||||
///
|
///
|
||||||
/// This type also cannot decode its internals and
|
/// This type also cannot decode its internals and
|
||||||
/// is not a `Codec` type, only `Message` can do that.
|
/// is not a `Codec` type, only `Message` can do that.
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct BorrowMessage<'a> {
|
pub struct BorrowMessage<'a> {
|
||||||
pub typ: ContentType,
|
pub typ: ContentType,
|
||||||
pub version: ProtocolVersion,
|
pub version: ProtocolVersion,
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
use super::codec::Reader;
|
use super::codec::Reader;
|
||||||
use super::codec::Codec;
|
use super::codec::Codec;
|
||||||
use super::message::Message;
|
use super::message::Message;
|
||||||
|
use super::enums::{
|
||||||
|
AlertDescription,
|
||||||
|
AlertLevel,
|
||||||
|
HandshakeType
|
||||||
|
};
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -60,3 +65,33 @@ fn can_read_safari_client_hello() {
|
||||||
println!("m = {:?}", m);
|
println!("m = {:?}", m);
|
||||||
assert_eq!(m.decode_payload(), false);
|
assert_eq!(m.decode_payload(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn alert_is_not_handshake() {
|
||||||
|
let m = Message::build_alert(AlertLevel::Fatal, AlertDescription::DecodeError);
|
||||||
|
assert_eq!(false, m.is_handshake_type(HandshakeType::ClientHello));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn alert_is_not_opaque() {
|
||||||
|
let mut m = Message::build_alert(AlertLevel::Fatal, AlertDescription::DecodeError);
|
||||||
|
assert_eq!(None, m.take_opaque_payload());
|
||||||
|
assert_eq!(false, m.decode_payload());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn construct_all_types() {
|
||||||
|
let samples = [
|
||||||
|
&b"\x14\x03\x04\x00\x01\x01"[..],
|
||||||
|
&b"\x15\x03\x04\x00\x02\x01\x16"[..],
|
||||||
|
&b"\x16\x03\x04\x00\x05\x18\x00\x00\x01\x00"[..],
|
||||||
|
&b"\x17\x03\x04\x00\x04\x11\x22\x33\x44"[..],
|
||||||
|
&b"\x18\x03\x04\x00\x04\x11\x22\x33\x44"[..]
|
||||||
|
];
|
||||||
|
for bytes in samples.iter() {
|
||||||
|
let mut m = Message::read_bytes(bytes).unwrap();
|
||||||
|
println!("m = {:?}", m);
|
||||||
|
m.decode_payload();
|
||||||
|
println!("m' = {:?}", m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue