示例#1
0
        public YubikeyNeoDeviceHandle()
        {
            IntPtr intPtr = IntPtr.Zero;

            YubikeyNeoNative.YkNeoManagerInit(ref intPtr);
            Device = intPtr;
        }
示例#2
0
        private YubikeyNeoManager()
        {
            YubicoNeoReturnCode code = YubikeyNeoNative.YkNeoManagerGlobalInit(0);

            if (code != YubicoNeoReturnCode.YKNEOMGR_OK)
            {
                throw new Exception("Unable to init global: " + code);
            }
        }
示例#3
0
        public void Dispose()
        {
            if (Device != IntPtr.Zero)
            {
                YubikeyNeoNative.YkNeoManagerDone(Device);
            }

            Device = IntPtr.Zero;
        }
示例#4
0
        public void Dispose()
        {
            if (_currentDevice == IntPtr.Zero)
            {
                return;
            }

            YubikeyNeoNative.YkNeoManagerDone(_currentDevice);
            _currentDevice = IntPtr.Zero;
        }
示例#5
0
        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);
        }
示例#6
0
        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)));
        }
示例#7
0
        public int GetSerialNumber()
        {
            if (_currentDevice == IntPtr.Zero)
            {
                return(-1);
            }

            if (_currentDevice == IntPtr.Zero)
            {
                throw new Exception("Not initialized");
            }

            return(YubikeyNeoNative.YkNeoManagerGetSerialNumber(_currentDevice));
        }
示例#8
0
        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));
        }
示例#9
0
        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);
            }
        }
示例#10
0
        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));
        }
示例#11
0
 public void Dispose()
 {
     YubikeyNeoNative.YkNeoManagerGlobalDone();
 }