Repository: google/OpenSK
File: src/main.rs (Rust)

Code before:
            };
        });
        #[cfg(feature = "with_ctap1")]
        let mut buttons = buttons_callback.init().flex_unwrap();
        // At the moment, all buttons are accepted. You can customize your setup here.
        #[cfg(feature = "with_ctap1")]
        for mut button in &mut buttons {
            button.enable().flex_unwrap();
        }

        let mut pkt_request = [0; 64];
        let usb_endpoint =
            match usb_ctap_hid::recv_with_timeout(&mut pkt_request, KEEPALIVE_DELAY_TOCK)
                .flex_unwrap()
            {
                Some(usb_ctap_hid::SendOrRecvStatus::Received(endpoint)) => {
                    #[cfg(feature = "debug_ctap")]
                    print_packet_notice("Received packet", &clock);
                    Some(endpoint)
                }
                #[cfg(feature = "debug_ctap")]
                Some(usb_ctap_hid::SendOrRecvStatus::Sent) => {
                    panic!("Returned transmit status on receive")
                }
                #[cfg(not(feature = "debug_ctap"))]
                Some(usb_ctap_hid::SendOrRecvStatus::Sent) => panic!(),
                None => None,
            };

        let now = clock.try_now().unwrap();
        #[cfg(feature = "with_ctap1")]
        {
            if button_touched.get() {
                ctap.state().u2f_grant_user_presence(now);
            }
            // Cleanup button callbacks. We miss button presses while processing though.
            // Heavy computation mostly follows a registered touch luckily. Unregistering
            // callbacks is important to not clash with those from check_user_presence.
            for mut button in &mut buttons {
                button.disable().flex_unwrap();
            }
            drop(buttons);
            drop(buttons_callback);
        }

        // These calls are making sure that even for long inactivity, wrapping clock values
        // don't cause problems with timers.
        ctap.update_timeouts(now);

        if let Some(endpoint) = usb_endpoint {
            let transport = match endpoint {

Review comment (suggestion):
I don't think we should address binary size at call-site. We should fix this at a higher-level. I would just pay the cost of binary size and keep the code readable. (A simple fix would be to compile with `panic-immediate-abort` to fix all panics.)

Code after:
            };
        });
        #[cfg(feature = "with_ctap1")]
        let mut buttons = buttons_callback.init().flex_unwrap();
        // At the moment, all buttons are accepted. You can customize your setup here.
        #[cfg(feature = "with_ctap1")]
        for mut button in &mut buttons {
            button.enable().flex_unwrap();
        }

        let mut pkt_request = [0; 64];
        let usb_endpoint =
            match usb_ctap_hid::recv_with_timeout(&mut pkt_request, KEEPALIVE_DELAY_TOCK)
                .flex_unwrap()
            {
                usb_ctap_hid::SendOrRecvStatus::Received(endpoint) => {
                    #[cfg(feature = "debug_ctap")]
                    print_packet_notice("Received packet", &clock);
                    Some(endpoint)
                }
                usb_ctap_hid::SendOrRecvStatus::Sent => {
                    panic!("Returned transmit status on receive")
                }
                usb_ctap_hid::SendOrRecvStatus::Timeout => None,
            };

        let now = clock.try_now().unwrap();
        #[cfg(feature = "with_ctap1")]
        {
            if button_touched.get() {
                ctap.state().u2f_grant_user_presence(now);
            }
            // Cleanup button callbacks. We miss button presses while processing though.
            // Heavy computation mostly follows a registered touch luckily. Unregistering
            // callbacks is important to not clash with those from check_user_presence.
            for mut button in &mut buttons {
                button.disable().flex_unwrap();
            }
            drop(buttons);
            drop(buttons_callback);
        }

        // These calls are making sure that even for long inactivity, wrapping clock values
        // don't cause problems with timers.
        ctap.update_timeouts(now);

        if let Some(endpoint) = usb_endpoint {
            let transport = match endpoint {
                usb_ctap_hid::UsbEndpoint::MainHid => Transport::MainHid,
                #[cfg(feature = "vendor_hid")]
                usb_ctap_hid::UsbEndpoint::VendorHid => Transport::VendorHid,