| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.ComponentModel; |
| | 6 | | using Azure.Security.KeyVault.Keys.Cryptography; |
| | 7 | |
|
| | 8 | | namespace Azure.Security.KeyVault.Keys |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// An operation that can be performed with the key. |
| | 12 | | /// </summary> |
| | 13 | | public readonly struct KeyOperation : IEquatable<KeyOperation> |
| | 14 | | { |
| | 15 | | private readonly string _value; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Initializes a new instance of the <see cref="KeyOperation"/> structure. |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="value">The string value of the instance.</param> |
| | 21 | | public KeyOperation(string value) |
| | 22 | | { |
| 2340 | 23 | | _value = value ?? throw new ArgumentNullException(nameof(value)); |
| 2340 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Gets a value that indicates the key can be used to encrypt with the <see cref="CryptographyClient.EncryptAsy |
| | 28 | | /// </summary> |
| 178 | 29 | | public static KeyOperation Encrypt { get; } = new KeyOperation("encrypt"); |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Gets a value that indicates the key can be used to decrypt with the <see cref="CryptographyClient.DecryptAsy |
| | 33 | | /// </summary> |
| 174 | 34 | | public static KeyOperation Decrypt { get; } = new KeyOperation("decrypt"); |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Gets a value that indicates the key can be used to sign with the <see cref="CryptographyClient.SignAsync"/> |
| | 38 | | /// </summary> |
| 512 | 39 | | public static KeyOperation Sign { get; } = new KeyOperation("sign"); |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Gets a value that indicates the key can be used to verify with the <see cref="CryptographyClient.VerifyAsync |
| | 43 | | /// </summary> |
| 404 | 44 | | public static KeyOperation Verify { get; } = new KeyOperation("verify"); |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Gets a value that indicates the key can be used to wrap another key with the <see cref="CryptographyClient.W |
| | 48 | | /// </summary> |
| 110 | 49 | | public static KeyOperation WrapKey { get; } = new KeyOperation("wrapKey"); |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Gets a value that indicates the key can be used to unwrap another key with the <see cref="CryptographyClient |
| | 53 | | /// </summary> |
| 98 | 54 | | public static KeyOperation UnwrapKey { get; } = new KeyOperation("unwrapKey"); |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// Gets a value that indicates the key can be imported during creation using the <see cref="KeyClient.ImportKey |
| | 58 | | /// </summary> |
| 0 | 59 | | public static KeyOperation Import { get; } = new KeyOperation("import"); |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Determines if two <see cref="KeyOperation"/> values are the same. |
| | 63 | | /// </summary> |
| | 64 | | /// <param name="left">The first <see cref="KeyOperation"/> to compare.</param> |
| | 65 | | /// <param name="right">The second <see cref="KeyOperation"/> to compare.</param> |
| | 66 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur |
| 1068 | 67 | | public static bool operator ==(KeyOperation left, KeyOperation right) => left.Equals(right); |
| | 68 | |
|
| | 69 | | /// <summary> |
| | 70 | | /// Determines if two <see cref="KeyOperation"/> values are different. |
| | 71 | | /// </summary> |
| | 72 | | /// <param name="left">The first <see cref="KeyOperation"/> to compare.</param> |
| | 73 | | /// <param name="right">The second <see cref="KeyOperation"/> to compare.</param> |
| | 74 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu |
| 0 | 75 | | public static bool operator !=(KeyOperation left, KeyOperation right) => !left.Equals(right); |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Converts a string to a <see cref="KeyOperation"/>. |
| | 79 | | /// </summary> |
| | 80 | | /// <param name="value">The string value to convert.</param> |
| 2314 | 81 | | public static implicit operator KeyOperation(string value) => new KeyOperation(value); |
| | 82 | |
|
| | 83 | | /// <inheritdoc/> |
| | 84 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 85 | | public override bool Equals(object obj) => obj is KeyOperation other && Equals(other); |
| | 86 | |
|
| | 87 | | /// <inheritdoc/> |
| 1698 | 88 | | public bool Equals(KeyOperation other) => string.Equals(_value, other._value, StringComparison.Ordinal); |
| | 89 | |
|
| | 90 | | /// <inheritdoc/> |
| | 91 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| 0 | 92 | | public override int GetHashCode() => _value?.GetHashCode() ?? 0; |
| | 93 | |
|
| | 94 | | /// <inheritdoc/> |
| 338 | 95 | | public override string ToString() => _value; |
| | 96 | | } |
| | 97 | | } |