Esempio n. 1
0
        async Task <FidoU2FHidMessage> QueryLowLevelAsync(FidoU2FHidMessage query, CancellationToken cancellationToken, bool throwErrors = true)
        {
            try
            {
                await device.WriteFidoU2FHidMessageAsync(query, cancellationToken);

                var init = await device.ReadFidoU2FHidMessageAsync(cancellationToken);

                if (init.Channel != query.Channel)
                {
                    throw new Exception(
                              $"Bad channel in query answer (0x{init.Channel:X8} but expected 0x{query.Channel:X8})");
                }

                if (init.Command == U2FHidCommand.Error)
                {
                    if (throwErrors)
                    {
                        ThrowForError(init);
                    }
                    return(init);
                }

                if (init.Command != query.Command)
                {
                    throw new Exception($"Bad command in query answer ({init.Command} but expected {query.Command})");
                }

                return(init);
            }
            catch (DeviceNotConnectedException exception)
            {
                throw new KeyGoneException("The key isn't connected anymore", exception);
            }
        }