private YubikeyNeoManager() { YubicoNeoReturnCode code = YubikeyNeoNative.YkNeoManagerGlobalInit(0); if (code != YubicoNeoReturnCode.YKNEOMGR_OK) { throw new Exception("Unable to init global: " + code); } }
internal YubikeyNeoDevice(string name) { YubicoNeoReturnCode code = YubikeyNeoNative.YkNeoManagerInit(ref _currentDevice); if (code != YubicoNeoReturnCode.YKNEOMGR_OK) { throw new Exception("Unable to init: " + code); } YubikeyNeoNative.YkNeoManagerConnect(_currentDevice, name); }
public void SetMode(YubicoNeoModeEnum mode) { if (_currentDevice == IntPtr.Zero) { return; } if (_currentDevice == IntPtr.Zero) { throw new Exception("Not initialized"); } YubicoNeoReturnCode code = YubikeyNeoNative.YkNeoManagerSetMode(_currentDevice, mode); if (code != YubicoNeoReturnCode.YKNEOMGR_OK) { throw new Exception("Unable to set mode: " + code); } }
public IEnumerable <string> ListDevices(bool filter = true) { byte[] data; using (YubikeyNeoDeviceHandle deviceHandle = new YubikeyNeoDeviceHandle()) { IntPtr ptr = IntPtr.Zero; try { int len = 2048; // A typical reader name is 32 chars long. This gives space for 64 readers. ptr = Marshal.AllocHGlobal(len); YubicoNeoReturnCode res = YubikeyNeoNative.YkNeoManagerListDevices(deviceHandle.Device, ptr, ref len); if (res != YubicoNeoReturnCode.YKNEOMGR_OK) { return(Enumerable.Empty <string>()); } data = new byte[len]; Marshal.Copy(ptr, data, 0, len); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } } if (filter) { return(StringUtils.ParseStrings(data).Where(IsValidDevice)); } return(StringUtils.ParseStrings(data)); }