< Summary

Class:Azure.Security.KeyVault.Keys.KeyRequestParameters
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\KeyRequestParameters.cs
Covered lines:68
Uncovered lines:2
Coverable lines:70
Total lines:152
Line coverage:97.1% (68 of 70)
Covered branches:51
Total branches:52
Branch coverage:98% (51 of 52)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
get_KeyType()-100%100%
get_KeySize()-100%100%
get_Attributes()-0%100%
get_KeyOperations()-100%100%
get_Enabled()-100%100%
get_NotBefore()-100%100%
get_Expires()-100%100%
get_Tags()-100%100%
get_Curve()-100%100%
.ctor(...)-91.67%91.67%
.ctor(...)-100%100%
.ctor(...)-100%100%
.ctor(...)-100%100%
Azure.Security.KeyVault.IJsonSerializable.WriteProperties(...)-100%100%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Text.Json;
 7
 8namespace Azure.Security.KeyVault.Keys
 9{
 10    internal class KeyRequestParameters : IJsonSerializable
 11    {
 12        private const string KeyTypePropertyName = "kty";
 13        private const string KeySizePropertyName = "key_size";
 14        private const string KeyOpsPropertyName = "key_ops";
 15        private const string CurveNamePropertyName = "crv";
 16        private const string AttributesPropertyName = "attributes";
 17        private const string TagsPropertyName = "tags";
 18
 219        private static readonly JsonEncodedText s_keyTypePropertyNameBytes = JsonEncodedText.Encode(KeyTypePropertyName)
 220        private static readonly JsonEncodedText s_keySizePropertyNameBytes = JsonEncodedText.Encode(KeySizePropertyName)
 221        private static readonly JsonEncodedText s_keyOpsPropertyNameBytes = JsonEncodedText.Encode(KeyOpsPropertyName);
 222        private static readonly JsonEncodedText s_curveNamePropertyNameBytes = JsonEncodedText.Encode(CurveNamePropertyN
 223        private static readonly JsonEncodedText s_attributesPropertyNameBytes = JsonEncodedText.Encode(AttributesPropert
 224        private static readonly JsonEncodedText s_tagsPropertyNameBytes = JsonEncodedText.Encode(TagsPropertyName);
 25
 26        private KeyAttributes _attributes;
 27
 103228        public KeyType KeyType { get; set; }
 40029        public int? KeySize { get; set; }
 030        public KeyAttributes Attributes { get; set; }
 49631        public IList<KeyOperation> KeyOperations { get; set; }
 46832        public bool? Enabled { get => _attributes.Enabled; set => _attributes.Enabled = value; }
 32033        public DateTimeOffset? NotBefore { get => _attributes.NotBefore; set => _attributes.NotBefore = value; }
 35634        public DateTimeOffset? Expires { get => _attributes.ExpiresOn; set => _attributes.ExpiresOn = value; }
 46435        public IDictionary<string, string> Tags { get; set; }
 51236        public KeyCurveName? Curve { get; set; }
 37
 7238        internal KeyRequestParameters(KeyProperties key, IEnumerable<KeyOperation> operations)
 39        {
 7240            if (key.Enabled.HasValue)
 41            {
 7242                Enabled = key.Enabled.Value;
 43            }
 7244            if (key.ExpiresOn.HasValue)
 45            {
 3646                Expires = key.ExpiresOn.Value;
 47            }
 7248            if (key.NotBefore.HasValue)
 49            {
 050                NotBefore = key.NotBefore.Value;
 51            }
 7252            if (key.Tags != null && key.Tags.Count > 0)
 53            {
 2454                Tags = new Dictionary<string, string>(key.Tags);
 55            }
 7256            if (operations != null)
 57            {
 3658                KeyOperations = new List<KeyOperation>(operations);
 59            }
 7260        }
 61
 32062        internal KeyRequestParameters(KeyType type, CreateKeyOptions options = default)
 63        {
 32064            KeyType = type;
 32065            if (options != null)
 66            {
 15667                if (options.Enabled.HasValue)
 68                {
 469                    Enabled = options.Enabled.Value;
 70                }
 15671                if (options.ExpiresOn.HasValue)
 72                {
 473                    Expires = options.ExpiresOn.Value;
 74                }
 15675                if (options.NotBefore.HasValue)
 76                {
 477                    NotBefore = options.NotBefore.Value;
 78                }
 15679                if (options.KeyOperations != null && options.KeyOperations.Count > 0)
 80                {
 1681                    KeyOperations = new List<KeyOperation>(options.KeyOperations);
 82                }
 15683                if (options.Tags != null && options.Tags.Count > 0)
 84                {
 1285                    Tags = new Dictionary<string, string>(options.Tags);
 86                }
 87            }
 32088        }
 89
 90        internal KeyRequestParameters(CreateEcKeyOptions ecKey)
 10891            : this(ecKey.KeyType, ecKey)
 92        {
 10893            if (ecKey.CurveName.HasValue)
 94            {
 6095                Curve = ecKey.CurveName.Value;
 96            }
 10897        }
 98
 99        internal KeyRequestParameters(CreateRsaKeyOptions rsaKey)
 44100            : this(rsaKey.KeyType, rsaKey)
 101        {
 44102            if (rsaKey.KeySize.HasValue)
 103            {
 4104                KeySize = rsaKey.KeySize.Value;
 105            }
 44106        }
 107
 108        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 109        {
 392110            if (KeyType != default)
 111            {
 320112                json.WriteString(s_keyTypePropertyNameBytes, KeyType.ToString());
 113            }
 392114            if (KeySize.HasValue)
 115            {
 4116                json.WriteNumber(s_keySizePropertyNameBytes, KeySize.Value);
 117            }
 392118            if (Curve.HasValue)
 119            {
 60120                json.WriteString(s_curveNamePropertyNameBytes, Curve.Value.ToString());
 121            }
 392122            if (Enabled.HasValue || NotBefore.HasValue || Expires.HasValue)
 123            {
 76124                json.WriteStartObject(s_attributesPropertyNameBytes);
 125
 76126                _attributes.WriteProperties(json);
 127
 76128                json.WriteEndObject();
 129            }
 392130            if (!KeyOperations.IsNullOrEmpty())
 131            {
 52132                json.WriteStartArray(s_keyOpsPropertyNameBytes);
 344133                foreach (KeyOperation operation in KeyOperations)
 134                {
 120135                    json.WriteStringValue(operation.ToString());
 136                }
 52137                json.WriteEndArray();
 138            }
 392139            if (!Tags.IsNullOrEmpty())
 140            {
 36141                json.WriteStartObject(s_tagsPropertyNameBytes);
 142
 216143                foreach (KeyValuePair<string, string> kvp in Tags)
 144                {
 72145                    json.WriteString(kvp.Key, kvp.Value);
 146                }
 147
 36148                json.WriteEndObject();
 149            }
 392150        }
 151    }
 152}