示例#1
0
        internal override void ReadProperty(JsonProperty prop)
        {
            switch (prop.Name)
            {
            case IdPropertyName:
                Key.Id        = prop.Value.GetString();
                Properties.Id = new Uri(Key.Id);
                KeyVaultIdentifier kvid = KeyVaultIdentifier.Parse(Properties.Id);
                Properties.Name     = kvid.Name;
                Properties.VaultUri = kvid.VaultUri;
                Properties.Version  = kvid.Version;
                break;

            case ContentTypePropertyName:
                ContentType = prop.Value.GetString();
                break;

            case ValuePropertyName:
                byte[] keyBytes = Base64Url.Decode(prop.Value.GetString());
                Key.K = keyBytes;
                break;

            default:
                base.ReadProperty(prop);
                break;
            }
        }
示例#2
0
        private async Task <Key> GetKeyAsync(Uri keyId, CancellationToken cancellationToken)
        {
            using Request request = CreateGetRequest(keyId);

            Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

            return(KeyVaultIdentifier.Parse(keyId).Collection == KeyVaultIdentifier.SecretsCollection ? (Key)ParseResponse(response, new SecretKey()) : ParseResponse(response, new Key()));
        }
示例#3
0
        private Key GetKey(Uri keyId, CancellationToken cancellationToken)
        {
            using Request request = CreateGetRequest(keyId);

            Response response = _pipeline.SendRequest(request, cancellationToken);

            return(KeyVaultIdentifier.Parse(keyId).Collection == KeyVaultIdentifier.SecretsCollection ? (Key)ParseResponse(response, new SecretKey()) : ParseResponse(response, new Key()));
        }
        /// <summary>
        /// Tries to create a new instance of the <see cref="KeyVaultCertificateIdentifier"/> from the given <paramref name="id"/>.
        /// </summary>
        /// <param name="id">A <see cref="Uri"/> to a Key Vault certificate with or without a version.</param>
        /// <param name="identifier">A <see cref="KeyVaultCertificateIdentifier"/> from the given <paramref name="id"/> if valid; otherwise, an empty structure if invalid.</param>
        /// <returns>True if the <see cref="Uri"/> contains a <see cref="VaultUri"/>, <see cref="Name"/>, and optional <see cref="Version"/>; otherwise, false.</returns>
        /// <remarks>
        /// Successfully parsing the given <see cref="Uri"/> does not guarantee that the <paramref name="id"/> is a valid Key Vault certificate identifier:
        /// only that it contains the necessary number of path parts that look like a Key Vault certificate identifier. If the <see cref="VaultUri"/> references
        /// a valid Key Vault, the service will return an error if the <see cref="Name"/> and <see cref="Version"/> do not specify a valid certificate.
        /// </remarks>
        public static bool TryCreate(Uri id, out KeyVaultCertificateIdentifier identifier)
        {
            if (KeyVaultIdentifier.TryParse(id, out KeyVaultIdentifier value))
            {
                identifier = new KeyVaultCertificateIdentifier(value.Id, value.VaultUri, value.Name, value.Version);
                return(true);
            }

            identifier = default;
            return(false);
        }
示例#5
0
        /// <summary>
        /// Creates a new instance of the <see cref="KeyVaultCertificateIdentifier"/> class.
        /// </summary>
        /// <param name="id">The <see cref="Uri"/> to a certificate or deleted certificate.</param>
        /// <exception cref="ArgumentException"><paramref name="id"/> is not a valid Key Vault certificate ID.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> is null.</exception>
        public KeyVaultCertificateIdentifier(Uri id)
        {
            Argument.AssertNotNull(id, nameof(id));

            if (KeyVaultIdentifier.TryParse(id, out KeyVaultIdentifier identifier))
            {
                SourceId = id;
                VaultUri = identifier.VaultUri;
                Name     = identifier.Name;
                Version  = identifier.Version;
            }
            else
            {
                throw new ArgumentException($"{id} is not a valid Key Vault certificate ID", nameof(id));
            }
        }
        /// <summary>
        /// Tries to parse a <see cref="Uri"/> to a certificate or deleted certificate.
        /// </summary>
        /// <param name="id">The <see cref="Uri"/> to a certificate or deleted certificate.</param>
        /// <param name="certificateId">A <see cref="KeyVaultCertificateIdentifier"/> containing information about the certificate or deleted certificate.</param>
        /// <returns>True if the <paramref name="id"/> could be parsed successfully; otherwise, false.</returns>
        public static bool TryParse(Uri id, out KeyVaultCertificateIdentifier certificateId)
        {
            if (KeyVaultIdentifier.TryParse(id, out KeyVaultIdentifier identifier))
            {
                certificateId = new KeyVaultCertificateIdentifier(
                    id,
                    identifier.VaultUri,
                    identifier.Name,
                    identifier.Version);

                return(true);
            }

            certificateId = default;
            return(false);
        }