// Returns keyImpl owned by cache, thus KeyHolder is not used public IKeyImpl TryGet(KeyIdentity identity, KeyDisposition disposition, KeySecurity samDesired) { lock (this) { CacheKey cacheKey = new CacheKey { Identity = identity, Disposition = disposition }; if (!cachedKeyImpls_.ContainsKey(cacheKey)) { return(null); } KeyImplHolder cached = cachedKeyImpls_[cacheKey]; if (!samDesired.IsSubSetOf(cached.GetKeyImpl().GetAccessMode())) { return(null); } return(cached.GetKeyImpl()); } }
// If the keyImpl is added, returns NotOwningKeyImplHolder, // otherwise returns original KeyImplHolder public KeyImplHolder Add(KeyIdentity identity, KeyDisposition disposition, KeyImplHolder keyHolder) { lock (this) { CacheKey cacheKey = new CacheKey { Identity = identity, Disposition = disposition }; if (cachedKeyImpls_.ContainsKey(cacheKey)) { return(keyHolder); } cachedKeyImpls_.Add(cacheKey, keyHolder); return(new NotOwningKeyImplHolder(keyHolder.GetKeyImpl())); } }