From cb9e1302021c5afca938de2dd961ae2d644d9e96 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Tue, 9 Feb 2021 12:27:03 -0800 Subject: [PATCH] Resolve archboard feedback (#18582) * Rename Encrypt/DecryptOptions to Encrypt/DecryptParameters * Make AdditionalAuthenticatedData read-only * Change parsing of Key Vault identifiers and implement IEquatable --- .../CHANGELOG.md | 5 + ...ty.KeyVault.Certificates.netstandard2.0.cs | 8 +- .../src/KeyVaultCertificateIdentifier.cs | 75 +++++------- .../KeyVaultCertificateIdentifierTests.cs | 43 ++++--- .../Azure.Security.KeyVault.Keys/CHANGELOG.md | 9 ++ ...e.Security.KeyVault.Keys.netstandard2.0.cs | 88 +++++++------- .../Cryptography/AesCryptographyProvider.cs | 24 ++-- .../src/Cryptography/CryptographyClient.cs | 56 ++++----- .../Cryptography/CryptographyModelFactory.cs | 39 ++++--- ...DecryptOptions.cs => DecryptParameters.cs} | 110 +++++++++--------- ...EncryptOptions.cs => EncryptParameters.cs} | 108 ++++++++--------- .../src/Cryptography/ICryptographyProvider.cs | 8 +- .../Cryptography/LocalCryptographyClient.cs | 48 ++++---- .../Cryptography/LocalCryptographyProvider.cs | 12 +- .../Cryptography/RemoteCryptographyClient.cs | 36 +++--- .../Cryptography/RsaCryptographyProvider.cs | 16 +-- .../src/KeyVaultKeyIdentifier.cs | 75 +++++------- .../tests/AesCryptographyProviderTests.cs | 20 ++-- .../tests/CryptographyModelFactoryTests.cs | 14 +-- ...ionsTests.cs => DecryptParametersTests.cs} | 56 ++++----- ...ionsTests.cs => EncryptParametersTests.cs} | 60 +++++----- .../tests/KeyVaultKeyIdentifierTests.cs | 43 ++++--- .../tests/RsaCryptographyProviderTests.cs | 4 +- .../tests/ThrowingCryptographyProvider.cs | 8 +- .../CHANGELOG.md | 7 ++ ...ecurity.KeyVault.Secrets.netstandard2.0.cs | 8 +- .../src/KeyVaultSecretIdentifier.cs | 75 +++++------- .../tests/KeyVaultSecretIdentifierTests.cs | 43 ++++--- 28 files changed, 573 insertions(+), 525 deletions(-) rename sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/{DecryptOptions.cs => DecryptParameters.cs} (52%) rename sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/{EncryptOptions.cs => EncryptParameters.cs} (52%) rename sdk/keyvault/Azure.Security.KeyVault.Keys/tests/{DecryptOptionsTests.cs => DecryptParametersTests.cs} (63%) rename sdk/keyvault/Azure.Security.KeyVault.Keys/tests/{EncryptOptionsTests.cs => EncryptParametersTests.cs} (52%) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/CHANGELOG.md b/sdk/keyvault/Azure.Security.KeyVault.Certificates/CHANGELOG.md index 951effc6dc78..7ee432c12ae2 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/CHANGELOG.md +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/CHANGELOG.md @@ -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) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/api/Azure.Security.KeyVault.Certificates.netstandard2.0.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/api/Azure.Security.KeyVault.Certificates.netstandard2.0.cs index fd17ec630e38..4f5383b497ba 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/api/Azure.Security.KeyVault.Certificates.netstandard2.0.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/api/Azure.Security.KeyVault.Certificates.netstandard2.0.cs @@ -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 { 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 { diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/KeyVaultCertificateIdentifier.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/KeyVaultCertificateIdentifier.cs index a8d82ae7196e..fe19e756a42a 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/KeyVaultCertificateIdentifier.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/src/KeyVaultCertificateIdentifier.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using Azure.Core; namespace Azure.Security.KeyVault.Certificates { @@ -9,18 +10,33 @@ namespace Azure.Security.KeyVault.Certificates /// Information about a parsed from a . /// You can use this information when calling methods of a . /// - public readonly struct KeyVaultCertificateIdentifier + public readonly struct KeyVaultCertificateIdentifier : IEquatable { - private KeyVaultCertificateIdentifier(Uri sourceId, Uri vaultUri, string name, string version) + /// + /// Creates a new instance of the class. + /// + /// The to a certificate or deleted certificate. + /// is not a valid Key Vault certificate ID. + /// is null. + 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)); + } } /// - /// Gets the source passed to or . + /// Gets the source passed to . /// public Uri SourceId { get; } @@ -39,43 +55,16 @@ private KeyVaultCertificateIdentifier(Uri sourceId, Uri vaultUri, string name, s /// public string Version { get; } - /// - /// Parses a to a certificate or deleted certificate. - /// - /// The to a certificate or deleted certificate. - /// A containing information about the certificate or deleted certificate. - /// The is not a valid Key Vault certificate ID. - 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)); - } + /// + public override bool Equals(object obj) => + obj is KeyVaultCertificateIdentifier other && Equals(other); - /// - /// Tries to parse a to a certificate or deleted certificate. - /// - /// The to a certificate or deleted certificate. - /// A containing information about the certificate or deleted certificate. - /// True if the could be parsed successfully; otherwise, false. - 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); + /// + public bool Equals(KeyVaultCertificateIdentifier other) => + SourceId.Equals(other.SourceId); - return true; - } - - certificateId = default; - return false; - } + /// + public override int GetHashCode() => + SourceId.GetHashCode(); } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/KeyVaultCertificateIdentifierTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/KeyVaultCertificateIdentifierTests.cs index faf311abd12a..7f77b6691b52 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/KeyVaultCertificateIdentifierTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Certificates/tests/KeyVaultCertificateIdentifierTests.cs @@ -9,12 +9,19 @@ namespace Azure.Security.KeyVault.Certificates.Tests { public class KeyVaultCertificateIdentifierTests { + [Test] + public void KeyVaultCertificateIdentifierNullThrows() + { + ArgumentException ex = Assert.Throws(() => 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); @@ -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 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), diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/CHANGELOG.md b/sdk/keyvault/Azure.Security.KeyVault.Keys/CHANGELOG.md index 63762c6a1531..871dfeee3d4f 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/CHANGELOG.md +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/CHANGELOG.md @@ -6,6 +6,14 @@ - 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 @@ -13,6 +21,7 @@ - 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) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/api/Azure.Security.KeyVault.Keys.netstandard2.0.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/api/Azure.Security.KeyVault.Keys.netstandard2.0.cs index 8c459182f1ae..77d2a6579660 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/api/Azure.Security.KeyVault.Keys.netstandard2.0.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/api/Azure.Security.KeyVault.Keys.netstandard2.0.cs @@ -36,9 +36,9 @@ public CreateRsaKeyOptions(string name, bool hardwareProtected = false) { } } public static partial class CryptographyModelFactory { - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions DecryptOptions(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv = null, byte[] authenticationTag = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters DecryptParameters(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv = null, byte[] authenticationTag = null, byte[] additionalAuthenticatedData = null) { throw null; } public static Azure.Security.KeyVault.Keys.Cryptography.DecryptResult DecryptResult(string keyId = null, byte[] plaintext = null, Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm = default(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm)) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions EncryptOptions(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters EncryptParameters(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv = null, byte[] additionalAuthenticatedData = null) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Security.KeyVault.Keys.Cryptography.EncryptResult EncryptResult(string keyId, byte[] ciphertext, Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm) { throw null; } public static Azure.Security.KeyVault.Keys.Cryptography.EncryptResult EncryptResult(string keyId = null, byte[] ciphertext = null, Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm = default(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm), byte[] iv = null, byte[] authenticatedTag = null, byte[] additionalAuthenticatedData = null) { throw null; } @@ -256,16 +256,18 @@ public KeyVaultKey(string name) { } public Azure.Security.KeyVault.Keys.KeyProperties Properties { get { throw null; } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct KeyVaultKeyIdentifier + public readonly partial struct KeyVaultKeyIdentifier : System.IEquatable { private readonly object _dummy; private readonly int _dummyPrimitive; + public KeyVaultKeyIdentifier(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.Keys.KeyVaultKeyIdentifier Parse(System.Uri id) { throw null; } - public static bool TryParse(System.Uri id, out Azure.Security.KeyVault.Keys.KeyVaultKeyIdentifier keyId) { throw null; } + public bool Equals(Azure.Security.KeyVault.Keys.KeyVaultKeyIdentifier other) { throw null; } + public override bool Equals(object obj) { throw null; } + public override int GetHashCode() { throw null; } } public partial class RecoverDeletedKeyOperation : Azure.Operation { @@ -293,14 +295,14 @@ public CryptographyClient(System.Uri keyId, Azure.Core.TokenCredential credentia System.Threading.Tasks.Task Azure.Core.Cryptography.IKeyEncryptionKey.UnwrapKeyAsync(string algorithm, System.ReadOnlyMemory encryptedKey, System.Threading.CancellationToken cancellationToken) { throw null; } byte[] Azure.Core.Cryptography.IKeyEncryptionKey.WrapKey(string algorithm, System.ReadOnlyMemory key, System.Threading.CancellationToken cancellationToken) { throw null; } System.Threading.Tasks.Task Azure.Core.Cryptography.IKeyEncryptionKey.WrapKeyAsync(string algorithm, System.ReadOnlyMemory key, System.Threading.CancellationToken cancellationToken) { throw null; } - public virtual Azure.Security.KeyVault.Keys.Cryptography.DecryptResult Decrypt(Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Security.KeyVault.Keys.Cryptography.DecryptResult Decrypt(Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.DecryptResult Decrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] ciphertext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task DecryptAsync(Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DecryptAsync(Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DecryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] ciphertext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.EncryptResult Encrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Security.KeyVault.Keys.Cryptography.EncryptResult Encrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Security.KeyVault.Keys.Cryptography.EncryptResult Encrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task EncryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task EncryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task EncryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.SignResult Sign(Azure.Security.KeyVault.Keys.Cryptography.SignatureAlgorithm algorithm, byte[] digest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task SignAsync(Azure.Security.KeyVault.Keys.Cryptography.SignatureAlgorithm algorithm, byte[] digest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.SignResult SignData(Azure.Security.KeyVault.Keys.Cryptography.SignatureAlgorithm algorithm, byte[] data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } @@ -329,26 +331,26 @@ public enum ServiceVersion V7_2 = 2, } } - public partial class DecryptOptions + public partial class DecryptParameters { - internal DecryptOptions() { } - public byte[] AdditionalAuthenticatedData { get { throw null; } set { } } + internal DecryptParameters() { } + public byte[] AdditionalAuthenticatedData { get { throw null; } } public Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm Algorithm { get { throw null; } } public byte[] AuthenticationTag { get { throw null; } } public byte[] Ciphertext { get { throw null; } } public byte[] Iv { get { throw null; } } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A128CbcOptions(byte[] ciphertext, byte[] iv) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A128CbcPadOptions(byte[] ciphertext, byte[] iv) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A128GcmOptions(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A192CbcOptions(byte[] ciphertext, byte[] iv) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A192CbcPadOptions(byte[] ciphertext, byte[] iv) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A192GcmOptions(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A256CbcOptions(byte[] ciphertext, byte[] iv) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A256CbcPadOptions(byte[] ciphertext, byte[] iv) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions A256GcmOptions(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions Rsa15Options(byte[] ciphertext) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions RsaOaep256Options(byte[] ciphertext) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions RsaOaepOptions(byte[] ciphertext) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A128CbcPadParameters(byte[] ciphertext, byte[] iv) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A128CbcParameters(byte[] ciphertext, byte[] iv) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A128GcmParameters(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A192CbcPadParameters(byte[] ciphertext, byte[] iv) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A192CbcParameters(byte[] ciphertext, byte[] iv) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A192GcmParameters(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A256CbcPadParameters(byte[] ciphertext, byte[] iv) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A256CbcParameters(byte[] ciphertext, byte[] iv) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters A256GcmParameters(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters Rsa15Parameters(byte[] ciphertext) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters RsaOaep256Parameters(byte[] ciphertext) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters RsaOaepParameters(byte[] ciphertext) { throw null; } } public partial class DecryptResult { @@ -385,25 +387,25 @@ internal DecryptResult() { } public static bool operator !=(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm left, Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm right) { throw null; } public override string ToString() { throw null; } } - public partial class EncryptOptions + public partial class EncryptParameters { - internal EncryptOptions() { } - public byte[] AdditionalAuthenticatedData { get { throw null; } set { } } + internal EncryptParameters() { } + public byte[] AdditionalAuthenticatedData { get { throw null; } } public Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm Algorithm { get { throw null; } } public byte[] Iv { get { throw null; } } public byte[] Plaintext { get { throw null; } } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A128CbcOptions(byte[] plaintext, byte[] iv = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A128CbcPadOptions(byte[] plaintext, byte[] iv = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A128GcmOptions(byte[] plaintext, byte[] additionalAuthenticationData = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A192CbcOptions(byte[] plaintext, byte[] iv = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A192CbcPadOptions(byte[] plaintext, byte[] iv = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A192GcmOptions(byte[] plaintext, byte[] additionalAuthenticationData = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A256CbcOptions(byte[] plaintext, byte[] iv = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A256CbcPadOptions(byte[] plaintext, byte[] iv = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions A256GcmOptions(byte[] plaintext, byte[] additionalAuthenticationData = null) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions Rsa15Options(byte[] plaintext) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions RsaOaep256Options(byte[] plaintext) { throw null; } - public static Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions RsaOaepOptions(byte[] plaintext) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A128CbcPadParameters(byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A128CbcParameters(byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A128GcmParameters(byte[] plaintext, byte[] additionalAuthenticationData = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A192CbcPadParameters(byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A192CbcParameters(byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A192GcmParameters(byte[] plaintext, byte[] additionalAuthenticationData = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A256CbcPadParameters(byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A256CbcParameters(byte[] plaintext, byte[] iv = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters A256GcmParameters(byte[] plaintext, byte[] additionalAuthenticationData = null) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters Rsa15Parameters(byte[] plaintext) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters RsaOaep256Parameters(byte[] plaintext) { throw null; } + public static Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters RsaOaepParameters(byte[] plaintext) { throw null; } } public partial class EncryptResult { @@ -458,14 +460,14 @@ public LocalCryptographyClient(Azure.Security.KeyVault.Keys.JsonWebKey jsonWebKe System.Threading.Tasks.Task Azure.Core.Cryptography.IKeyEncryptionKey.UnwrapKeyAsync(string algorithm, System.ReadOnlyMemory encryptedKey, System.Threading.CancellationToken cancellationToken) { throw null; } byte[] Azure.Core.Cryptography.IKeyEncryptionKey.WrapKey(string algorithm, System.ReadOnlyMemory key, System.Threading.CancellationToken cancellationToken) { throw null; } System.Threading.Tasks.Task Azure.Core.Cryptography.IKeyEncryptionKey.WrapKeyAsync(string algorithm, System.ReadOnlyMemory key, System.Threading.CancellationToken cancellationToken) { throw null; } - public virtual Azure.Security.KeyVault.Keys.Cryptography.DecryptResult Decrypt(Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Security.KeyVault.Keys.Cryptography.DecryptResult Decrypt(Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.DecryptResult Decrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] ciphertext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task DecryptAsync(Azure.Security.KeyVault.Keys.Cryptography.DecryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DecryptAsync(Azure.Security.KeyVault.Keys.Cryptography.DecryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task DecryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] ciphertext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.EncryptResult Encrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual Azure.Security.KeyVault.Keys.Cryptography.EncryptResult Encrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Security.KeyVault.Keys.Cryptography.EncryptResult Encrypt(Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task EncryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm algorithm, byte[] plaintext, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - public virtual System.Threading.Tasks.Task EncryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task EncryptAsync(Azure.Security.KeyVault.Keys.Cryptography.EncryptParameters parameters, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.SignResult Sign(Azure.Security.KeyVault.Keys.Cryptography.SignatureAlgorithm algorithm, byte[] digest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task SignAsync(Azure.Security.KeyVault.Keys.Cryptography.SignatureAlgorithm algorithm, byte[] digest, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Security.KeyVault.Keys.Cryptography.SignResult SignData(Azure.Security.KeyVault.Keys.Cryptography.SignatureAlgorithm algorithm, byte[] data, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/AesCryptographyProvider.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/AesCryptographyProvider.cs index 95bc264a7d22..be162a71cf27 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/AesCryptographyProvider.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/AesCryptographyProvider.cs @@ -27,18 +27,18 @@ public override bool SupportsOperation(KeyOperation operation) return false; } - public override DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken = default) + public override DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); ThrowIfTimeInvalid(); - EncryptionAlgorithm algorithm = options.Algorithm; + EncryptionAlgorithm algorithm = parameters.Algorithm; if (algorithm.GetAesCbcEncryptionAlgorithm() is AesCbc aesCbc) { - using ICryptoTransform decryptor = aesCbc.CreateDecryptor(KeyMaterial.K, options.Iv); + using ICryptoTransform decryptor = aesCbc.CreateDecryptor(KeyMaterial.K, parameters.Iv); - byte[] ciphertext = options.Ciphertext; + byte[] ciphertext = parameters.Ciphertext; byte[] plaintext = decryptor.TransformFinalBlock(ciphertext, 0, ciphertext.Length); return new DecryptResult @@ -55,21 +55,21 @@ public override DecryptResult Decrypt(DecryptOptions options, CancellationToken } } - public override EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken = default) + public override EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); ThrowIfTimeInvalid(); - EncryptionAlgorithm algorithm = options.Algorithm; + EncryptionAlgorithm algorithm = parameters.Algorithm; if (algorithm.GetAesCbcEncryptionAlgorithm() is AesCbc aesCbc) { // Make sure the IV is initialized. - options.Initialize(); + parameters.Initialize(); - using ICryptoTransform encryptor = aesCbc.CreateEncryptor(KeyMaterial.K, options.Iv); + using ICryptoTransform encryptor = aesCbc.CreateEncryptor(KeyMaterial.K, parameters.Iv); - byte[] plaintext = options.Plaintext; + byte[] plaintext = parameters.Plaintext; byte[] ciphertext = encryptor.TransformFinalBlock(plaintext, 0, plaintext.Length); return new EncryptResult @@ -77,7 +77,7 @@ public override EncryptResult Encrypt(EncryptOptions options, CancellationToken Algorithm = algorithm, KeyId = KeyMaterial.Id, Ciphertext = ciphertext, - Iv = options.Iv, + Iv = parameters.Iv, }; } else diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyClient.cs index a7894c2e14c7..710145046fb3 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyClient.cs @@ -153,7 +153,7 @@ internal CryptographyClient(Uri keyId, KeyVaultPipeline pipeline) /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual async Task EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default) => - await EncryptAsync(new EncryptOptions(algorithm, plaintext), cancellationToken).ConfigureAwait(false); + await EncryptAsync(new EncryptParameters(algorithm, plaintext), cancellationToken).ConfigureAwait(false); /// /// Encrypts the specified plaintext. @@ -170,25 +170,25 @@ public virtual async Task EncryptAsync(EncryptionAlgorithm algori /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default) => - Encrypt(new EncryptOptions(algorithm, plaintext), cancellationToken); + Encrypt(new EncryptParameters(algorithm, plaintext), cancellationToken); /// /// Encrypts plaintext. /// - /// An containing the data to encrypt and other options for algorithm-dependent encryption. + /// An containing the data to encrypt and other parameters for algorithm-dependent encryption. /// A to cancel the operation. /// /// An containing the encrypted data /// along with all other information needed to decrypt it. This information should be stored with the encrypted data. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual async Task EncryptAsync(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual async Task EncryptAsync(EncryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(CryptographyClient)}.{nameof(Encrypt)}"); scope.AddAttribute("key", _keyId); @@ -206,7 +206,7 @@ public virtual async Task EncryptAsync(EncryptOptions options, Ca { try { - result = await _provider.EncryptAsync(options, cancellationToken).ConfigureAwait(false); + result = await _provider.EncryptAsync(parameters, cancellationToken).ConfigureAwait(false); } catch (CryptographicException ex) when (_provider.ShouldRemote) { @@ -217,7 +217,7 @@ public virtual async Task EncryptAsync(EncryptOptions options, Ca if (result is null) { - result = await _remoteProvider.EncryptAsync(options, cancellationToken).ConfigureAwait(false); + result = await _remoteProvider.EncryptAsync(parameters, cancellationToken).ConfigureAwait(false); } return result; @@ -232,20 +232,20 @@ public virtual async Task EncryptAsync(EncryptOptions options, Ca /// /// Encrypts plaintext. /// - /// An containing the data to encrypt and other options for algorithm-dependent encryption. + /// An containing the data to encrypt and other parameters for algorithm-dependent encryption. /// A to cancel the operation. /// /// An containing the encrypted data /// along with all other information needed to decrypt it. This information should be stored with the encrypted data. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(CryptographyClient)}.{nameof(Encrypt)}"); scope.AddAttribute("key", _keyId); @@ -263,7 +263,7 @@ public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken c { try { - result = _provider.Encrypt(options, cancellationToken); + result = _provider.Encrypt(parameters, cancellationToken); } catch (CryptographicException ex) when (_provider.ShouldRemote) { @@ -273,7 +273,7 @@ public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken c if (result is null) { - result = _remoteProvider.Encrypt(options, cancellationToken); + result = _remoteProvider.Encrypt(parameters, cancellationToken); } return result; @@ -300,7 +300,7 @@ public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken c /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual async Task DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default) => - await DecryptAsync(new DecryptOptions(algorithm, ciphertext), cancellationToken).ConfigureAwait(false); + await DecryptAsync(new DecryptParameters(algorithm, ciphertext), cancellationToken).ConfigureAwait(false); /// /// Decrypts ciphertext. @@ -317,25 +317,25 @@ public virtual async Task DecryptAsync(EncryptionAlgorithm algori /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual DecryptResult Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default) => - Decrypt(new DecryptOptions(algorithm, ciphertext), cancellationToken); + Decrypt(new DecryptParameters(algorithm, ciphertext), cancellationToken); /// /// Decrypts ciphertext. /// - /// A containing the data to decrypt and other options for algorithm-dependent decryption. + /// A containing the data to decrypt and other parameters for algorithm-dependent decryption. /// A to cancel the operation. /// /// The result of the decrypt operation. The returned contains the encrypted data /// along with information regarding the algorithm and key used to decrypt it. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual async Task DecryptAsync(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual async Task DecryptAsync(DecryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(CryptographyClient)}.{nameof(Decrypt)}"); scope.AddAttribute("key", _keyId); @@ -353,7 +353,7 @@ public virtual async Task DecryptAsync(DecryptOptions options, Ca { try { - result = await _provider.DecryptAsync(options, cancellationToken).ConfigureAwait(false); + result = await _provider.DecryptAsync(parameters, cancellationToken).ConfigureAwait(false); } catch (CryptographicException ex) when (_provider.ShouldRemote) { @@ -364,7 +364,7 @@ public virtual async Task DecryptAsync(DecryptOptions options, Ca if (result is null) { - result = await _remoteProvider.DecryptAsync(options, cancellationToken).ConfigureAwait(false); + result = await _remoteProvider.DecryptAsync(parameters, cancellationToken).ConfigureAwait(false); } return result; @@ -379,20 +379,20 @@ public virtual async Task DecryptAsync(DecryptOptions options, Ca /// /// Decrypts the specified ciphertext. /// - /// A containing the data to decrypt and other options for algorithm-dependent decryption. + /// A containing the data to decrypt and other parameters for algorithm-dependent decryption. /// A to cancel the operation. /// /// The result of the decrypt operation. The returned contains the encrypted data /// along with information regarding the algorithm and key used to decrypt it. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); using DiagnosticScope scope = _pipeline.CreateScope($"{nameof(CryptographyClient)}.{nameof(Decrypt)}"); scope.AddAttribute("key", _keyId); @@ -410,7 +410,7 @@ public virtual DecryptResult Decrypt(DecryptOptions options, CancellationToken c { try { - result = _provider.Decrypt(options, cancellationToken); + result = _provider.Decrypt(parameters, cancellationToken); } catch (CryptographicException ex) when (_provider.ShouldRemote) { @@ -420,7 +420,7 @@ public virtual DecryptResult Decrypt(DecryptOptions options, CancellationToken c if (result is null) { - result = _remoteProvider.Decrypt(options, cancellationToken); + result = _remoteProvider.Decrypt(parameters, cancellationToken); } return result; diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyModelFactory.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyModelFactory.cs index cde9057c9e08..984d9807e14a 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyModelFactory.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/CryptographyModelFactory.cs @@ -13,19 +13,22 @@ namespace Azure.Security.KeyVault.Keys public static class CryptographyModelFactory { /// - /// Initializes a new instance of the class for mocking purposes. + /// Initializes a new instance of the class for mocking purposes. /// - /// Sets the property. - /// Sets the property. - /// Sets the property. - /// Sets the property. - /// A new instance of the class for mocking purposes. + /// Sets the property. + /// Sets the property. + /// Sets the property. + /// Sets the property. + /// Sets the property. + /// A new instance of the class for mocking purposes. /// is null. - public static DecryptOptions DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv = default, byte[] authenticationTag = default) => new DecryptOptions(algorithm, ciphertext) - { - Iv = iv, - AuthenticationTag = authenticationTag, - }; + public static DecryptParameters DecryptParameters(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv = default, byte[] authenticationTag = default, byte[] additionalAuthenticatedData = default) => + new DecryptParameters(algorithm, ciphertext) + { + Iv = iv, + AuthenticationTag = authenticationTag, + AdditionalAuthenticatedData = additionalAuthenticatedData, + }; /// /// Initializes a new instance of the class for mocking purposes. @@ -42,14 +45,16 @@ public static class CryptographyModelFactory }; /// - /// Initializes a new instance of the class for mocking purposes. + /// Initializes a new instance of the class for mocking purposes. /// - /// Sets the property. - /// Sets the property. - /// Sets the property. - /// A new instance of the class for mocking purposes. + /// Sets the property. + /// Sets the property. + /// Sets the property. + /// Sets the property. + /// A new instance of the class for mocking purposes. /// is null. - public static EncryptOptions EncryptOptions(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv = default) => new EncryptOptions(algorithm, plaintext, iv, null); + public static EncryptParameters EncryptParameters(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv = default, byte[] additionalAuthenticatedData = default) => + new EncryptParameters(algorithm, plaintext, iv, additionalAuthenticatedData); /// /// Initializes a new instance of the class for mocking purposes. diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/DecryptOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/DecryptParameters.cs similarity index 52% rename from sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/DecryptOptions.cs rename to sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/DecryptParameters.cs index 9ecdb3da8533..d6d77fc2c839 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/DecryptOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/DecryptParameters.cs @@ -8,134 +8,134 @@ namespace Azure.Security.KeyVault.Keys.Cryptography { /// - /// Options for decrypting ciphertext. + /// Parameters for decrypting ciphertext. /// - public class DecryptOptions : IJsonSerializable + public class DecryptParameters : IJsonSerializable { /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static DecryptOptions Rsa15Options(byte[] ciphertext) => - new DecryptOptions(EncryptionAlgorithm.Rsa15, ciphertext); + public static DecryptParameters Rsa15Parameters(byte[] ciphertext) => + new DecryptParameters(EncryptionAlgorithm.Rsa15, ciphertext); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static DecryptOptions RsaOaepOptions(byte[] ciphertext) => - new DecryptOptions(EncryptionAlgorithm.RsaOaep, ciphertext); + public static DecryptParameters RsaOaepParameters(byte[] ciphertext) => + new DecryptParameters(EncryptionAlgorithm.RsaOaep, ciphertext); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static DecryptOptions RsaOaep256Options(byte[] ciphertext) => - new DecryptOptions(EncryptionAlgorithm.RsaOaep256, ciphertext); + public static DecryptParameters RsaOaep256Parameters(byte[] ciphertext) => + new DecryptParameters(EncryptionAlgorithm.RsaOaep256, ciphertext); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. /// The initialization vector (or nonce) generated during encryption. /// The authentication tag generated during encryption. /// Optional data that is authenticated but not encrypted. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// , , or is null. - public static DecryptOptions A128GcmOptions(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) => - new DecryptOptions(EncryptionAlgorithm.A128Gcm, ciphertext, iv, authenticationTag, additionalAuthenticationData); + public static DecryptParameters A128GcmParameters(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) => + new DecryptParameters(EncryptionAlgorithm.A128Gcm, ciphertext, iv, authenticationTag, additionalAuthenticationData); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. /// The initialization vector (or nonce) generated during encryption. /// The authentication tag generated during encryption. /// Optional data that is authenticated but not encrypted. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// , , or is null. - public static DecryptOptions A192GcmOptions(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) => - new DecryptOptions(EncryptionAlgorithm.A192Gcm, ciphertext, iv, authenticationTag, additionalAuthenticationData); + public static DecryptParameters A192GcmParameters(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) => + new DecryptParameters(EncryptionAlgorithm.A192Gcm, ciphertext, iv, authenticationTag, additionalAuthenticationData); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. /// The initialization vector (or nonce) generated during encryption. /// The authentication tag generated during encryption. /// Optional data that is authenticated but not encrypted. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// , , or is null. - public static DecryptOptions A256GcmOptions(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) => - new DecryptOptions(EncryptionAlgorithm.A256Gcm, ciphertext, iv, authenticationTag, additionalAuthenticationData); + public static DecryptParameters A256GcmParameters(byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticationData = null) => + new DecryptParameters(EncryptionAlgorithm.A256Gcm, ciphertext, iv, authenticationTag, additionalAuthenticationData); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. /// The initialization vector used during encryption. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// or is null. - public static DecryptOptions A128CbcOptions(byte[] ciphertext, byte[] iv) => - new DecryptOptions(EncryptionAlgorithm.A128Cbc, ciphertext, iv); + public static DecryptParameters A128CbcParameters(byte[] ciphertext, byte[] iv) => + new DecryptParameters(EncryptionAlgorithm.A128Cbc, ciphertext, iv); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. /// The initialization vector used during encryption. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// or is null. - public static DecryptOptions A192CbcOptions(byte[] ciphertext, byte[] iv) => - new DecryptOptions(EncryptionAlgorithm.A192Cbc, ciphertext, iv); + public static DecryptParameters A192CbcParameters(byte[] ciphertext, byte[] iv) => + new DecryptParameters(EncryptionAlgorithm.A192Cbc, ciphertext, iv); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The ciphertext to decrypt. /// The initialization vector used during encryption. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// or is null. - public static DecryptOptions A256CbcOptions(byte[] ciphertext, byte[] iv) => - new DecryptOptions(EncryptionAlgorithm.A256Cbc, ciphertext, iv); + public static DecryptParameters A256CbcParameters(byte[] ciphertext, byte[] iv) => + new DecryptParameters(EncryptionAlgorithm.A256Cbc, ciphertext, iv); /// - /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. + /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. /// /// The ciphertext to decrypt. /// The initialization vector used during encryption. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// or is null. - public static DecryptOptions A128CbcPadOptions(byte[] ciphertext, byte[] iv) => - new DecryptOptions(EncryptionAlgorithm.A128CbcPad, ciphertext, iv); + public static DecryptParameters A128CbcPadParameters(byte[] ciphertext, byte[] iv) => + new DecryptParameters(EncryptionAlgorithm.A128CbcPad, ciphertext, iv); /// - /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. + /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. /// /// The ciphertext to decrypt. /// The initialization vector used during encryption. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// or is null. - public static DecryptOptions A192CbcPadOptions(byte[] ciphertext, byte[] iv) => - new DecryptOptions(EncryptionAlgorithm.A192CbcPad, ciphertext, iv); + public static DecryptParameters A192CbcPadParameters(byte[] ciphertext, byte[] iv) => + new DecryptParameters(EncryptionAlgorithm.A192CbcPad, ciphertext, iv); /// - /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. + /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. /// /// The ciphertext to decrypt. /// The initialization vector used during encryption. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// or is null. - public static DecryptOptions A256CbcPadOptions(byte[] ciphertext, byte[] iv) => - new DecryptOptions(EncryptionAlgorithm.A256CbcPad, ciphertext, iv); + public static DecryptParameters A256CbcPadParameters(byte[] ciphertext, byte[] iv) => + new DecryptParameters(EncryptionAlgorithm.A256CbcPad, ciphertext, iv); - internal DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext) + internal DecryptParameters(EncryptionAlgorithm algorithm, byte[] ciphertext) { Argument.AssertNotNull(ciphertext, nameof(ciphertext)); @@ -143,7 +143,7 @@ internal DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext) Ciphertext = ciphertext; } - internal DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv) + internal DecryptParameters(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv) { Argument.AssertNotNull(ciphertext, nameof(ciphertext)); Argument.AssertNotNull(iv, nameof(iv)); @@ -153,7 +153,7 @@ internal DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] Iv = iv; } - internal DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticatedData) + internal DecryptParameters(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] iv, byte[] authenticationTag, byte[] additionalAuthenticatedData) { Argument.AssertNotNull(ciphertext, nameof(ciphertext)); Argument.AssertNotNull(iv, nameof(iv)); @@ -187,9 +187,9 @@ internal DecryptOptions(EncryptionAlgorithm algorithm, byte[] ciphertext, byte[] public byte[] AuthenticationTag { get; internal set; } /// - /// Gets or sets additional data that is authenticated during decryption but not encrypted. + /// Gets additional data that is authenticated during decryption but not encrypted. /// - public byte[] AdditionalAuthenticatedData { get; set; } + public byte[] AdditionalAuthenticatedData { get; internal set; } void IJsonSerializable.WriteProperties(Utf8JsonWriter json) { diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptOptions.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptParameters.cs similarity index 52% rename from sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptOptions.cs rename to sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptParameters.cs index 5e78403ebe02..74884ed1ac00 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptOptions.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/EncryptParameters.cs @@ -9,136 +9,136 @@ namespace Azure.Security.KeyVault.Keys.Cryptography { /// - /// Options for encrypting plaintext. + /// Parameters for encrypting plaintext. /// - public class EncryptOptions : IJsonSerializable + public class EncryptParameters : IJsonSerializable { /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The plaintext to encrypt. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions Rsa15Options(byte[] plaintext) => - new EncryptOptions(EncryptionAlgorithm.Rsa15, plaintext, null, null); + public static EncryptParameters Rsa15Parameters(byte[] plaintext) => + new EncryptParameters(EncryptionAlgorithm.Rsa15, plaintext, null, null); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The plaintext to encrypt. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions RsaOaepOptions(byte[] plaintext) => - new EncryptOptions(EncryptionAlgorithm.RsaOaep, plaintext, null, null); + public static EncryptParameters RsaOaepParameters(byte[] plaintext) => + new EncryptParameters(EncryptionAlgorithm.RsaOaep, plaintext, null, null); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The plaintext to encrypt. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions RsaOaep256Options(byte[] plaintext) => - new EncryptOptions(EncryptionAlgorithm.RsaOaep256, plaintext, null, null); + public static EncryptParameters RsaOaep256Parameters(byte[] plaintext) => + new EncryptParameters(EncryptionAlgorithm.RsaOaep256, plaintext, null, null); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// The nonce will be generated automatically and returned in the after encryption. /// /// The plaintext to encrypt. /// Optional data that is authenticated but not encrypted. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A128GcmOptions(byte[] plaintext, byte[] additionalAuthenticationData = null) => - new EncryptOptions(EncryptionAlgorithm.A128Gcm, plaintext, null, additionalAuthenticationData); + public static EncryptParameters A128GcmParameters(byte[] plaintext, byte[] additionalAuthenticationData = null) => + new EncryptParameters(EncryptionAlgorithm.A128Gcm, plaintext, null, additionalAuthenticationData); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// The nonce will be generated automatically and returned in the after encryption. /// /// The plaintext to encrypt. /// Optional data that is authenticated but not encrypted. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A192GcmOptions(byte[] plaintext, byte[] additionalAuthenticationData = null) => - new EncryptOptions(EncryptionAlgorithm.A192Gcm, plaintext, null, additionalAuthenticationData); + public static EncryptParameters A192GcmParameters(byte[] plaintext, byte[] additionalAuthenticationData = null) => + new EncryptParameters(EncryptionAlgorithm.A192Gcm, plaintext, null, additionalAuthenticationData); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// The nonce will be generated automatically and returned in the after encryption. /// /// The plaintext to encrypt. /// Optional data that is authenticated but not encrypted. - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A256GcmOptions(byte[] plaintext, byte[] additionalAuthenticationData = null) => - new EncryptOptions(EncryptionAlgorithm.A256Gcm, plaintext, null, additionalAuthenticationData); + public static EncryptParameters A256GcmParameters(byte[] plaintext, byte[] additionalAuthenticationData = null) => + new EncryptParameters(EncryptionAlgorithm.A256Gcm, plaintext, null, additionalAuthenticationData); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The plaintext to encrypt. /// Optional initialization vector. If null, a cryptographically random initialization vector will be generated using . - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A128CbcOptions(byte[] plaintext, byte[] iv = null) => - new EncryptOptions(EncryptionAlgorithm.A128Cbc, plaintext, iv, null); + public static EncryptParameters A128CbcParameters(byte[] plaintext, byte[] iv = null) => + new EncryptParameters(EncryptionAlgorithm.A128Cbc, plaintext, iv, null); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The plaintext to encrypt. /// Optional initialization vector. If null, a cryptographically random initialization vector will be generated using . - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A192CbcOptions(byte[] plaintext, byte[] iv = null) => - new EncryptOptions(EncryptionAlgorithm.A192Cbc, plaintext, iv, null); + public static EncryptParameters A192CbcParameters(byte[] plaintext, byte[] iv = null) => + new EncryptParameters(EncryptionAlgorithm.A192Cbc, plaintext, iv, null); /// - /// Creates an instance of the class for the encryption algorithm. + /// Creates an instance of the class for the encryption algorithm. /// /// The plaintext to encrypt. /// Optional initialization vector. If null, a cryptographically random initialization vector will be generated using . - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A256CbcOptions(byte[] plaintext, byte[] iv = null) => - new EncryptOptions(EncryptionAlgorithm.A256Cbc, plaintext, iv, null); + public static EncryptParameters A256CbcParameters(byte[] plaintext, byte[] iv = null) => + new EncryptParameters(EncryptionAlgorithm.A256Cbc, plaintext, iv, null); /// - /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. + /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. /// /// The plaintext to encrypt. /// Optional initialization vector. If null, a cryptographically random initialization vector will be generated using . - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A128CbcPadOptions(byte[] plaintext, byte[] iv = null) => - new EncryptOptions(EncryptionAlgorithm.A128CbcPad, plaintext, iv, null); + public static EncryptParameters A128CbcPadParameters(byte[] plaintext, byte[] iv = null) => + new EncryptParameters(EncryptionAlgorithm.A128CbcPad, plaintext, iv, null); /// - /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. + /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. /// /// The plaintext to encrypt. /// Optional initialization vector. If null, a cryptographically random initialization vector will be generated using . - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A192CbcPadOptions(byte[] plaintext, byte[] iv = null) => - new EncryptOptions(EncryptionAlgorithm.A192CbcPad, plaintext, iv, null); + public static EncryptParameters A192CbcPadParameters(byte[] plaintext, byte[] iv = null) => + new EncryptParameters(EncryptionAlgorithm.A192CbcPad, plaintext, iv, null); /// - /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. + /// Creates an instance of the class for the encryption algorithm with PKCS#7 padding. /// /// The plaintext to encrypt. /// Optional initialization vector. If null, a cryptographically random initialization vector will be generated using . - /// An instance of the class for the encryption algorithm. + /// An instance of the class for the encryption algorithm. /// is null. - public static EncryptOptions A256CbcPadOptions(byte[] plaintext, byte[] iv = null) => - new EncryptOptions(EncryptionAlgorithm.A256CbcPad, plaintext, iv, null); + public static EncryptParameters A256CbcPadParameters(byte[] plaintext, byte[] iv = null) => + new EncryptParameters(EncryptionAlgorithm.A256CbcPad, plaintext, iv, null); - internal EncryptOptions(EncryptionAlgorithm algorithm, byte[] plaintext) : + internal EncryptParameters(EncryptionAlgorithm algorithm, byte[] plaintext) : this(algorithm, plaintext, null, null) { } - internal EncryptOptions(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv, byte[] additionalAuthenticatedData) + internal EncryptParameters(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] iv, byte[] additionalAuthenticatedData) { Argument.AssertNotNull(plaintext, nameof(plaintext)); @@ -164,9 +164,9 @@ internal EncryptOptions(EncryptionAlgorithm algorithm, byte[] plaintext, byte[] public byte[] Iv { get; private set; } /// - /// Gets or sets additional data that is authenticated during decryption but not encrypted. + /// Gets additional data that is authenticated during decryption but not encrypted. /// - public byte[] AdditionalAuthenticatedData { get; set; } + public byte[] AdditionalAuthenticatedData { get; } internal void Initialize() { diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/ICryptographyProvider.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/ICryptographyProvider.cs index 01dacf62205e..b357ddf8a192 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/ICryptographyProvider.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/ICryptographyProvider.cs @@ -12,13 +12,13 @@ internal interface ICryptographyProvider bool SupportsOperation(KeyOperation operation); - Task EncryptAsync(EncryptOptions options, CancellationToken cancellationToken = default); + Task EncryptAsync(EncryptParameters parameters, CancellationToken cancellationToken = default); - EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken = default); + EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken = default); - Task DecryptAsync(DecryptOptions options, CancellationToken cancellationToken = default); + Task DecryptAsync(DecryptParameters parameters, CancellationToken cancellationToken = default); - DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken = default); + DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken = default); Task WrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken = default); diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyClient.cs index b1400bbcf2dc..28d845934299 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyClient.cs @@ -63,7 +63,7 @@ protected LocalCryptographyClient() /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual async Task EncryptAsync(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default) => - await EncryptAsync(new EncryptOptions(algorithm, plaintext), cancellationToken).ConfigureAwait(false); + await EncryptAsync(new EncryptParameters(algorithm, plaintext), cancellationToken).ConfigureAwait(false); /// /// Encrypts the specified plaintext. @@ -80,30 +80,30 @@ public virtual async Task EncryptAsync(EncryptionAlgorithm algori /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual EncryptResult Encrypt(EncryptionAlgorithm algorithm, byte[] plaintext, CancellationToken cancellationToken = default) => - Encrypt(new EncryptOptions(algorithm, plaintext), cancellationToken); + Encrypt(new EncryptParameters(algorithm, plaintext), cancellationToken); /// /// Encrypts plaintext. /// - /// An containing the data to encrypt and other options for algorithm-dependent encryption. + /// An containing the data to encrypt and other parameters for algorithm-dependent encryption. /// A to cancel the operation. /// /// The result of the encrypt operation. The returned contains the encrypted data /// along with all other information needed to decrypt it. This information should be stored with the encrypted data. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual async Task EncryptAsync(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual async Task EncryptAsync(EncryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); EncryptResult result = null; if (_provider.SupportsOperation(KeyOperation.Encrypt)) { - result = await _provider.EncryptAsync(options, cancellationToken).ConfigureAwait(false); + result = await _provider.EncryptAsync(parameters, cancellationToken).ConfigureAwait(false); } return result ?? throw LocalCryptographyProvider.CreateOperationNotSupported(nameof(KeyOperation.Encrypt)); @@ -112,25 +112,25 @@ public virtual async Task EncryptAsync(EncryptOptions options, Ca /// /// Encrypts plaintext. /// - /// An containing the data to encrypt and other options for algorithm-dependent encryption. + /// An containing the data to encrypt and other parameters for algorithm-dependent encryption. /// A to cancel the operation. /// /// The result of the encrypt operation. The returned contains the encrypted data /// along with all other information needed to decrypt it. This information should be stored with the encrypted data. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); EncryptResult result = null; if (_provider.SupportsOperation(KeyOperation.Encrypt)) { - result = _provider.Encrypt(options, cancellationToken); + result = _provider.Encrypt(parameters, cancellationToken); } return result ?? throw LocalCryptographyProvider.CreateOperationNotSupported(nameof(KeyOperation.Encrypt)); @@ -151,7 +151,7 @@ public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken c /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual async Task DecryptAsync(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default) => - await DecryptAsync(new DecryptOptions(algorithm, ciphertext), cancellationToken).ConfigureAwait(false); + await DecryptAsync(new DecryptParameters(algorithm, ciphertext), cancellationToken).ConfigureAwait(false); /// /// Decrypts ciphertext. @@ -168,30 +168,30 @@ public virtual async Task DecryptAsync(EncryptionAlgorithm algori /// The key is invalid for the current operation. /// The operation is not supported with the specified key. public virtual DecryptResult Decrypt(EncryptionAlgorithm algorithm, byte[] ciphertext, CancellationToken cancellationToken = default) => - Decrypt(new DecryptOptions(algorithm, ciphertext), cancellationToken); + Decrypt(new DecryptParameters(algorithm, ciphertext), cancellationToken); /// /// Decrypts ciphertext. /// - /// A containing the data to decrypt and other options for algorithm-dependent decryption. + /// A containing the data to decrypt and other parameters for algorithm-dependent decryption. /// A to cancel the operation. /// /// The result of the decrypt operation. The returned contains the encrypted data /// along with information regarding the algorithm and key used to decrypt it. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual async Task DecryptAsync(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual async Task DecryptAsync(DecryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); DecryptResult result = null; if (_provider.SupportsOperation(KeyOperation.Decrypt)) { - result = await _provider.DecryptAsync(options, cancellationToken).ConfigureAwait(false); + result = await _provider.DecryptAsync(parameters, cancellationToken).ConfigureAwait(false); } return result ?? throw LocalCryptographyProvider.CreateOperationNotSupported(nameof(KeyOperation.Decrypt)); @@ -200,25 +200,25 @@ public virtual async Task DecryptAsync(DecryptOptions options, Ca /// /// Decrypts the specified ciphertext. /// - /// A containing the data to decrypt and other options for algorithm-dependent decryption. + /// A containing the data to decrypt and other parameters for algorithm-dependent decryption. /// A to cancel the operation. /// /// The result of the decrypt operation. The returned contains the encrypted data /// along with information regarding the algorithm and key used to decrypt it. /// /// The specified algorithm does not match the key corresponding to the key identifier. - /// is null. + /// is null. /// The local cryptographic provider threw an exception. /// The key is invalid for the current operation. /// The operation is not supported with the specified key. - public virtual DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken = default) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); DecryptResult result = null; if (_provider.SupportsOperation(KeyOperation.Decrypt)) { - result = _provider.Decrypt(options, cancellationToken); + result = _provider.Decrypt(parameters, cancellationToken); } return result ?? throw LocalCryptographyProvider.CreateOperationNotSupported(nameof(KeyOperation.Decrypt)); diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyProvider.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyProvider.cs index a5816f49fd17..a1bf337ada9f 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyProvider.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/LocalCryptographyProvider.cs @@ -26,25 +26,25 @@ public LocalCryptographyProvider(JsonWebKey keyMaterial, KeyProperties keyProper public abstract bool SupportsOperation(KeyOperation operation); - public virtual DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken = default) { throw CreateOperationNotSupported(nameof(Decrypt)); } - public virtual Task DecryptAsync(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual Task DecryptAsync(DecryptParameters parameters, CancellationToken cancellationToken = default) { - DecryptResult result = Decrypt(options, cancellationToken); + DecryptResult result = Decrypt(parameters, cancellationToken); return Task.FromResult(result); } - public virtual EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken = default) { throw CreateOperationNotSupported(nameof(Encrypt)); } - public virtual Task EncryptAsync(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual Task EncryptAsync(EncryptParameters parameters, CancellationToken cancellationToken = default) { - EncryptResult result = Encrypt(options, cancellationToken); + EncryptResult result = Encrypt(parameters, cancellationToken); return Task.FromResult(result); } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RemoteCryptographyClient.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RemoteCryptographyClient.cs index 8258d77d1031..6e56ee1ec35d 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RemoteCryptographyClient.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RemoteCryptographyClient.cs @@ -41,7 +41,7 @@ internal RemoteCryptographyClient(KeyVaultPipeline pipeline) public bool SupportsOperation(KeyOperation operation) => true; - public virtual async Task> EncryptAsync(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual async Task> EncryptAsync(EncryptParameters parameters, CancellationToken cancellationToken = default) { using DiagnosticScope scope = Pipeline.CreateScope($"{nameof(RemoteCryptographyClient)}.{nameof(Encrypt)}"); scope.AddAttribute("key", _keyId); @@ -51,9 +51,9 @@ public virtual async Task> EncryptAsync(EncryptOptions o { // Make sure the IV is initialized. // TODO: Remove this call once the service will initialized it: https://github.com/Azure/azure-sdk-for-net/issues/16175 - options.Initialize(); + parameters.Initialize(); - return await Pipeline.SendRequestAsync(RequestMethod.Post, options, () => new EncryptResult { Algorithm = options.Algorithm }, cancellationToken, "/encrypt").ConfigureAwait(false); + return await Pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new EncryptResult { Algorithm = parameters.Algorithm }, cancellationToken, "/encrypt").ConfigureAwait(false); } catch (Exception e) { @@ -62,7 +62,7 @@ public virtual async Task> EncryptAsync(EncryptOptions o } } - public virtual Response Encrypt(EncryptOptions options, CancellationToken cancellationToken = default) + public virtual Response Encrypt(EncryptParameters parameters, CancellationToken cancellationToken = default) { using DiagnosticScope scope = Pipeline.CreateScope($"{nameof(RemoteCryptographyClient)}.{nameof(Encrypt)}"); scope.AddAttribute("key", _keyId); @@ -72,9 +72,9 @@ public virtual Response Encrypt(EncryptOptions options, Cancellat { // Make sure the IV is initialized. // TODO: Remove this call once the service will initialized it: https://github.com/Azure/azure-sdk-for-net/issues/16175 - options.Initialize(); + parameters.Initialize(); - return Pipeline.SendRequest(RequestMethod.Post, options, () => new EncryptResult { Algorithm = options.Algorithm }, cancellationToken, "/encrypt"); + return Pipeline.SendRequest(RequestMethod.Post, parameters, () => new EncryptResult { Algorithm = parameters.Algorithm }, cancellationToken, "/encrypt"); } catch (Exception e) { @@ -83,7 +83,7 @@ public virtual Response Encrypt(EncryptOptions options, Cancellat } } - public virtual async Task> DecryptAsync(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual async Task> DecryptAsync(DecryptParameters parameters, CancellationToken cancellationToken = default) { using DiagnosticScope scope = Pipeline.CreateScope($"{nameof(RemoteCryptographyClient)}.{nameof(Decrypt)}"); scope.AddAttribute("key", _keyId); @@ -91,7 +91,7 @@ public virtual async Task> DecryptAsync(DecryptOptions o try { - return await Pipeline.SendRequestAsync(RequestMethod.Post, options, () => new DecryptResult { Algorithm = options.Algorithm }, cancellationToken, "/decrypt").ConfigureAwait(false); + return await Pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new DecryptResult { Algorithm = parameters.Algorithm }, cancellationToken, "/decrypt").ConfigureAwait(false); } catch (Exception e) { @@ -100,7 +100,7 @@ public virtual async Task> DecryptAsync(DecryptOptions o } } - public virtual Response Decrypt(DecryptOptions options, CancellationToken cancellationToken = default) + public virtual Response Decrypt(DecryptParameters parameters, CancellationToken cancellationToken = default) { using DiagnosticScope scope = Pipeline.CreateScope($"{nameof(RemoteCryptographyClient)}.{nameof(Decrypt)}"); scope.AddAttribute("key", _keyId); @@ -108,7 +108,7 @@ public virtual Response Decrypt(DecryptOptions options, Cancellat try { - return Pipeline.SendRequest(RequestMethod.Post, options, () => new DecryptResult { Algorithm = options.Algorithm }, cancellationToken, "/decrypt"); + return Pipeline.SendRequest(RequestMethod.Post, parameters, () => new DecryptResult { Algorithm = parameters.Algorithm }, cancellationToken, "/decrypt"); } catch (Exception e) { @@ -339,24 +339,24 @@ internal virtual Response GetKey(CancellationToken cancellationToke bool ICryptographyProvider.ShouldRemote => false; - async Task ICryptographyProvider.EncryptAsync(EncryptOptions options, CancellationToken cancellationToken) + async Task ICryptographyProvider.EncryptAsync(EncryptParameters parameters, CancellationToken cancellationToken) { - return await EncryptAsync(options, cancellationToken).ConfigureAwait(false); + return await EncryptAsync(parameters, cancellationToken).ConfigureAwait(false); } - EncryptResult ICryptographyProvider.Encrypt(EncryptOptions options, CancellationToken cancellationToken) + EncryptResult ICryptographyProvider.Encrypt(EncryptParameters parameters, CancellationToken cancellationToken) { - return Encrypt(options, cancellationToken); + return Encrypt(parameters, cancellationToken); } - async Task ICryptographyProvider.DecryptAsync(DecryptOptions options, CancellationToken cancellationToken) + async Task ICryptographyProvider.DecryptAsync(DecryptParameters parameters, CancellationToken cancellationToken) { - return await DecryptAsync(options, cancellationToken).ConfigureAwait(false); + return await DecryptAsync(parameters, cancellationToken).ConfigureAwait(false); } - DecryptResult ICryptographyProvider.Decrypt(DecryptOptions options, CancellationToken cancellationToken) + DecryptResult ICryptographyProvider.Decrypt(DecryptParameters parameters, CancellationToken cancellationToken) { - return Decrypt(options, cancellationToken); + return Decrypt(parameters, cancellationToken); } async Task ICryptographyProvider.WrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RsaCryptographyProvider.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RsaCryptographyProvider.cs index 842d1b341d12..0638bf0106a8 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RsaCryptographyProvider.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/Cryptography/RsaCryptographyProvider.cs @@ -26,13 +26,13 @@ public override bool SupportsOperation(KeyOperation operation) return false; } - public override EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken) + public override EncryptResult Encrypt(EncryptParameters parameters, CancellationToken cancellationToken) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); ThrowIfTimeInvalid(); - EncryptionAlgorithm algorithm = options.Algorithm; + EncryptionAlgorithm algorithm = parameters.Algorithm; RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); if (padding is null) { @@ -40,7 +40,7 @@ public override EncryptResult Encrypt(EncryptOptions options, CancellationToken return null; } - byte[] ciphertext = Encrypt(options.Plaintext, padding); + byte[] ciphertext = Encrypt(parameters.Plaintext, padding); EncryptResult result = null; if (ciphertext != null) @@ -56,9 +56,9 @@ public override EncryptResult Encrypt(EncryptOptions options, CancellationToken return result; } - public override DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken) + public override DecryptResult Decrypt(DecryptParameters parameters, CancellationToken cancellationToken) { - Argument.AssertNotNull(options, nameof(options)); + Argument.AssertNotNull(parameters, nameof(parameters)); if (MustRemote) { @@ -67,7 +67,7 @@ public override DecryptResult Decrypt(DecryptOptions options, CancellationToken return null; } - EncryptionAlgorithm algorithm = options.Algorithm; + EncryptionAlgorithm algorithm = parameters.Algorithm; RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding(); if (padding is null) { @@ -75,7 +75,7 @@ public override DecryptResult Decrypt(DecryptOptions options, CancellationToken return null; } - byte[] plaintext = Decrypt(options.Ciphertext, padding); + byte[] plaintext = Decrypt(parameters.Ciphertext, padding); DecryptResult result = null; if (plaintext != null) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyVaultKeyIdentifier.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyVaultKeyIdentifier.cs index 849a22c3c8a2..8f2f6825a6ce 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyVaultKeyIdentifier.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/src/KeyVaultKeyIdentifier.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using Azure.Core; namespace Azure.Security.KeyVault.Keys { @@ -9,18 +10,33 @@ namespace Azure.Security.KeyVault.Keys /// Information about a parsed from a . /// You can use this information when calling methods of a . /// - public readonly struct KeyVaultKeyIdentifier + public readonly struct KeyVaultKeyIdentifier : IEquatable { - private KeyVaultKeyIdentifier(Uri sourceId, Uri vaultUri, string name, string version) + /// + /// Creates a new instance of the class. + /// + /// The to a key or deleted key. + /// is not a valid Key Vault key ID. + /// is null. + public KeyVaultKeyIdentifier(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 key ID", nameof(id)); + } } /// - /// Gets the source passed to or . + /// Gets the source passed to . /// public Uri SourceId { get; } @@ -39,43 +55,16 @@ private KeyVaultKeyIdentifier(Uri sourceId, Uri vaultUri, string name, string ve /// public string Version { get; } - /// - /// Parses a to a key or deleted key. - /// - /// The to a key or deleted key. - /// A containing information about the key or deleted key. - /// The is not a valid Key Vault key ID. - public static KeyVaultKeyIdentifier Parse(Uri id) - { - if (TryParse(id, out KeyVaultKeyIdentifier keyId)) - { - return keyId; - } - - throw new ArgumentException($"{id} is not a valid Key Vault key ID", nameof(id)); - } + /// + public override bool Equals(object obj) => + obj is KeyVaultKeyIdentifier other && Equals(other); - /// - /// Tries to parse a to a key or deleted key. - /// - /// The to a key or deleted key. - /// A containing information about the key or deleted key. - /// True if the could be parsed successfully; otherwise, false. - public static bool TryParse(Uri id, out KeyVaultKeyIdentifier keyId) - { - if (KeyVaultIdentifier.TryParse(id, out KeyVaultIdentifier identifier)) - { - keyId = new KeyVaultKeyIdentifier( - id, - identifier.VaultUri, - identifier.Name, - identifier.Version); + /// + public bool Equals(KeyVaultKeyIdentifier other) => + SourceId.Equals(other.SourceId); - return true; - } - - keyId = default; - return false; - } + /// + public override int GetHashCode() => + SourceId.GetHashCode(); } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/AesCryptographyProviderTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/AesCryptographyProviderTests.cs index 459853f3997f..09e9fa1f9ce4 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/AesCryptographyProviderTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/AesCryptographyProviderTests.cs @@ -74,7 +74,7 @@ public void EncryptBeforeValidDate() AesCryptographyProvider provider = new AesCryptographyProvider(key.Key, key.Properties); byte[] iv = { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 }; - EncryptOptions options = EncryptOptions.A128CbcOptions(Encoding.UTF8.GetBytes("Single block msg"), iv); + EncryptParameters options = EncryptParameters.A128CbcParameters(Encoding.UTF8.GetBytes("Single block msg"), iv); InvalidOperationException ex = Assert.Throws(() => provider.Encrypt(options, default)); Assert.AreEqual($"The key \"test\" is not valid before {key.Properties.NotBefore.Value:r}.", ex.Message); @@ -97,7 +97,7 @@ public void EncryptAfterValidDate() AesCryptographyProvider provider = new AesCryptographyProvider(key.Key, key.Properties); byte[] iv = { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 }; - EncryptOptions options = EncryptOptions.A128CbcOptions(Encoding.UTF8.GetBytes("Single block msg"), iv); + EncryptParameters options = EncryptParameters.A128CbcParameters(Encoding.UTF8.GetBytes("Single block msg"), iv); InvalidOperationException ex = Assert.Throws(() => provider.Encrypt(options, default)); Assert.AreEqual($"The key \"test\" is not valid after {key.Properties.ExpiresOn.Value:r}.", ex.Message); @@ -113,7 +113,7 @@ public void EncryptionAlgorithmNotSupported() JsonWebKey key = new JsonWebKey(aes); AesCryptographyProvider provider = new AesCryptographyProvider(key, null); - Assert.IsNull(provider.Encrypt(new EncryptOptions(new EncryptionAlgorithm("invalid"), new byte[] { 0 }))); + Assert.IsNull(provider.Encrypt(new EncryptParameters(new EncryptionAlgorithm("invalid"), new byte[] { 0 }))); EventWrittenEventArgs e = listener.SingleEventById(KeysEventSource.AlgorithmNotSupportedEvent); Assert.AreEqual("Encrypt", e.GetProperty("operation")); @@ -130,7 +130,7 @@ public void DecryptionAlgorithmNotSupported() JsonWebKey key = new JsonWebKey(aes); AesCryptographyProvider provider = new AesCryptographyProvider(key, null); - Assert.IsNull(provider.Decrypt(new DecryptOptions(new EncryptionAlgorithm("invalid"), new byte[] { 0 }))); + Assert.IsNull(provider.Decrypt(new DecryptParameters(new EncryptionAlgorithm("invalid"), new byte[] { 0 }))); EventWrittenEventArgs e = listener.SingleEventById(KeysEventSource.AlgorithmNotSupportedEvent); Assert.AreEqual("Decrypt", e.GetProperty("operation")); @@ -155,7 +155,7 @@ public void EncryptDecryptRoundtrips(EncryptionAlgorithm algorithm) byte[] plaintext = Encoding.UTF8.GetBytes("plaintext"); - EncryptOptions encryptOptions = new EncryptOptions(algorithm, plaintext, iv, aad); + EncryptParameters encryptOptions = new EncryptParameters(algorithm, plaintext, iv, aad); EncryptResult encrypted = provider.Encrypt(encryptOptions, default); Assert.IsNotNull(encrypted); @@ -218,7 +218,7 @@ public void EncryptDecryptRoundtrips(EncryptionAlgorithm algorithm) break; } - DecryptOptions decryptOptions = new DecryptOptions(algorithm, encrypted.Ciphertext, encrypted.Iv); + DecryptParameters decryptOptions = new DecryptParameters(algorithm, encrypted.Ciphertext, encrypted.Iv); DecryptResult decrypted = provider.Decrypt(decryptOptions, default); Assert.IsNotNull(decrypted); @@ -242,13 +242,13 @@ public void InitializesIv(EncryptionAlgorithm algorithm) byte[] plaintext = Encoding.UTF8.GetBytes("plaintext"); - EncryptOptions encryptOptions = new EncryptOptions(algorithm, plaintext, null, null); + EncryptParameters encryptOptions = new EncryptParameters(algorithm, plaintext, null, null); EncryptResult encrypted = provider.Encrypt(encryptOptions, default); Assert.IsNotNull(encryptOptions.Iv); CollectionAssert.AreEqual(encryptOptions.Iv, encrypted.Iv); - DecryptOptions decryptOptions = new DecryptOptions(algorithm, encrypted.Ciphertext, encrypted.Iv); + DecryptParameters decryptOptions = new DecryptParameters(algorithm, encrypted.Ciphertext, encrypted.Iv); DecryptResult decrypted = provider.Decrypt(decryptOptions, default); Assert.IsNotNull(decrypted); @@ -271,7 +271,7 @@ public void AesGcmEncryptNotSupported([EnumValues(nameof(EncryptionAlgorithm.A12 byte[] plaintext = Encoding.UTF8.GetBytes("plaintext"); AesCryptographyProvider provider = new AesCryptographyProvider(key, null); - Assert.IsNull(provider.Encrypt(new EncryptOptions(algorithm, plaintext))); + Assert.IsNull(provider.Encrypt(new EncryptParameters(algorithm, plaintext))); } [Test] @@ -290,7 +290,7 @@ public void AesGcmDecryptNotSupported([EnumValues(nameof(EncryptionAlgorithm.A12 byte[] tag = new byte[] { 0xeb, 0x2f, 0x3a, 0xd3, 0x87, 0xb0, 0x72, 0x68, 0xba, 0xcc, 0x04, 0x91 }; AesCryptographyProvider provider = new AesCryptographyProvider(key, null); - Assert.IsNull(provider.Decrypt(new DecryptOptions(algorithm, ciphertext, iv, tag, null))); + Assert.IsNull(provider.Decrypt(new DecryptParameters(algorithm, ciphertext, iv, tag, null))); } private static IEnumerable GetEncryptionAlgorithms() diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyModelFactoryTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyModelFactoryTests.cs index 1330b6f2b05b..59706248238b 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyModelFactoryTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/CryptographyModelFactoryTests.cs @@ -11,13 +11,13 @@ public class CryptographyModelFactoryTests { [Test] public void DecryptOptionsRequiresCiphertext() => - Assert.AreEqual("ciphertext", Assert.Throws(() => CryptographyModelFactory.DecryptOptions(EncryptionAlgorithm.A128Cbc, null)).ParamName); + Assert.AreEqual("ciphertext", Assert.Throws(() => CryptographyModelFactory.DecryptParameters(EncryptionAlgorithm.A128Cbc, null)).ParamName); [Test] public void DecryptOptionsOnlyRequired() { byte[] buffer = new byte[] { 0, 1, 2, 3 }; - DecryptOptions options = CryptographyModelFactory.DecryptOptions(EncryptionAlgorithm.A128Cbc, buffer, null, null); + DecryptParameters options = CryptographyModelFactory.DecryptParameters(EncryptionAlgorithm.A128Cbc, buffer, null, null); Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm); CollectionAssert.AreEqual(buffer, options.Ciphertext); @@ -30,8 +30,7 @@ public void DecryptOptionsOnlyRequired() public void DecryptOptionsAll() { byte[] buffer = new byte[] { 0, 1, 2, 3 }; - DecryptOptions options = CryptographyModelFactory.DecryptOptions(EncryptionAlgorithm.A128Cbc, buffer, buffer, buffer); - options.AdditionalAuthenticatedData = buffer; + DecryptParameters options = CryptographyModelFactory.DecryptParameters(EncryptionAlgorithm.A128Cbc, buffer, buffer, buffer, buffer); Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm); CollectionAssert.AreEqual(buffer, options.Ciphertext); @@ -42,13 +41,13 @@ public void DecryptOptionsAll() [Test] public void EncryptOptionsRequiresPlaintext() => - Assert.AreEqual("plaintext", Assert.Throws(() => CryptographyModelFactory.EncryptOptions(EncryptionAlgorithm.A128Cbc, null)).ParamName); + Assert.AreEqual("plaintext", Assert.Throws(() => CryptographyModelFactory.EncryptParameters(EncryptionAlgorithm.A128Cbc, null)).ParamName); [Test] public void EncryptOptionsOnlyRequired() { byte[] buffer = new byte[] { 0, 1, 2, 3 }; - EncryptOptions options = CryptographyModelFactory.EncryptOptions(EncryptionAlgorithm.A128Cbc, buffer); + EncryptParameters options = CryptographyModelFactory.EncryptParameters(EncryptionAlgorithm.A128Cbc, buffer); Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm); CollectionAssert.AreEqual(buffer, options.Plaintext); @@ -60,8 +59,7 @@ public void EncryptOptionsOnlyRequired() public void EncryptOptionsAll() { byte[] buffer = new byte[] { 0, 1, 2, 3 }; - EncryptOptions options = CryptographyModelFactory.EncryptOptions(EncryptionAlgorithm.A128Cbc, buffer, buffer); - options.AdditionalAuthenticatedData = buffer; + EncryptParameters options = CryptographyModelFactory.EncryptParameters(EncryptionAlgorithm.A128Cbc, buffer, buffer, buffer); Assert.AreEqual(EncryptionAlgorithm.A128Cbc, options.Algorithm); CollectionAssert.AreEqual(buffer, options.Plaintext); diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/DecryptOptionsTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/DecryptParametersTests.cs similarity index 63% rename from sdk/keyvault/Azure.Security.KeyVault.Keys/tests/DecryptOptionsTests.cs rename to sdk/keyvault/Azure.Security.KeyVault.Keys/tests/DecryptParametersTests.cs index 018fa1142604..b3db967969cb 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/DecryptOptionsTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/DecryptParametersTests.cs @@ -7,95 +7,95 @@ namespace Azure.Security.KeyVault.Keys.Tests { - public class DecryptOptionsTests + public class DecryptParametersTests { [Test] public void RequiresCiphertext() { - ArgumentNullException ex = Assert.Throws(() => DecryptOptions.Rsa15Options(null)); + ArgumentNullException ex = Assert.Throws(() => DecryptParameters.Rsa15Parameters(null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.RsaOaepOptions(null)); + ex = Assert.Throws(() => DecryptParameters.RsaOaepParameters(null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.RsaOaep256Options(null)); + ex = Assert.Throws(() => DecryptParameters.RsaOaep256Parameters(null)); Assert.AreEqual("ciphertext", ex.ParamName); } [Test] public void RequiresOnlyCiphertextIvAuthenticationTag() { - ArgumentNullException ex = Assert.Throws(() => DecryptOptions.A128GcmOptions(null, null, null, null)); + ArgumentNullException ex = Assert.Throws(() => DecryptParameters.A128GcmParameters(null, null, null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A128GcmOptions(Array.Empty(), null, null, null)); + ex = Assert.Throws(() => DecryptParameters.A128GcmParameters(Array.Empty(), null, null, null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A128GcmOptions(Array.Empty(), Array.Empty(), null, null)); + ex = Assert.Throws(() => DecryptParameters.A128GcmParameters(Array.Empty(), Array.Empty(), null, null)); Assert.AreEqual("authenticationTag", ex.ParamName); - Assert.DoesNotThrow(() => DecryptOptions.A128GcmOptions(Array.Empty(), Array.Empty(), Array.Empty(), null)); + Assert.DoesNotThrow(() => DecryptParameters.A128GcmParameters(Array.Empty(), Array.Empty(), Array.Empty(), null)); - ex = Assert.Throws(() => DecryptOptions.A192GcmOptions(null, null, null, null)); + ex = Assert.Throws(() => DecryptParameters.A192GcmParameters(null, null, null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A192GcmOptions(Array.Empty(), null, null, null)); + ex = Assert.Throws(() => DecryptParameters.A192GcmParameters(Array.Empty(), null, null, null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A192GcmOptions(Array.Empty(), Array.Empty(), null, null)); + ex = Assert.Throws(() => DecryptParameters.A192GcmParameters(Array.Empty(), Array.Empty(), null, null)); Assert.AreEqual("authenticationTag", ex.ParamName); - Assert.DoesNotThrow(() => DecryptOptions.A192GcmOptions(Array.Empty(), Array.Empty(), Array.Empty(), null)); + Assert.DoesNotThrow(() => DecryptParameters.A192GcmParameters(Array.Empty(), Array.Empty(), Array.Empty(), null)); - ex = Assert.Throws(() => DecryptOptions.A256GcmOptions(null, null, null, null)); + ex = Assert.Throws(() => DecryptParameters.A256GcmParameters(null, null, null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A256GcmOptions(Array.Empty(), null, null, null)); + ex = Assert.Throws(() => DecryptParameters.A256GcmParameters(Array.Empty(), null, null, null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A256GcmOptions(Array.Empty(), Array.Empty(), null, null)); + ex = Assert.Throws(() => DecryptParameters.A256GcmParameters(Array.Empty(), Array.Empty(), null, null)); Assert.AreEqual("authenticationTag", ex.ParamName); - Assert.DoesNotThrow(() => DecryptOptions.A256GcmOptions(Array.Empty(), Array.Empty(), Array.Empty(), null)); + Assert.DoesNotThrow(() => DecryptParameters.A256GcmParameters(Array.Empty(), Array.Empty(), Array.Empty(), null)); } [Test] public void RequiresCiphertextIv() { - ArgumentNullException ex = Assert.Throws(() => DecryptOptions.A128CbcOptions(null, null)); + ArgumentNullException ex = Assert.Throws(() => DecryptParameters.A128CbcParameters(null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A128CbcOptions(Array.Empty(), null)); + ex = Assert.Throws(() => DecryptParameters.A128CbcParameters(Array.Empty(), null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A192CbcOptions(null, null)); + ex = Assert.Throws(() => DecryptParameters.A192CbcParameters(null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A192CbcOptions(Array.Empty(), null)); + ex = Assert.Throws(() => DecryptParameters.A192CbcParameters(Array.Empty(), null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A256CbcOptions(null, null)); + ex = Assert.Throws(() => DecryptParameters.A256CbcParameters(null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A256CbcOptions(Array.Empty(), null)); + ex = Assert.Throws(() => DecryptParameters.A256CbcParameters(Array.Empty(), null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A128CbcPadOptions(null, null)); + ex = Assert.Throws(() => DecryptParameters.A128CbcPadParameters(null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A128CbcPadOptions(Array.Empty(), null)); + ex = Assert.Throws(() => DecryptParameters.A128CbcPadParameters(Array.Empty(), null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A192CbcPadOptions(null, null)); + ex = Assert.Throws(() => DecryptParameters.A192CbcPadParameters(null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A192CbcPadOptions(Array.Empty(), null)); + ex = Assert.Throws(() => DecryptParameters.A192CbcPadParameters(Array.Empty(), null)); Assert.AreEqual("iv", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A256CbcPadOptions(null, null)); + ex = Assert.Throws(() => DecryptParameters.A256CbcPadParameters(null, null)); Assert.AreEqual("ciphertext", ex.ParamName); - ex = Assert.Throws(() => DecryptOptions.A256CbcPadOptions(Array.Empty(), null)); + ex = Assert.Throws(() => DecryptParameters.A256CbcPadParameters(Array.Empty(), null)); Assert.AreEqual("iv", ex.ParamName); } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/EncryptOptionsTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/EncryptParametersTests.cs similarity index 52% rename from sdk/keyvault/Azure.Security.KeyVault.Keys/tests/EncryptOptionsTests.cs rename to sdk/keyvault/Azure.Security.KeyVault.Keys/tests/EncryptParametersTests.cs index f0f495152713..2f768cf66d1d 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/EncryptOptionsTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/EncryptParametersTests.cs @@ -8,87 +8,87 @@ namespace Azure.Security.KeyVault.Keys.Tests { - public class EncryptOptionsTests + public class EncryptParametersTests { [Test] public void RequiresPlaintext() { - ArgumentNullException ex = Assert.Throws(() => EncryptOptions.Rsa15Options(null)); + ArgumentNullException ex = Assert.Throws(() => EncryptParameters.Rsa15Parameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - ex = Assert.Throws(() => EncryptOptions.RsaOaepOptions(null)); + ex = Assert.Throws(() => EncryptParameters.RsaOaepParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - ex = Assert.Throws(() => EncryptOptions.RsaOaep256Options(null)); + ex = Assert.Throws(() => EncryptParameters.RsaOaep256Parameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - ex = Assert.Throws(() => EncryptOptions.A128GcmOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128GcmParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A128GcmOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A128GcmParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A192GcmOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A192GcmParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A192GcmOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A192GcmParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A256GcmOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A256GcmParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A256GcmOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A256GcmParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A128CbcOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128CbcParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A128CbcOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A128CbcParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A128CbcOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128CbcParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A192CbcOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A192CbcParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A128CbcOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128CbcParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A256CbcOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A256CbcParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A128CbcPadOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128CbcPadParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A128CbcPadOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A128CbcPadParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A128CbcPadOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128CbcPadParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A192CbcPadOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A192CbcPadParameters(Array.Empty(), null)); - ex = Assert.Throws(() => EncryptOptions.A128CbcPadOptions(null)); + ex = Assert.Throws(() => EncryptParameters.A128CbcPadParameters(null)); Assert.AreEqual("plaintext", ex.ParamName); - Assert.DoesNotThrow(() => EncryptOptions.A256CbcPadOptions(Array.Empty(), null)); + Assert.DoesNotThrow(() => EncryptParameters.A256CbcPadParameters(Array.Empty(), null)); } [Test] public void InitializesIv([EnumValues] EncryptionAlgorithm algorithm) { - EncryptOptions options = new EncryptOptions(algorithm, Array.Empty()); - options.Initialize(); + EncryptParameters parameters = new EncryptParameters(algorithm, Array.Empty()); + parameters.Initialize(); if (algorithm.GetAesCbcEncryptionAlgorithm() != null) { - byte[] iv = options.Iv; + byte[] iv = parameters.Iv; - Assert.IsNotNull(options.Iv); - CollectionAssert.IsNotEmpty(options.Iv); + Assert.IsNotNull(parameters.Iv); + CollectionAssert.IsNotEmpty(parameters.Iv); // Calling it again should not overwrite. - options.Initialize(); + parameters.Initialize(); - Assert.AreSame(iv, options.Iv); + Assert.AreSame(iv, parameters.Iv); } else { - Assert.IsNull(options.Iv); + Assert.IsNull(parameters.Iv); } } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyVaultKeyIdentifierTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyVaultKeyIdentifierTests.cs index 049f53b91b33..6b40e15f754d 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyVaultKeyIdentifierTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/KeyVaultKeyIdentifierTests.cs @@ -9,12 +9,19 @@ namespace Azure.Security.KeyVault.Keys.Tests { public class KeyVaultKeyIdentifierTests { + [Test] + public void KeyVaultKeyIdentifierNullThrows() + { + ArgumentException ex = Assert.Throws(() => new KeyVaultKeyIdentifier(null)); + Assert.AreEqual("id", ex.ParamName); + } + [TestCaseSource(nameof(Data))] public bool Parse(Uri id, Uri vaultUri, string name, string version) { try { - KeyVaultKeyIdentifier identifier = KeyVaultKeyIdentifier.Parse(id); + KeyVaultKeyIdentifier identifier = new KeyVaultKeyIdentifier(id); Assert.AreEqual(id, identifier.SourceId); Assert.AreEqual(vaultUri, identifier.VaultUri); @@ -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 (KeyVaultKeyIdentifier.TryParse(id, out KeyVaultKeyIdentifier identifier)) - { - Assert.AreEqual(id, identifier.SourceId); - Assert.AreEqual(vaultUri, identifier.VaultUri); - Assert.AreEqual(name, identifier.Name); - Assert.AreEqual(version, identifier.Version); + KeyVaultKeyIdentifier a = new KeyVaultKeyIdentifier(new Uri("https://test.vault.azure.net/keys/test-name/test-version")); + KeyVaultKeyIdentifier b = new KeyVaultKeyIdentifier(new Uri("https://test.vault.azure.net/keys/test-name/test-version")); - return true; - } + Assert.AreEqual(a, b); + } + + [Test] + public void NotEquals() + { + KeyVaultKeyIdentifier a = new KeyVaultKeyIdentifier(new Uri("https://test.vault.azure.net/keys/test-name/test-version?api-version=7.0")); + KeyVaultKeyIdentifier b = new KeyVaultKeyIdentifier(new Uri("https://test.vault.azure.net/keys/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"); + KeyVaultKeyIdentifier keyId = new KeyVaultKeyIdentifier(uri); - return false; + Assert.AreEqual(uri.GetHashCode(), keyId.GetHashCode()); } private static IEnumerable Data => new[] { - new IdentifierTestData(null).Returns(false), new IdentifierTestData("https://test.vault.azure.net").Returns(false), new IdentifierTestData("https://test.vault.azure.net/keys").Returns(false), new IdentifierTestData("https://test.vault.azure.net/keys/test-name", "https://test.vault.azure.net", "test-name").Returns(true), diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/RsaCryptographyProviderTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/RsaCryptographyProviderTests.cs index 0d3341ceeb49..a96c0d336e33 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/RsaCryptographyProviderTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/RsaCryptographyProviderTests.cs @@ -28,7 +28,7 @@ public void EncryptBeforeValidDate() RsaCryptographyProvider provider = new RsaCryptographyProvider(key.Key, key.Properties); byte[] plaintext = Encoding.UTF8.GetBytes("test"); - InvalidOperationException ex = Assert.Throws(() => provider.Encrypt(EncryptOptions.RsaOaep256Options(plaintext), default)); + InvalidOperationException ex = Assert.Throws(() => provider.Encrypt(EncryptParameters.RsaOaep256Parameters(plaintext), default)); Assert.AreEqual($"The key \"test\" is not valid before {key.Properties.NotBefore.Value:r}.", ex.Message); } @@ -49,7 +49,7 @@ public void EncryptAfterValidDate() RsaCryptographyProvider provider = new RsaCryptographyProvider(key.Key, key.Properties); byte[] plaintext = Encoding.UTF8.GetBytes("test"); - InvalidOperationException ex = Assert.Throws(() => provider.Encrypt(EncryptOptions.RsaOaep256Options(plaintext), default)); + InvalidOperationException ex = Assert.Throws(() => provider.Encrypt(EncryptParameters.RsaOaep256Parameters(plaintext), default)); Assert.AreEqual($"The key \"test\" is not valid after {key.Properties.ExpiresOn.Value:r}.", ex.Message); } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/ThrowingCryptographyProvider.cs b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/ThrowingCryptographyProvider.cs index 251dbd607cfb..fa4ba11f1baa 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/ThrowingCryptographyProvider.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Keys/tests/ThrowingCryptographyProvider.cs @@ -16,13 +16,13 @@ internal class ThrowingCryptographyProvider : ICryptographyProvider public bool SupportsOperation(KeyOperation operation) => true; - public DecryptResult Decrypt(DecryptOptions options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); + public DecryptResult Decrypt(DecryptParameters options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); - public Task DecryptAsync(DecryptOptions options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); + public Task DecryptAsync(DecryptParameters options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); - public EncryptResult Encrypt(EncryptOptions options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); + public EncryptResult Encrypt(EncryptParameters options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); - public Task EncryptAsync(EncryptOptions options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); + public Task EncryptAsync(EncryptParameters options, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); public SignResult Sign(SignatureAlgorithm algorithm, byte[] digest, CancellationToken cancellationToken = default) => throw new CryptographicException(CRYPT_E_NO_PROVIDER); diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/CHANGELOG.md b/sdk/keyvault/Azure.Security.KeyVault.Secrets/CHANGELOG.md index 3788828f9dd8..756058c2e06c 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/CHANGELOG.md +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/CHANGELOG.md @@ -2,6 +2,13 @@ ## 4.2.0-beta.4 (Unreleased) +### Added + +- Added constructor to `KeyVaultSecretIdentifier` to parse a `Uri`. + +### Removed + +- Removed `KeyVaultSecretIdentifier.Parse` and `KeyVaultSecretIdentifier.TryParse` in favor of the added constructor. ## 4.2.0-beta.3 (2020-11-12) diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/api/Azure.Security.KeyVault.Secrets.netstandard2.0.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/api/Azure.Security.KeyVault.Secrets.netstandard2.0.cs index d6627b57d0fe..4eeb313dc54f 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/api/Azure.Security.KeyVault.Secrets.netstandard2.0.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/api/Azure.Security.KeyVault.Secrets.netstandard2.0.cs @@ -29,16 +29,18 @@ public KeyVaultSecret(string name, string value) { } public string Value { get { throw null; } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct KeyVaultSecretIdentifier + public readonly partial struct KeyVaultSecretIdentifier : System.IEquatable { private readonly object _dummy; private readonly int _dummyPrimitive; + public KeyVaultSecretIdentifier(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.Secrets.KeyVaultSecretIdentifier Parse(System.Uri id) { throw null; } - public static bool TryParse(System.Uri id, out Azure.Security.KeyVault.Secrets.KeyVaultSecretIdentifier secretId) { throw null; } + public bool Equals(Azure.Security.KeyVault.Secrets.KeyVaultSecretIdentifier other) { throw null; } + public override bool Equals(object obj) { throw null; } + public override int GetHashCode() { throw null; } } public partial class RecoverDeletedSecretOperation : Azure.Operation { diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/KeyVaultSecretIdentifier.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/KeyVaultSecretIdentifier.cs index 3514b992b0a2..c95cb91c6d0b 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/KeyVaultSecretIdentifier.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/src/KeyVaultSecretIdentifier.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using Azure.Core; namespace Azure.Security.KeyVault.Secrets { @@ -9,18 +10,33 @@ namespace Azure.Security.KeyVault.Secrets /// Information about a parsed from a . /// You can use this information when calling methods of a . /// - public readonly struct KeyVaultSecretIdentifier + public readonly struct KeyVaultSecretIdentifier : IEquatable { - private KeyVaultSecretIdentifier(Uri sourceId, Uri vaultUri, string name, string version) + /// + /// Creates a new instance of the class. + /// + /// The to a secret or deleted secret. + /// is not a valid Key Vault secret ID. + /// is null. + public KeyVaultSecretIdentifier(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 secret ID", nameof(id)); + } } /// - /// Gets the source passed to or . + /// Gets the source passed to . /// public Uri SourceId { get; } @@ -39,43 +55,16 @@ private KeyVaultSecretIdentifier(Uri sourceId, Uri vaultUri, string name, string /// public string Version { get; } - /// - /// Parses a to a secret or deleted secret. - /// - /// The to a secret or deleted secret. - /// A containing information about the secret or deleted secret. - /// The is not a valid Key Vault secret ID. - public static KeyVaultSecretIdentifier Parse(Uri id) - { - if (TryParse(id, out KeyVaultSecretIdentifier secretId)) - { - return secretId; - } - - throw new ArgumentException($"{id} is not a valid Key Vault secret ID", nameof(id)); - } + /// + public override bool Equals(object obj) => + obj is KeyVaultSecretIdentifier other && Equals(other); - /// - /// Tries to parse a to a secret or deleted secret. - /// - /// The to a secret or deleted secret. - /// A containing information about the secret or deleted secret. - /// True if the could be parsed successfully; otherwise, false. - public static bool TryParse(Uri id, out KeyVaultSecretIdentifier secretId) - { - if (KeyVaultIdentifier.TryParse(id, out KeyVaultIdentifier identifier)) - { - secretId = new KeyVaultSecretIdentifier( - id, - identifier.VaultUri, - identifier.Name, - identifier.Version); + /// + public bool Equals(KeyVaultSecretIdentifier other) => + SourceId.Equals(other.SourceId); - return true; - } - - secretId = default; - return false; - } + /// + public override int GetHashCode() => + SourceId.GetHashCode(); } } diff --git a/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/KeyVaultSecretIdentifierTests.cs b/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/KeyVaultSecretIdentifierTests.cs index 2d135f618054..39fedf60c416 100644 --- a/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/KeyVaultSecretIdentifierTests.cs +++ b/sdk/keyvault/Azure.Security.KeyVault.Secrets/tests/KeyVaultSecretIdentifierTests.cs @@ -9,12 +9,19 @@ namespace Azure.Security.KeyVault.Secrets.Tests { public class KeyVaultSecretIdentifierTests { + [Test] + public void KeyVaultSecretIdentifierNullThrows() + { + ArgumentException ex = Assert.Throws(() => new KeyVaultSecretIdentifier(null)); + Assert.AreEqual("id", ex.ParamName); + } + [TestCaseSource(nameof(Data))] public bool Parse(Uri id, Uri vaultUri, string name, string version) { try { - KeyVaultSecretIdentifier identifier = KeyVaultSecretIdentifier.Parse(id); + KeyVaultSecretIdentifier identifier = new KeyVaultSecretIdentifier(id); Assert.AreEqual(id, identifier.SourceId); Assert.AreEqual(vaultUri, identifier.VaultUri); @@ -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 (KeyVaultSecretIdentifier.TryParse(id, out KeyVaultSecretIdentifier identifier)) - { - Assert.AreEqual(id, identifier.SourceId); - Assert.AreEqual(vaultUri, identifier.VaultUri); - Assert.AreEqual(name, identifier.Name); - Assert.AreEqual(version, identifier.Version); + KeyVaultSecretIdentifier a = new KeyVaultSecretIdentifier(new Uri("https://test.vault.azure.net/deletedsecrets/test-name/test-version")); + KeyVaultSecretIdentifier b = new KeyVaultSecretIdentifier(new Uri("https://test.vault.azure.net/deletedsecrets/test-name/test-version")); - return true; - } + Assert.AreEqual(a, b); + } + + [Test] + public void NotEquals() + { + KeyVaultSecretIdentifier a = new KeyVaultSecretIdentifier(new Uri("https://test.vault.azure.net/deletedsecrets/test-name/test-version?api-version=7.0")); + KeyVaultSecretIdentifier b = new KeyVaultSecretIdentifier(new Uri("https://test.vault.azure.net/deletedsecrets/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"); + KeyVaultSecretIdentifier keyId = new KeyVaultSecretIdentifier(uri); - return false; + Assert.AreEqual(uri.GetHashCode(), keyId.GetHashCode()); } private static IEnumerable Data => new[] { - new IdentifierTestData(null).Returns(false), new IdentifierTestData("https://test.vault.azure.net").Returns(false), new IdentifierTestData("https://test.vault.azure.net/secrets").Returns(false), new IdentifierTestData("https://test.vault.azure.net/secrets/test-name", "https://test.vault.azure.net", "test-name").Returns(true),