Skip to main content

tiberius/
tds.rs

1pub mod codec;
2pub(crate) mod collation;
3mod context;
4pub mod numeric;
5pub mod stream;
6pub mod time;
7pub mod xml;
8
9pub(crate) use collation::*;
10pub(crate) use context::*;
11pub(crate) use numeric::*;
12
13/// The amount of bytes a packet header consists of
14pub(crate) const HEADER_BYTES: usize = 8;
15
16uint_enum! {
17    /// The configured encryption level specifying if encryption is required
18    #[repr(u8)]
19    pub enum EncryptionLevel {
20        /// Only use encryption for the login procedure
21        Off = 0,
22        /// Encrypt everything if possible
23        On = 1,
24        /// Do not encrypt anything
25        NotSupported = 2,
26        /// Encrypt everything and fail if not possible
27        Required = 3,
28        /// Start encryption before the TDS prelogin (TDS 8.0 "strict" mode) and
29        /// encrypt everything, failing if not possible.
30        Strict = 4,
31    }
32
33}
34
35impl EncryptionLevel {
36    /// The value sent on the wire in the prelogin `ENCRYPTION` option.
37    ///
38    /// `Strict` (TDS 8.0) is negotiated out-of-band via a TLS handshake before
39    /// the prelogin, so when a prelogin is emitted at all it advertises the
40    /// classic `Required` value.
41    pub(crate) fn as_wire_value(&self) -> u8 {
42        match self {
43            EncryptionLevel::Strict => EncryptionLevel::Required as u8,
44            other => *other as u8,
45        }
46    }
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn encryption_level_as_wire_value() {
55        assert_eq!(EncryptionLevel::Off.as_wire_value(), 0);
56        assert_eq!(EncryptionLevel::On.as_wire_value(), 1);
57        assert_eq!(EncryptionLevel::NotSupported.as_wire_value(), 2);
58        assert_eq!(EncryptionLevel::Required.as_wire_value(), 3);
59        assert_eq!(EncryptionLevel::Strict.as_wire_value(), 3);
60    }
61}