< Summary

Class:Azure.Security.KeyVault.Keys.Cryptography.KeyWrapAlgorithm
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\Cryptography\KeyWrapAlgorithm.cs
Covered lines:21
Uncovered lines:9
Coverable lines:30
Total lines:119
Line coverage:70% (21 of 30)
Covered branches:9
Total branches:18
Branch coverage:50% (9 of 18)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%50%
get_RsaOaep()-100%100%
get_Rsa15()-100%100%
get_RsaOaep256()-100%100%
get_A128KW()-100%100%
get_A192KW()-0%100%
get_A256KW()-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()-71.43%66.67%
GetKeySizeInBits()-71.43%66.67%
GetKeySizeInBytes()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\Cryptography\KeyWrapAlgorithm.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 key wrap and unwrap.
 12    /// </summary>
 13    public readonly struct KeyWrapAlgorithm : IEquatable<KeyWrapAlgorithm>
 14    {
 15        internal const string RsaOaepValue = "RSA-OAEP";
 16        internal const string Rsa15Value = "RSA1_5";
 17        internal const string RsaOaep256Value = "RSA-OAEP-256";
 18        internal const string A128KWValue = "A128KW";
 19        internal const string A192KWValue = "A192KW";
 20        internal const string A256KWValue = "A256KW";
 21
 22        private readonly string _value;
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="KeyWrapAlgorithm"/> structure.
 26        /// </summary>
 27        /// <param name="value">The string value of the instance.</param>
 28        public KeyWrapAlgorithm(string value)
 29        {
 4030            _value = value ?? throw new ArgumentNullException(nameof(value));
 4031        }
 32
 33        /// <summary>
 34        /// Gets an RSA-OAEP <see cref="KeyWrapAlgorithm"/>.
 35        /// </summary>
 2636        public static KeyWrapAlgorithm RsaOaep { get; } = new KeyWrapAlgorithm(RsaOaepValue);
 37
 38        /// <summary>
 39        /// Gets an RSA1_5 <see cref="KeyWrapAlgorithm"/>.
 40        /// </summary>
 1041        public static KeyWrapAlgorithm Rsa15 { get; } = new KeyWrapAlgorithm(Rsa15Value);
 42
 43        /// <summary>
 44        /// Gets an RSA-OAEP-256 <see cref="KeyWrapAlgorithm"/>.
 45        /// </summary>
 1446        public static KeyWrapAlgorithm RsaOaep256 { get; } = new KeyWrapAlgorithm(RsaOaep256Value);
 47
 48        /// <summary>
 49        /// Gets an AES 128 Key Wrap <see cref="KeyWrapAlgorithm"/>.
 50        /// </summary>
 651        public static KeyWrapAlgorithm A128KW { get; } = new KeyWrapAlgorithm(A128KWValue);
 52
 53        /// <summary>
 54        /// Gets an AES 192 Key Wrap <see cref="KeyWrapAlgorithm"/>.
 55        /// </summary>
 056        public static KeyWrapAlgorithm A192KW { get; } = new KeyWrapAlgorithm(A192KWValue);
 57
 58        /// <summary>
 59        /// Gets an AES 256 Key Wrap <see cref="KeyWrapAlgorithm"/>.
 60        /// </summary>
 1461        public static KeyWrapAlgorithm A256KW { get; } = new KeyWrapAlgorithm(A256KWValue);
 62
 63        /// <summary>
 64        /// Determines if two <see cref="KeyWrapAlgorithm"/> values are the same.
 65        /// </summary>
 66        /// <param name="left">The first <see cref="KeyWrapAlgorithm"/> to compare.</param>
 67        /// <param name="right">The second <see cref="KeyWrapAlgorithm"/> to compare.</param>
 68        /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are the same; otherwise, false.</retur
 069        public static bool operator ==(KeyWrapAlgorithm left, KeyWrapAlgorithm right) => left.Equals(right);
 70
 71        /// <summary>
 72        /// Determines if two <see cref="KeyWrapAlgorithm"/> values are different.
 73        /// </summary>
 74        /// <param name="left">The first <see cref="KeyWrapAlgorithm"/> to compare.</param>
 75        /// <param name="right">The second <see cref="KeyWrapAlgorithm"/> to compare.</param>
 76        /// <returns>True if <paramref name="left"/> and <paramref name="right"/> are different; otherwise, false.</retu
 077        public static bool operator !=(KeyWrapAlgorithm left, KeyWrapAlgorithm right) => !left.Equals(right);
 78
 79        /// <summary>
 80        /// Converts a string to a <see cref="KeyWrapAlgorithm"/>.
 81        /// </summary>
 82        /// <param name="value">The string value to convert.</param>
 2883        public static implicit operator KeyWrapAlgorithm(string value) => new KeyWrapAlgorithm(value);
 84
 85        /// <inheritdoc/>
 86        [EditorBrowsable(EditorBrowsableState.Never)]
 087        public override bool Equals(object obj) => obj is KeyWrapAlgorithm other && Equals(other);
 88
 89        /// <inheritdoc/>
 90        [EditorBrowsable(EditorBrowsableState.Never)]
 2491        public bool Equals(KeyWrapAlgorithm other) => string.Equals(_value, other._value, StringComparison.Ordinal);
 92
 93        /// <inheritdoc/>
 94        [EditorBrowsable(EditorBrowsableState.Never)]
 095        public override int GetHashCode() => _value?.GetHashCode() ?? 0;
 96
 97        /// <inheritdoc/>
 98        [EditorBrowsable(EditorBrowsableState.Never)]
 12099        public override string ToString() => _value;
 100
 12101        internal RSAEncryptionPadding GetRsaEncryptionPadding() => _value switch
 12102        {
 0103            Rsa15Value => RSAEncryptionPadding.Pkcs1,
 16104            RsaOaepValue => RSAEncryptionPadding.OaepSHA1,
 0105            RsaOaep256Value => RSAEncryptionPadding.OaepSHA256,
 20106            _ => null,
 12107        };
 108
 16109        internal int GetKeySizeInBits() => _value switch
 16110        {
 0111            A128KWValue => 128,
 0112            A192KWValue => 192,
 24113            A256KWValue => 256,
 24114            _ => 0,
 16115        };
 116
 16117        internal int GetKeySizeInBytes() => GetKeySizeInBits() >> 3;
 118    }
 119}