@@ -545,7 +545,11 @@ impl RouterKey {
545
545
/// The only flag currently used is the least significant bit that is
546
546
/// 1 for an announcement and 0 for a withdrawal.
547
547
pub fn flags ( & self ) -> u8 {
548
- ( self . fixed . header . session >> 8 ) as u8
548
+ // The two-byte Session field is reused for the Flags byte and one
549
+ // reserved byte (of zeroes). As the value of the Session field is in
550
+ // network byte order, we are actually looking at (Reserved, Flags),
551
+ // so we want the lower byte here.
552
+ self . fixed . header . session as u8
549
553
}
550
554
551
555
/// Returns the subject key identifier.
@@ -845,7 +849,11 @@ impl Aspa {
845
849
/// The only flag currently used is the least significant bit that is
846
850
/// 1 for an announcement and 0 for a withdrawal.
847
851
pub fn flags ( & self ) -> u8 {
848
- ( self . fixed . header . session >> 8 ) as u8
852
+ // The two-byte Session field is reused for the Flags byte and one
853
+ // reserved byte (of zeroes). As the value of the Session field is in
854
+ // network byte order, we are actually looking at (Reserved, Flags),
855
+ // so we want the lower byte here.
856
+ self . fixed . header . session as u8
849
857
}
850
858
851
859
/// Returns the customer ASN.
@@ -1818,6 +1826,19 @@ mod test {
1818
1826
) ;
1819
1827
}
1820
1828
1829
+ #[ test]
1830
+ fn router_key_flags ( ) {
1831
+ for flags in [ 0 , 1 , 128 , 255 ] {
1832
+ let key = RouterKey :: new (
1833
+ 1 , flags,
1834
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 ] ,
1835
+ Asn :: from_u32 ( 0x1000f ) ,
1836
+ RouterKeyInfo :: new ( Bytes :: from_static ( & [ 21 , 22 , 23 , 24 ] ) ) . unwrap ( )
1837
+ ) ;
1838
+ assert_eq ! ( key. flags( ) , flags) ;
1839
+ }
1840
+ }
1841
+
1821
1842
#[ tokio:: test]
1822
1843
async fn read_write_aspa ( ) {
1823
1844
read_write ! (
@@ -1836,6 +1857,20 @@ mod test {
1836
1857
) ;
1837
1858
}
1838
1859
1860
+ #[ test]
1861
+ fn aspa_flags ( ) {
1862
+ for flags in [ 0 , 1 , 128 , 255 ] {
1863
+ let aspa = Aspa :: new (
1864
+ 2 , flags,
1865
+ Asn :: from_u32 ( 0x1000f ) ,
1866
+ ProviderAsns :: try_from_iter ( [
1867
+ Asn :: from_u32 ( 0x1000d ) , Asn :: from_u32 ( 0x1000e )
1868
+ ] ) . unwrap ( ) ,
1869
+ ) ;
1870
+ assert_eq ! ( aspa. flags( ) , flags) ;
1871
+ }
1872
+ }
1873
+
1839
1874
#[ test]
1840
1875
fn provider_count ( ) {
1841
1876
assert_eq ! (
0 commit comments