kerberos_asn1/
int32.rs

1
2/// (*Int32*) Kerberos i32.
3/// Defined in RFC4120, section 5.2.4.
4/// ```asn1
5///    Int32           ::= INTEGER (-2147483648..2147483647)
6///                    -- signed values representable in 32 bits
7/// ```
8pub type Int32 = i32;
9
10#[cfg(test)]
11mod test {
12    use super::*;
13    use red_asn1::Asn1Object;
14
15    #[test]
16    fn test_encode_int32() {
17        assert_eq!(vec![0x02, 0x02, 0xff, 0x79], Int32::from(-135).build());
18
19        assert_eq!(vec![0x02, 0x01, 0x03], Int32::from(3).build());
20    }
21
22    #[test]
23    fn test_decode_int32() {
24        assert_eq!(-135, Int32::parse(&[0x02, 0x02, 0xff, 0x79]).unwrap().1);
25
26        assert_eq!(3, Int32::parse(&[0x02, 0x01, 0x03]).unwrap().1);
27    }
28
29    #[should_panic(expected = "IncorrectValue")]
30    #[test]
31    fn test_decode_higher_value_than_int32() {
32        Int32::parse(&[0x02, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00]).unwrap();
33    }
34
35    #[should_panic(expected = "IncorrectValue")]
36    #[test]
37    fn test_decode_lower_value_than_int32() {
38        Int32::parse(&[0x02, 0x05, 0xf1, 0x00, 0x00, 0x00, 0x00]).unwrap();
39    }
40
41}