public YubikeyNeoDeviceHandle() { IntPtr intPtr = IntPtr.Zero; YubikeyNeoNative.YkNeoManagerInit(ref intPtr); Device = intPtr; }
private YubikeyNeoManager() { YubicoNeoReturnCode code = YubikeyNeoNative.YkNeoManagerGlobalInit(0); if (code != YubicoNeoReturnCode.YKNEOMGR_OK) { throw new Exception("Unable to init global: " + code); } }
public void Dispose() { if (Device != IntPtr.Zero) { YubikeyNeoNative.YkNeoManagerDone(Device); } Device = IntPtr.Zero; }
public void Dispose() { if (_currentDevice == IntPtr.Zero) { return; } YubikeyNeoNative.YkNeoManagerDone(_currentDevice); _currentDevice = IntPtr.Zero; }
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 YubicoNeoMode GetMode() { if (_currentDevice == IntPtr.Zero) { return(new YubicoNeoMode(0)); } if (_currentDevice == IntPtr.Zero) { throw new Exception("Not initialized"); } return(new YubicoNeoMode(YubikeyNeoNative.YkNeoManagerGetMode(_currentDevice))); }
public int GetSerialNumber() { if (_currentDevice == IntPtr.Zero) { return(-1); } if (_currentDevice == IntPtr.Zero) { throw new Exception("Not initialized"); } return(YubikeyNeoNative.YkNeoManagerGetSerialNumber(_currentDevice)); }
public Version GetVersion() { if (_currentDevice == IntPtr.Zero) { return(new Version()); } if (_currentDevice == IntPtr.Zero) { throw new Exception("Not initialized"); } byte major = YubikeyNeoNative.YkNeoManagerGetVersionMajor(_currentDevice); byte minor = YubikeyNeoNative.YkNeoManagerGetVersionMinor(_currentDevice); byte build = YubikeyNeoNative.YkNeoManagerGetVersionBuild(_currentDevice); return(new Version(major, minor, build)); }
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)); }
public void Dispose() { YubikeyNeoNative.YkNeoManagerGlobalDone(); }