Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6951e474 authored by Zhengping Jiang's avatar Zhengping Jiang
Browse files

floss: pad zero when convert to little endian

If the key has zeros, the conversion may lose digits without padding
zeros.

Bug: 298575700
Test: mma -j32 | cl_HID_reports_reboot_test.floss
Change-Id: I2d98a2d9818a081a0a9d78f5fc4c341c45c4ff0e
parent d6f23d8c
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -246,9 +246,9 @@ fn reverse_endianness(str: String, uppercase: bool) -> Result<String, String> {
    match u128::from_str_radix(&s, 16) {
    match u128::from_str_radix(&s, 16) {
        Ok(x) => {
        Ok(x) => {
            if uppercase {
            if uppercase {
                Ok(format!("{:X}", x.swap_bytes()))
                Ok(format!("{:0>32X}", x.swap_bytes()))
            } else {
            } else {
                Ok(format!("{:x}", x.swap_bytes()))
                Ok(format!("{:0>32x}", x.swap_bytes()))
            }
            }
        }
        }
        Err(err) => Err(format!("Error converting link key: {}", err)),
        Err(err) => Err(format!("Error converting link key: {}", err)),
@@ -961,6 +961,11 @@ mod tests {
            key.apply_action("00112233445566778899AABBCCDDEE".to_string()),
            key.apply_action("00112233445566778899AABBCCDDEE".to_string()),
            Ok("eeddccbbaa9988776655443322110000".to_string())
            Ok("eeddccbbaa9988776655443322110000".to_string())
        );
        );
        // Conversion shouldn't lose leading zeros
        assert_eq!(
            key.apply_action("112233445566778899AABBCCDDEE0000".to_string()),
            Ok("0000eeddccbbaa998877665544332211".to_string())
        );
    }
    }


    #[test]
    #[test]