Ejemplo n.º 1
0
        /// <summary>
        /// Provides an IKey implementation for the specified key or secret identifier.
        /// </summary>
        /// <param name="kid">The key or secret identifier to resolve</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>The resolved IKey implementation or null</returns>
        public async Task <IKey> ResolveKeyAsync(string kid, CancellationToken token)
        {
            if (string.IsNullOrWhiteSpace(kid))
            {
                throw new ArgumentNullException("kid");
            }

            // If the resolver has a name prefix, only handle kid that have that prefix.
            if (_name != null)
            {
                var vaultUrl = new Uri(_name);
                var keyUrl   = new Uri(kid);

                if (string.Compare(vaultUrl.Scheme, keyUrl.Scheme, true) != 0 || string.Compare(vaultUrl.Authority, keyUrl.Authority, true) != 0 || vaultUrl.Port != keyUrl.Port)
                {
                    return(null);
                }
            }

            if (KeyIdentifier.IsKeyIdentifier(kid))
            {
                return(await ResolveKeyFromKeyAsync(kid, token).ConfigureAwait(false));
            }

            if (SecretIdentifier.IsSecretIdentifier(kid))
            {
                return(await ResolveKeyFromSecretAsync(kid, token).ConfigureAwait(false));
            }

            // Return null rather than throw an exception here
            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Provides an IKey implementation for the specified key or secret identifier.
        /// </summary>
        /// <param name="kid">The key or secret identifier to resolve</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>The resolved IKey implementation or null</returns>
        public async Task <IKey> ResolveKeyAsync(string kid, CancellationToken token)
        {
            if (string.IsNullOrWhiteSpace(kid))
            {
                throw new ArgumentNullException("kid");
            }

            // If the resolver has a name prefix, only handle kid that have that prefix
            if (!string.IsNullOrEmpty(_name) && !kid.StartsWith(_name, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            if (KeyIdentifier.IsKeyIdentifier(kid))
            {
                return(await ResolveKeyFromKeyAsync(kid, token).ConfigureAwait(false));
            }

            if (SecretIdentifier.IsSecretIdentifier(kid))
            {
                return(await ResolveKeyFromSecretAsync(kid, token).ConfigureAwait(false));
            }

            // Return null rather than throw an exception here
            return(null);
        }