Repository: google/OpenSK
File: examples/nfct_test.rs (Rust)

Code before:
                            }
                            _ => {
                                let mut reply = [rx_buf[0], 0x90, 0x00];
                                bench_transmit(&mut console, &timer, "TX: 0x9000", &mut reply);
                            }
                        }
                        0x52 | 0x50 /* WUPA | Halt */ => {
                            if NfcTag::disable_emulation() {
                                writeln!(console, " -- TAG DISABLED").unwrap();
                            }
                            state = State::Disabled;
                            break;
                        }
                        _ => (),
                    }
                }
            }
            State::Disabled => {
                NfcTag::enable_emulation();
                // Configure Type 4 tag
                if NfcTag::configure(4) {
                    state = State::Enabled;
                }
            }
        }
        state_change_cntr += 1;
        if state_change_cntr > 100 && state == State::Disabled {
            break;
        }
    }
    writeln!(console, "****************************************").unwrap();
}


Review comment (refactor):
It's a little bit hard to catch that you `break` inside the loop. I started wondering why you don't just use a `for` loop. I think a general reason is the nesting depth. Could the function be more readable if you refactor out the inner part? It could return a `bool` where it currently breaks.

Code after:
            0xc2 /* DESELECT */ => {
                // Ignore the request
                let mut command_error = [0x6A, 0x81];
                return_code = bench_transmit(&mut console, &timer, "TX: DESELECT", &mut command_error);
            }
            0x02 | 0x03 /* APDU Prefix */ => match buf[2] {
                // If the received packet is applet selection command (FIDO 2)
                0xa4 /* SELECT */ => if buf[3] == 0x04 && buf[5] == 0x08 && buf[6] == 0xa0 {
                    // Vesion: "FIDO_2_0"
                    let mut reply = [buf[0], 0x46, 0x49, 0x44, 0x4f, 0x5f, 0x32, 0x5f, 0x30, 0x90, 0x00,];
                    return_code = bench_transmit(&mut console, &timer, "TX: Version Str", &mut reply);
                } else if (buf[6] == 0xd2 && buf[7] == 0x76) || (buf[6] == 0xe1 && (buf[7] == 0x03 || buf[7] == 0x04)){
                    let mut reply = [buf[0], 0x90, 0x00];
                    return_code = bench_transmit(&mut console, &timer, "TX: 0x9000", &mut reply);
                } else /* Unknown file */ {
                    let mut reply = [buf[0], 0x6a, 0x82];
                    return_code = bench_transmit(&mut console, &timer, "TX: 0x6A82", &mut reply);
                }
                0xb0 /* READ */ =>  match buf[5] {
                    0x02 => {
                        let mut reply = [buf[0], 0x12, 0x90, 0x00,];
                        return_code = bench_transmit(&mut console, &timer, "TX: File Size", &mut reply);
                    }
                    0x12 => {
                        let mut reply = [buf[0], 0xd1, 0x01, 0x0e, 0x55, 0x77, 0x77, 0x77, 0x2e, 0x6f, 0x70, 0x65,
                        0x6e, 0x73, 0x6b, 0x2e, 0x64, 0x65, 0x76, 0x90, 0x00,];
                        return_code = bench_transmit(&mut console, &timer, "TX: NDEF", &mut reply);
                    }
                    0x0f => {
                        let mut reply = [buf[0], 0x00, 0x0f, 0x20, 0x00, 0x7f, 0x00, 0x7f, 0x04, 0x06, 0xe1, 0x04,
                        0x00, 0x7f, 0x00, 0x00, 0x90, 0x00,];
                        return_code = bench_transmit(&mut console, &timer, "TX: CC", &mut reply);
                    }
                    _ => {
                        let mut reply = [buf[0], 0x90, 0x00];
                        return_code = bench_transmit(&mut console, &timer, "TX: 0x9000", &mut reply);
                    }
                }
                _ => {
                    let mut reply = [buf[0], 0x90, 0x00];
                    return_code = bench_transmit(&mut console, &timer, "TX: 0x9000", &mut reply);
                }
            }
            0x26 | 0x52 | 0x50 /* REQA | WUPA | Halt */ => {
                return ReturnCode::EOFF;
            }
            _ => (),
        }
        return_code
    }