| | | 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.Certificates |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Supported JsonWebKey key types (kty) |
| | | 11 | | /// </summary> |
| | | 12 | | public readonly struct CertificateKeyType : IEquatable<CertificateKeyType> |
| | | 13 | | { |
| | | 14 | | internal const string EcValue = "EC"; |
| | | 15 | | internal const string EcHsmValue = "EC-HSM"; |
| | | 16 | | internal const string RsaValue = "RSA"; |
| | | 17 | | internal const string RsaHsmValue = "RSA-HSM"; |
| | | 18 | | |
| | | 19 | | private readonly string _value; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Initializes a new instance of the <see cref="CertificateKeyType"/> structure. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="value">The string value of the instance.</param> |
| | | 25 | | public CertificateKeyType(string value) |
| | | 26 | | { |
| | 78 | 27 | | _value = value ?? throw new ArgumentNullException(nameof(value)); |
| | 78 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// An Elliptic Curve Cryptographic (ECC) algorithm. |
| | | 32 | | /// </summary> |
| | 0 | 33 | | public static CertificateKeyType Ec { get; } = new CertificateKeyType(EcValue); |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// An Elliptic Curve Cryptographic (ECC) algorithm backed by HSM. |
| | | 37 | | /// </summary> |
| | 0 | 38 | | public static CertificateKeyType EcHsm { get; } = new CertificateKeyType(EcHsmValue); |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// An RSA cryptographic algorithm. |
| | | 42 | | /// </summary> |
| | 70 | 43 | | public static CertificateKeyType Rsa { get; } = new CertificateKeyType(RsaValue); |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// An RSA cryptographic algorithm backed by HSM. |
| | | 47 | | /// </summary> |
| | 0 | 48 | | public static CertificateKeyType RsaHsm { get; } = new CertificateKeyType(RsaHsmValue); |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Determines if two <see cref="CertificateKeyType"/> values are the same. |
| | | 52 | | /// </summary> |
| | | 53 | | /// <param name="left">The first <see cref="CertificateKeyType"/> to compare.</param> |
| | | 54 | | /// <param name="right">The second <see cref="CertificateKeyType"/> to compare.</param> |
| | | 55 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur |
| | 0 | 56 | | public static bool operator ==(CertificateKeyType left, CertificateKeyType right) => left.Equals(right); |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Determines if two <see cref="CertificateKeyType"/> values are different. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="left">The first <see cref="CertificateKeyType"/> to compare.</param> |
| | | 62 | | /// <param name="right">The second <see cref="CertificateKeyType"/> to compare.</param> |
| | | 63 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu |
| | 0 | 64 | | public static bool operator !=(CertificateKeyType left, CertificateKeyType right) => !left.Equals(right); |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Converts a string to a <see cref="CertificateKeyType"/>. |
| | | 68 | | /// </summary> |
| | | 69 | | /// <param name="value">The string value to convert.</param> |
| | 70 | 70 | | public static implicit operator CertificateKeyType(string value) => new CertificateKeyType(value); |
| | | 71 | | |
| | | 72 | | /// <inheritdoc/> |
| | | 73 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 0 | 74 | | public override bool Equals(object obj) => obj is CertificateKeyType other && Equals(other); |
| | | 75 | | |
| | | 76 | | /// <inheritdoc/> |
| | 6 | 77 | | public bool Equals(CertificateKeyType 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/> |
| | 56 | 84 | | public override string ToString() => _value; |
| | | 85 | | } |
| | | 86 | | } |