/// <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);
        }
示例#2
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);
        }