Skip to content

Commit

Permalink
assert -> debug_assert in data path
Browse files Browse the repository at this point in the history
  • Loading branch information
ctz committed Sep 26, 2016
1 parent 7af1e3e commit 86267ce
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/cipher.rs
Expand Up @@ -189,9 +189,9 @@ impl GCMMessageCipher {
nonce_offset: [0u8; 8]
};

assert_eq!(enc_iv.len(), 4);
assert_eq!(dec_iv.len(), 4);
assert_eq!(nonce_offset.len(), 8);
debug_assert_eq!(enc_iv.len(), 4);
debug_assert_eq!(dec_iv.len(), 4);
debug_assert_eq!(nonce_offset.len(), 8);

ret.enc_salt.as_mut().write(enc_iv).unwrap();
ret.dec_salt.as_mut().write(dec_iv).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/client.rs
Expand Up @@ -57,7 +57,7 @@ pub struct ClientSessionMemoryCache {

impl ClientSessionMemoryCache {
pub fn new(size: usize) -> Box<ClientSessionMemoryCache> {
assert!(size > 0);
debug_assert!(size > 0);
Box::new(ClientSessionMemoryCache {
cache: collections::HashMap::new(),
max_entries: size
Expand Down Expand Up @@ -220,7 +220,7 @@ impl ClientConfig {
* is PACKET_OVERHEAD. */
if let Some(x) = *mtu {
use msgs::fragmenter;
assert!(x > fragmenter::PACKET_OVERHEAD);
debug_assert!(x > fragmenter::PACKET_OVERHEAD);
self.mtu = Some(x - fragmenter::PACKET_OVERHEAD);
} else {
self.mtu = None;
Expand Down
6 changes: 3 additions & 3 deletions src/hash_hs.rs
Expand Up @@ -33,7 +33,7 @@ impl HandshakeHash {
/// We might be doing client auth, so need to keep a full
/// log of the handshake.
pub fn set_client_auth_enabled(&mut self) {
assert!(self.ctx.is_none()); // or we might have already discarded messages
debug_assert!(self.ctx.is_none()); // or we might have already discarded messages
self.client_auth_enabled = true;
}

Expand All @@ -46,7 +46,7 @@ impl HandshakeHash {

/// We now know what hash function the verify_data will use.
pub fn start_hash(&mut self, alg: &'static digest::Algorithm) {
assert!(self.ctx.is_none());
debug_assert!(self.ctx.is_none());

let mut ctx = digest::Context::new(alg);
ctx.update(&self.buffer);
Expand Down Expand Up @@ -95,7 +95,7 @@ impl HandshakeHash {
/// so far. This method only works once; it resets the buffer
/// to empty.
pub fn take_handshake_buf(&mut self) -> Vec<u8> {
assert!(self.client_auth_enabled);
debug_assert!(self.client_auth_enabled);
mem::replace(&mut self.buffer, Vec::new())
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/msgs/codec.rs
Expand Up @@ -166,7 +166,7 @@ pub fn encode_vec_u8<T: Codec>(bytes: &mut Vec<u8>, items: &[T]) {
i.encode(&mut sub);
}

assert!(sub.len() <= 0xff);
debug_assert!(sub.len() <= 0xff);
encode_u8(sub.len() as u8, bytes);
bytes.append(&mut sub);
}
Expand All @@ -177,7 +177,7 @@ pub fn encode_vec_u16<T: Codec>(bytes: &mut Vec<u8>, items: &[T]) {
i.encode(&mut sub);
}

assert!(sub.len() <= 0xffff);
debug_assert!(sub.len() <= 0xffff);
encode_u16(sub.len() as u16, bytes);
bytes.append(&mut sub);
}
Expand All @@ -188,7 +188,7 @@ pub fn encode_vec_u24<T: Codec>(bytes: &mut Vec<u8>, items: &[T]) {
i.encode(&mut sub);
}

assert!(sub.len() <= 0xffffff);
debug_assert!(sub.len() <= 0xffffff);
encode_u24(sub.len() as u32, bytes);
bytes.append(&mut sub);
}
Expand Down
2 changes: 1 addition & 1 deletion src/msgs/fragmenter.rs
Expand Up @@ -15,7 +15,7 @@ impl MessageFragmenter {
/// include overhead (so a `max_fragment_len` of 5 will produce
/// 10 byte packets).
pub fn new(max_fragment_len: usize) -> MessageFragmenter {
assert!(max_fragment_len <= MAX_FRAGMENT_LEN);
debug_assert!(max_fragment_len <= MAX_FRAGMENT_LEN);
MessageFragmenter {
max_frag: max_fragment_len
}
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Expand Up @@ -138,7 +138,7 @@ pub struct ServerSessionMemoryCache {

impl ServerSessionMemoryCache {
pub fn new(size: usize) -> Box<ServerSessionMemoryCache> {
assert!(size > 0);
debug_assert!(size > 0);
Box::new(ServerSessionMemoryCache {
cache: collections::HashMap::new(),
max_entries: size
Expand Down
2 changes: 1 addition & 1 deletion src/server_hs.rs
Expand Up @@ -422,7 +422,7 @@ fn handle_client_hello(sess: &mut ServerSessionImpl, m: Message) -> Result<ConnS
.ok_or_else(|| incompatible(sess, "no supported point format"))
);

assert_eq!(ecpoint, ECPointFormat::Uncompressed);
debug_assert_eq!(ecpoint, ECPointFormat::Uncompressed);

try!(emit_server_hello(sess, client_hello));
emit_certificate(sess);
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Expand Up @@ -332,7 +332,7 @@ impl SessionCommon {
return;
}

assert!(self.we_encrypting);
debug_assert!(self.we_encrypting);

if data.len() == 0 {
/* Don't send empty fragments. */
Expand Down

0 comments on commit 86267ce

Please sign in to comment.