| | | 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 usages of a certificate key. |
| | | 11 | | /// </summary> |
| | | 12 | | public readonly struct CertificateKeyUsage : IEquatable<CertificateKeyUsage> |
| | | 13 | | { |
| | | 14 | | internal const string DigitalSignatureValue = "digitalSignature"; |
| | | 15 | | internal const string NonRepudiationValue = "nonRepudiation"; |
| | | 16 | | internal const string KeyEnciphermentValue = "keyEncipherment"; |
| | | 17 | | internal const string DataEnciphermentValue = "dataEncipherment"; |
| | | 18 | | internal const string KeyAgreementValue = "keyAgreement"; |
| | | 19 | | internal const string KeyCertSignValue = "keyCertSign"; |
| | | 20 | | internal const string CrlSignValue = "crlSign"; |
| | | 21 | | internal const string EncipherOnlyValue = "encipherOnly"; |
| | | 22 | | internal const string DecipherOnlyValue = "decipherOnly"; |
| | | 23 | | |
| | | 24 | | private readonly string _value; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes a new instance of the <see cref="CertificateKeyUsage"/> structure. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="value">The string value of the instance.</param> |
| | | 30 | | public CertificateKeyUsage(string value) |
| | | 31 | | { |
| | 350 | 32 | | _value = value ?? throw new ArgumentNullException(nameof(value)); |
| | 350 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used as a digital signat |
| | | 37 | | /// </summary> |
| | 66 | 38 | | public static CertificateKeyUsage DigitalSignature { get; } = new CertificateKeyUsage(DigitalSignatureValue); |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used for authentication. |
| | | 42 | | /// </summary> |
| | 0 | 43 | | public static CertificateKeyUsage NonRepudiation { get; } = new CertificateKeyUsage(NonRepudiationValue); |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used for key encryption. |
| | | 47 | | /// </summary> |
| | 66 | 48 | | public static CertificateKeyUsage KeyEncipherment { get; } = new CertificateKeyUsage(KeyEnciphermentValue); |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used for data encryption |
| | | 52 | | /// </summary> |
| | 66 | 53 | | public static CertificateKeyUsage DataEncipherment { get; } = new CertificateKeyUsage(DataEnciphermentValue); |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used to determine key ag |
| | | 57 | | /// </summary> |
| | 66 | 58 | | public static CertificateKeyUsage KeyAgreement { get; } = new CertificateKeyUsage(KeyAgreementValue); |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used to sign certificate |
| | | 62 | | /// </summary> |
| | 66 | 63 | | public static CertificateKeyUsage KeyCertSign { get; } = new CertificateKeyUsage(KeyCertSignValue); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used to sign a certifica |
| | | 67 | | /// </summary> |
| | 66 | 68 | | public static CertificateKeyUsage CrlSign { get; } = new CertificateKeyUsage(CrlSignValue); |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used for encryption only |
| | | 72 | | /// </summary> |
| | 0 | 73 | | public static CertificateKeyUsage EncipherOnly { get; } = new CertificateKeyUsage(EncipherOnlyValue); |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Gets a <see cref="CertificateKeyUsage"/> indicating that the certificate key can be used for decryption only |
| | | 77 | | /// </summary> |
| | 0 | 78 | | public static CertificateKeyUsage DecipherOnly { get; } = new CertificateKeyUsage(DecipherOnlyValue); |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Determines if two <see cref="CertificateKeyUsage"/> values are the same. |
| | | 82 | | /// </summary> |
| | | 83 | | /// <param name="left">The first <see cref="CertificateKeyUsage"/> to compare.</param> |
| | | 84 | | /// <param name="right">The second <see cref="CertificateKeyUsage"/> to compare.</param> |
| | | 85 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur |
| | 0 | 86 | | public static bool operator ==(CertificateKeyUsage left, CertificateKeyUsage right) => left.Equals(right); |
| | | 87 | | |
| | | 88 | | /// <summary> |
| | | 89 | | /// Determines if two <see cref="CertificateKeyUsage"/> values are different. |
| | | 90 | | /// </summary> |
| | | 91 | | /// <param name="left">The first <see cref="CertificateKeyUsage"/> to compare.</param> |
| | | 92 | | /// <param name="right">The second <see cref="CertificateKeyUsage"/> to compare.</param> |
| | | 93 | | /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu |
| | 0 | 94 | | public static bool operator !=(CertificateKeyUsage left, CertificateKeyUsage right) => !left.Equals(right); |
| | | 95 | | |
| | | 96 | | /// <summary> |
| | | 97 | | /// Converts a string to a <see cref="CertificateKeyUsage"/>. |
| | | 98 | | /// </summary> |
| | | 99 | | /// <param name="value">The string value to convert.</param> |
| | 332 | 100 | | public static implicit operator CertificateKeyUsage(string value) => new CertificateKeyUsage(value); |
| | | 101 | | |
| | | 102 | | /// <inheritdoc/> |
| | | 103 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 0 | 104 | | public override bool Equals(object obj) => obj is CertificateKeyUsage other && Equals(other); |
| | | 105 | | |
| | | 106 | | /// <inheritdoc/> |
| | 0 | 107 | | public bool Equals(CertificateKeyUsage other) => string.Equals(_value, other._value, StringComparison.Ordinal); |
| | | 108 | | |
| | | 109 | | /// <inheritdoc/> |
| | | 110 | | [EditorBrowsable(EditorBrowsableState.Never)] |
| | 0 | 111 | | public override int GetHashCode() => _value?.GetHashCode() ?? 0; |
| | | 112 | | |
| | | 113 | | /// <inheritdoc/> |
| | 316 | 114 | | public override string ToString() => _value; |
| | | 115 | | } |
| | | 116 | | } |