Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve archboard feedback #18582

Merged
merged 4 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
### Added

- Added default constructor to `CertificatePolicy` to use when importing a PEM-encoded certificate ([#16217](https://github.com/Azure/azure-sdk-for-net/issues/16217)).
- Added constructor to `KeyVaultCertificateIdentifier` to parse a `Uri`.

### Removed

- Removed `KeyVaultCertificateIdentifier.Parse` and `KeyVaultCertificateIdentifier.TryParse` in favor of the added constructor.

## 4.2.0-beta.3 (2020-11-12)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,18 @@ internal KeyVaultCertificate() { }
public System.Uri SecretId { get { throw null; } }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public readonly partial struct KeyVaultCertificateIdentifier
public readonly partial struct KeyVaultCertificateIdentifier : System.IEquatable<Azure.Security.KeyVault.Certificates.KeyVaultCertificateIdentifier>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public KeyVaultCertificateIdentifier(System.Uri id) { throw null; }
public string Name { get { throw null; } }
public System.Uri SourceId { get { throw null; } }
public System.Uri VaultUri { get { throw null; } }
public string Version { get { throw null; } }
public static Azure.Security.KeyVault.Certificates.KeyVaultCertificateIdentifier Parse(System.Uri id) { throw null; }
public static bool TryParse(System.Uri id, out Azure.Security.KeyVault.Certificates.KeyVaultCertificateIdentifier certificateId) { throw null; }
public bool Equals(Azure.Security.KeyVault.Certificates.KeyVaultCertificateIdentifier other) { throw null; }
public override bool Equals(object obj) { throw null; }
public override int GetHashCode() { throw null; }
}
public partial class KeyVaultCertificateWithPolicy : Azure.Security.KeyVault.Certificates.KeyVaultCertificate
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,41 @@
// Licensed under the MIT License.

using System;
using Azure.Core;

namespace Azure.Security.KeyVault.Certificates
{
/// <summary>
/// Information about a <see cref="KeyVaultCertificate"/> parsed from a <see cref="Uri"/>.
/// You can use this information when calling methods of a <see cref="CertificateClient"/>.
/// </summary>
public readonly struct KeyVaultCertificateIdentifier
public readonly struct KeyVaultCertificateIdentifier : IEquatable<KeyVaultCertificateIdentifier>
{
private KeyVaultCertificateIdentifier(Uri sourceId, Uri vaultUri, string name, string version)
/// <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)
{
SourceId = sourceId;
VaultUri = vaultUri;
Name = name;
Version = version;
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>
/// Gets the source <see cref="Uri"/> passed to <see cref="Parse(Uri)"/> or <see cref="TryParse(Uri, out KeyVaultCertificateIdentifier)"/>.
/// Gets the source <see cref="Uri"/> passed to <see cref="KeyVaultCertificateIdentifier(Uri)"/>.
/// </summary>
public Uri SourceId { get; }

Expand All @@ -39,43 +55,16 @@ private KeyVaultCertificateIdentifier(Uri sourceId, Uri vaultUri, string name, s
/// </summary>
public string Version { get; }

/// <summary>
/// Parses 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>
/// <returns>A <see cref="KeyVaultCertificateIdentifier"/> containing information about the certificate or deleted certificate.</returns>
/// <exception cref="ArgumentException">The <paramref name="id"/> is not a valid Key Vault certificate ID.</exception>
public static KeyVaultCertificateIdentifier Parse(Uri id)
{
if (TryParse(id, out KeyVaultCertificateIdentifier certificateId))
{
return certificateId;
}

throw new ArgumentException($"{id} is not a valid Key Vault certificate ID", nameof(id));
}
/// <inheritdoc/>
public override bool Equals(object obj) =>
obj is KeyVaultCertificateIdentifier other && Equals(other);

/// <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);
/// <inheritdoc/>
public bool Equals(KeyVaultCertificateIdentifier other) =>
SourceId.Equals(other.SourceId);

return true;
}

certificateId = default;
return false;
}
/// <inheritdoc/>
public override int GetHashCode() =>
SourceId.GetHashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ namespace Azure.Security.KeyVault.Certificates.Tests
{
public class KeyVaultCertificateIdentifierTests
{
[Test]
public void KeyVaultCertificateIdentifierNullThrows()
{
ArgumentException ex = Assert.Throws<ArgumentNullException>(() => new KeyVaultCertificateIdentifier(null));
Assert.AreEqual("id", ex.ParamName);
}

[TestCaseSource(nameof(Data))]
public bool Parse(Uri id, Uri vaultUri, string name, string version)
{
try
{
KeyVaultCertificateIdentifier identifier = KeyVaultCertificateIdentifier.Parse(id);
KeyVaultCertificateIdentifier identifier = new KeyVaultCertificateIdentifier(id);

Assert.AreEqual(id, identifier.SourceId);
Assert.AreEqual(vaultUri, identifier.VaultUri);
Expand All @@ -29,25 +36,35 @@ public bool Parse(Uri id, Uri vaultUri, string name, string version)
}
}

[TestCaseSource(nameof(Data))]
public bool TryParse(Uri id, Uri vaultUri, string name, string version)
[Test]
public void Equals()
{
if (KeyVaultCertificateIdentifier.TryParse(id, out KeyVaultCertificateIdentifier identifier))
{
Assert.AreEqual(id, identifier.SourceId);
Assert.AreEqual(vaultUri, identifier.VaultUri);
Assert.AreEqual(name, identifier.Name);
Assert.AreEqual(version, identifier.Version);
KeyVaultCertificateIdentifier a = new KeyVaultCertificateIdentifier(new Uri("https://test.vault.azure.net/deletedcertificates/test-name/test-version"));
KeyVaultCertificateIdentifier b = new KeyVaultCertificateIdentifier(new Uri("https://test.vault.azure.net/deletedcertificates/test-name/test-version"));

return true;
}
Assert.AreEqual(a, b);
}

[Test]
public void NotEquals()
{
KeyVaultCertificateIdentifier a = new KeyVaultCertificateIdentifier(new Uri("https://test.vault.azure.net/deletedcertificates/test-name/test-version?api-version=7.0"));
KeyVaultCertificateIdentifier b = new KeyVaultCertificateIdentifier(new Uri("https://test.vault.azure.net/deletedcertificates/test-name/test-version?api-version=7.1"));

Assert.AreNotEqual(a, b);
}

[Test]
public void TestGetHashCode()
{
Uri uri = new Uri("https://test.vault.azure.net/keys/test-name/test-version");
KeyVaultCertificateIdentifier keyId = new KeyVaultCertificateIdentifier(uri);

return false;
Assert.AreEqual(uri.GetHashCode(), keyId.GetHashCode());
}

private static IEnumerable<IdentifierTestData> Data => new[]
{
new IdentifierTestData(null).Returns(false),
new IdentifierTestData("https://test.vault.azure.net").Returns(false),
new IdentifierTestData("https://test.vault.azure.net/certificates").Returns(false),
new IdentifierTestData("https://test.vault.azure.net/certificates/test-name", "https://test.vault.azure.net", "test-name").Returns(true),
Expand Down
9 changes: 9 additions & 0 deletions sdk/keyvault/Azure.Security.KeyVault.Keys/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@

- Added `CreateEcKeyOptions` class.
- Added `CreateEcKey` and `CreateEcKeyAsync` methods to the `KeyClient` class.
- Added constructor to `KeyVaultKeyIdentifier` to parse a `Uri`.

### Changed

- Renamed `EncryptOptions` to `EncryptParameters`.
- Renamed `DecryptOptions` to `DecryptParameters`.
- Made `EncryptParameters.AdditionalAuthenticatedData` read-only, requiring it to be passed to the constructor.
- Made `DecryptParameters.AdditionalAuthenticatedData` read-only, requiring it to be passed to the constructor.

### Removed

- Removed local cryptographic support for AES-GCM.
- Removed `Export` and `ExportAsync` methods from `KeyClient`.
- Removed `Exportable` property from `KeyProperties`'.
- Removed `KeyReleasePolicy` class and associated properties.
- Removed `KeyVaultKeyIdentifier.Parse` and `KeyVaultKeyIdentifier.TryParse` in favor of the added constructor.

## 4.2.0-beta.3 (2020-11-12)

Expand Down
Loading