< Summary

Class:Azure.Security.KeyVault.Keys.Cryptography.EncryptionAlgorithm
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\Cryptography\EncryptionAlgorithm.cs
Covered lines:12
Uncovered lines:7
Coverable lines:19
Total lines:89
Line coverage:63.1% (12 of 19)
Covered branches:4
Total branches:12
Branch coverage:33.3% (4 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%50%
get_Rsa15()-100%100%
get_RsaOaep()-100%100%
get_RsaOaep256()-100%100%
op_Equality(...)-0%100%
op_Inequality(...)-0%100%
op_Implicit(...)-100%100%
Equals(...)-0%0%
Equals(...)-100%100%
GetHashCode()-0%0%
ToString()-100%100%
GetRsaEncryptionPadding()-57.14%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\Cryptography\EncryptionAlgorithm.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.ComponentModel;
 6using System.Security.Cryptography;
 7
 8namespace Azure.Security.KeyVault.Keys.Cryptography
 9{
 10    /// <summary>
 11    /// An algorithm used for encryption and decryption.
 12    /// </summary>
 13    public readonly struct EncryptionAlgorithm : IEquatable<EncryptionAlgorithm>
 14    {
 15        internal const string Rsa15Value = "RSA1_5";
 16        internal const string RsaOaepValue = "RSA-OAEP";
 17        internal const string RsaOaep256Value = "RSA-OAEP-256";
 18
 19        private readonly string _value;
 20
 21        /// <summary>
 22        /// Initializes a new instance of the <see cref="EncryptionAlgorithm"/> structure.
 23        /// </summary>
 24        /// <param name="value">The string value of the instance.</param>
 25        public EncryptionAlgorithm(string value)
 26        {
 2627            _value = value ?? throw new ArgumentNullException(nameof(value));
 2628        }
 29
 30        /// <summary>
 31        /// Gets an RSA1_5 <see cref="EncryptionAlgorithm"/>.
 32        /// </summary>
 1033        public static EncryptionAlgorithm Rsa15 { get; } = new EncryptionAlgorithm(Rsa15Value);
 34
 35        /// <summary>
 36        /// Gets an RSA-OAEP <see cref="EncryptionAlgorithm"/>.
 37        /// </summary>
 1838        public static EncryptionAlgorithm RsaOaep { get; } = new EncryptionAlgorithm(RsaOaepValue);
 39
 40        /// <summary>
 41        /// Gets an RSA-OAEP256 <see cref="EncryptionAlgorithm"/>.
 42        /// </summary>
 1443        public static EncryptionAlgorithm RsaOaep256 { get; } = new EncryptionAlgorithm(RsaOaep256Value);
 44
 45        /// <summary>
 46        /// Determines if two <see cref="EncryptionAlgorithm"/> values are the same.
 47        /// </summary>
 48        /// <param name="left">The first <see cref="EncryptionAlgorithm"/> to compare.</param>
 49        /// <param name="right">The second <see cref="EncryptionAlgorithm"/> to compare.</param>
 50        /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur
 051        public static bool operator ==(EncryptionAlgorithm left, EncryptionAlgorithm right) => left.Equals(right);
 52
 53        /// <summary>
 54        /// Determines if two <see cref="EncryptionAlgorithm"/> values are different.
 55        /// </summary>
 56        /// <param name="left">The first <see cref="EncryptionAlgorithm"/> to compare.</param>
 57        /// <param name="right">The second <see cref="EncryptionAlgorithm"/> to compare.</param>
 58        /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu
 059        public static bool operator !=(EncryptionAlgorithm left, EncryptionAlgorithm right) => !left.Equals(right);
 60
 61        /// <summary>
 62        /// Converts a string to a <see cref="EncryptionAlgorithm"/>.
 63        /// </summary>
 64        /// <param name="value">The string value to convert.</param>
 2065        public static implicit operator EncryptionAlgorithm(string value) => new EncryptionAlgorithm(value);
 66
 67        /// <inheritdoc/>
 68        [EditorBrowsable(EditorBrowsableState.Never)]
 069        public override bool Equals(object obj) => obj is EncryptionAlgorithm other && Equals(other);
 70
 71        /// <inheritdoc/>
 2472        public bool Equals(EncryptionAlgorithm other) => string.Equals(_value, other._value, StringComparison.Ordinal);
 73
 74        /// <inheritdoc/>
 75        [EditorBrowsable(EditorBrowsableState.Never)]
 076        public override int GetHashCode() => _value?.GetHashCode() ?? 0;
 77
 78        /// <inheritdoc/>
 9679        public override string ToString() => _value;
 80
 881        internal RSAEncryptionPadding GetRsaEncryptionPadding() => _value switch
 882        {
 083            Rsa15Value => RSAEncryptionPadding.Pkcs1,
 084            RsaOaepValue => RSAEncryptionPadding.OaepSHA1,
 085            RsaOaep256Value => RSAEncryptionPadding.OaepSHA256,
 1686            _ => null,
 887        };
 88    }
 89}