KeePassLib.Keys.CompositeKey.GetUserKey C# (CSharp) Method

GetUserKey() public method

Get the first user key of a specified type.
public GetUserKey ( Type tUserKeyType ) : IUserKey
tUserKeyType System.Type Type of the user key to get.
return IUserKey
        public IUserKey GetUserKey(Type tUserKeyType)
        {
            Debug.Assert(tUserKeyType != null);
            if(tUserKeyType == null) throw new ArgumentNullException("tUserKeyType");

            foreach(IUserKey pKey in m_vUserKeys)
            {
                if(pKey == null) { Debug.Assert(false); continue; }

            #if KeePassUAP
                if(pKey.GetType() == tUserKeyType)
                    return pKey;
            #else
                if(tUserKeyType.IsInstanceOfType(pKey))
                    return pKey;
            #endif
            }

            return null;
        }

Usage Example

Ejemplo n.º 1
0
        public void SetKeySources(IOConnectionInfo iocDb, CompositeKey cmpKey)
        {
            string strID = GetKeyAssocID(iocDb);
            int idx = GetKeyAssocIndex(strID);

            if((cmpKey == null) || !m_bRememberKeySources)
            {
                if(idx >= 0) m_vKeySources.RemoveAt(idx);
                return;
            }

            AceKeyAssoc a = new AceKeyAssoc();
            a.DatabasePath = strID;

            IUserKey kcpFile = cmpKey.GetUserKey(typeof(KcpKeyFile));
            if(kcpFile != null)
            {
                string strKeyFile = ((KcpKeyFile)kcpFile).Path;
                if(!string.IsNullOrEmpty(strKeyFile) && !StrUtil.IsDataUri(strKeyFile))
                {
                    if(!UrlUtil.IsAbsolutePath(strKeyFile))
                        strKeyFile = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(),
                            strKeyFile);

                    a.KeyFilePath = strKeyFile;
                }
            }

            IUserKey kcpCustom = cmpKey.GetUserKey(typeof(KcpCustomKey));
            if(kcpCustom != null)
                a.KeyProvider = ((KcpCustomKey)kcpCustom).Name;

            IUserKey kcpUser = cmpKey.GetUserKey(typeof(KcpUserAccount));
            a.UserAccount = (kcpUser != null);

            bool bAtLeastOne = ((a.KeyFilePath.Length > 0) ||
                (a.KeyProvider.Length > 0) || a.UserAccount);
            if(bAtLeastOne)
            {
                if(idx >= 0) m_vKeySources[idx] = a;
                else m_vKeySources.Add(a);
            }
            else if(idx >= 0) m_vKeySources.RemoveAt(idx);
        }
All Usage Examples Of KeePassLib.Keys.CompositeKey::GetUserKey