| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | |
| | | 7 | | namespace Azure.Security.KeyVault.Keys |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// <see cref="JsonWebKey"/> key types. |
| | | 11 | | /// </summary> |
| | | 12 | | public readonly struct KeyType : IEquatable<KeyType> |
| | | 13 | | { |
| | | 14 | | private readonly string _value; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Initializes a new instance of the <see cref="KeyType"/> structure. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <param name="value">The string value of the instance.</param> |
| | | 20 | | public KeyType(string value) |
| | | 21 | | { |
| | 716 | 22 | | _value = value ?? throw new ArgumentNullException(nameof(value)); |
| | 716 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// An Elliptic Curve Cryptographic (ECC) algorithm. |
| | | 27 | | /// </summary> |
| | 586 | 28 | | public static KeyType Ec { get; } = new KeyType("EC"); |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// An Elliptic Curve Cryptographic (ECC) algorithm backed by HSM. |
| | | 32 | | /// </summary> |
| | 112 | 33 | | public static KeyType EcHsm { get; } = new KeyType("EC-HSM"); |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// An RSA cryptographic algorithm. |
| | | 37 | | /// </summary> |
| | 734 | 38 | | public static KeyType Rsa { get; } = new KeyType("RSA"); |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// An RSA cryptographic algorithm backed by HSM. |
| | | 42 | | /// </summary> |
| | 144 | 43 | | public static KeyType RsaHsm { get; } = new KeyType("RSA-HSM"); |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// An AES cryptographic algorithm. |
| | | 47 | | /// </summary> |
| | 156 | 48 | | public static KeyType Oct { get; } = new KeyType("oct"); |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Determines if two <see cref="KeyType"/> values are the same. |
| | | 52 | | /// </summary> |
| | | 53 | | /// <param name="left">The first <see cref="KeyType"/> to compare.</param> |
| | | 54 | | /// <param name="right">The second <see cref="KeyType"/> to compare.</param> |
| | | 55 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur |
| | 938 | 56 | | public static bool operator ==(KeyType left, KeyType right) => left.Equals(right); |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Determines if two <see cref="KeyType"/> values are different. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="left">The first <see cref="KeyType"/> to compare.</param> |
| | | 62 | | /// <param name="right">The second <see cref="KeyType"/> to compare.</param> |
| | | 63 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu |
| | 626 | 64 | | public static bool operator !=(KeyType left, KeyType right) => !left.Equals(right); |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Converts a string to a <see cref="KeyType"/>. |
| | | 68 | | /// </summary> |
| | | 69 | | /// <param name="value">The string value to convert.</param> |
| | 704 | 70 | | public static implicit operator KeyType(string value) => new KeyType(value); |
| | | 71 | | |
| | | 72 | | /// <inheritdoc/> |
| | | 73 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 0 | 74 | | public override bool Equals(object obj) => obj is KeyType other && Equals(other); |
| | | 75 | | |
| | | 76 | | /// <inheritdoc/> |
| | 1892 | 77 | | public bool Equals(KeyType other) => string.Equals(_value, other._value, StringComparison.Ordinal); |
| | | 78 | | |
| | | 79 | | /// <inheritdoc/> |
| | | 80 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 0 | 81 | | public override int GetHashCode() => _value?.GetHashCode() ?? 0; |
| | | 82 | | |
| | | 83 | | /// <inheritdoc/> |
| | 402 | 84 | | public override string ToString() => _value; |
| | | 85 | | } |
| | | 86 | | } |