pub fn decrypt_server_payload(
    context: &Context,
    method: CipherKind,
    key: &[u8],
    payload: &mut [u8],
) -> ProtocolResult<(usize, Address, Option<UdpSocketControlData>)> {
    match method.category() {
        CipherCategory::None => {
            let _ = context;
            let _ = key;

            let mut cur = Cursor::new(payload);
            match Address::read_cursor(&mut cur) {
                Ok(address) => {
                    let pos = cur.position() as usize;
                    let payload = cur.into_inner();
                    payload.copy_within(pos.., 0);
                    Ok((payload.len() - pos, address, None))
                }
                Err(err) => Err(ProtocolError::InvalidAddress(err)),
            }
        }
        #[cfg(feature = "stream-cipher")]
        CipherCategory::Stream => decrypt_payload_stream(context, method, key, payload)
            .map(|(n, a)| (n, a, None))
            .map_err(Into::into),
        #[cfg(feature = "aead-cipher")]
        CipherCategory::Aead => decrypt_payload_aead(context, method, key, payload)
            .map(|(n, a)| (n, a, None))
            .map_err(Into::into),
        #[cfg(feature = "aead-cipher-2022")]
        CipherCategory::Aead2022 => decrypt_server_payload_aead_2022(context, method, key, payload)
            .map(|(n, a, c)| (n, a, Some(c)))
            .map_err(Into::into),
    }
}
Decrypt `Server -> Client` payload from ShadowSocks UDP encrypted packet
crates/shadowsocks/src/relay/udprelay/crypto_io.rs