public void PingSendCorrectBytes() { // Setup var scenario = HidScenario.Build(); BytesHolder holder = null; scenario.Write(report => { var sizeHi = report.Data.Array[report.Data.Offset + 5]; var sizeLo = report.Data.Array[report.Data.Offset + 6]; var size = (sizeHi << 8) | sizeLo; holder = new BytesHolder(size); AssertWriteInitPacket(report.Data, TestChannel, U2FHidCommand.Ping, holder); }); scenario.Read(() => new HidInputReport(BuildInitPacket(TestChannel, U2FHidCommand.Ping, holder))); var hid = CreateHidMock(); var device = new U2FHidKey(hid.Object, false); InitDevice(hid, device); scenario.Run(hid); // Act device.Ping().Wait(); // Assert scenario.End(); }
public async Task PingWithContinuation() { // Setup var pingData = new byte[100]; new Random().NextBytes(pingData); var writeInitData = pingData.Take(63 - 7).ToArray(); var writeContData = pingData.Skip(63 - 7).Take(63 - 5).ToArray(); var scenario = HidScenario.Build(); scenario.Write(report => AssertWriteInitPacketSized(report.Data, TestChannel, U2FHidCommand.Ping, pingData.Length, writeInitData)); scenario.Write(report => AssertWriteContinuation(report.Data, TestChannel, 0, writeContData)); scenario.Read(() => new HidInputReport(BuildInitPacketSized(TestChannel, U2FHidCommand.Ping, pingData.Length, writeInitData))); scenario.Read(() => new HidInputReport(BuildContinuationPacket(TestChannel, 0, writeContData))); var hid = CreateHidMock(); var device = new U2FHidKey(hid.Object, false); InitDevice(hid, device); scenario.Run(hid); // Act var returnedResponse = await device.Ping(pingData.Segment()); // Assert scenario.End(); Check.That(returnedResponse.ContentEquals(pingData.Segment())); }
public void WinkSendCorrectBytes() { // Setup var scenario = HidScenario.Build(); scenario.Write(report => AssertWriteInitPacket(report.Data, TestChannel, U2FHidCommand.Wink)); scenario.Read(() => new HidInputReport(BuildInitPacket(TestChannel, U2FHidCommand.Wink))); var hid = CreateHidMock(); var device = new U2FHidKey(hid.Object, false); InitDevice(hid, device); scenario.Run(hid); // Act device.WinkAsync().Wait(); // Assert scenario.End(); }
public void PingWithDataSendCorrectBytes() { // Setup var pingData = Encoding.UTF8.GetBytes("Testing !"); var scenario = HidScenario.Build(); scenario.Write(report => AssertWriteInitPacket(report.Data, TestChannel, U2FHidCommand.Ping, pingData)); scenario.Read(() => new HidInputReport(BuildInitPacket(TestChannel, U2FHidCommand.Ping, pingData))); var hid = CreateHidMock(); var device = new U2FHidKey(hid.Object, false); InitDevice(hid, device); scenario.Run(hid); // Act var returnedResponse = device.Ping(pingData.Segment()).Result; // Assert scenario.End(); Check.That(returnedResponse.ContentEquals(pingData.Segment())); }
static U2FHidDeviceInfo InitDevice(Mock <IHidDevice> hid, U2FHidKey device) { // Setup var scenario = HidScenario.Build(); var nonce = new BytesHolder(8); scenario.Write(report => AssertWriteInitPacket(report.Data, 0xffffffff, U2FHidCommand.Init, nonce)); scenario.Read(() => new HidInputReport(BuildInitPacket( 0xffffffff, U2FHidCommand.Init, nonce, (uint)TestChannel, (byte)1, (byte)2, (byte)3, (byte)4, (byte)U2FDeviceCapabilities.Wink))); scenario.Run(hid); var init = device.InitAsync().Result; scenario.End(); return(init); }