< Summary

Class:Azure.Security.KeyVault.Keys.ImportKeyOptions
Assembly:Azure.Security.KeyVault.Keys
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\ImportKeyOptions.cs
Covered lines:18
Uncovered lines:7
Coverable lines:25
Total lines:93
Line coverage:72% (18 of 25)
Covered branches:5
Total branches:10
Branch coverage:50% (5 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.cctor()-100%100%
.ctor(...)-100%100%
get_Name()-0%100%
get_Key()-100%100%
get_HardwareProtected()-0%100%
get_Properties()-100%100%
Azure.Security.KeyVault.IJsonSerializable.WriteProperties(...)-61.54%50%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Keys\src\ImportKeyOptions.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;
 7using Azure.Core;
 8
 9namespace Azure.Security.KeyVault.Keys
 10{
 11    /// <summary>
 12    /// The properties needed to import a key.
 13    /// </summary>
 14    public class ImportKeyOptions : IJsonSerializable
 15    {
 16        private const string KeyPropertyName = "key";
 17        private const string TagsPropertyName = "tags";
 18        private const string HsmPropertyName = "hsm";
 19
 220        private static readonly JsonEncodedText s_keyPropertyNameBytes = JsonEncodedText.Encode(KeyPropertyName);
 221        private static readonly JsonEncodedText s_tagsPropertyNameBytes = JsonEncodedText.Encode(TagsPropertyName);
 222        private static readonly JsonEncodedText s_hsmPropertyNameBytes = JsonEncodedText.Encode(HsmPropertyName);
 23
 24        /// <summary>
 25        /// Initializes a new instance of the <see cref="ImportKeyOptions"/> class.
 26        /// </summary>
 27        /// <param name="name">The name of the key to import.</param>
 28        /// <param name="keyMaterial">A <see cref="JsonWebKey"/> containing properties of the key to import.</param>
 29        /// <exception cref="ArgumentException"><paramref name="name"/> is an empty string.</exception>
 30        /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="keyMaterial"/> is null.</
 3631        public ImportKeyOptions(string name, JsonWebKey keyMaterial)
 32        {
 3633            Argument.AssertNotNull(keyMaterial, nameof(keyMaterial));
 34
 3635            Properties = new KeyProperties(name);
 3636            Key = keyMaterial;
 3637        }
 38
 39        /// <summary>
 40        /// Gets the name of the key to import.
 41        /// </summary>
 042        public string Name => Properties.Name;
 43
 44        /// <summary>
 45        /// Gets the cryptographic key, the key type, and the operations you can perform using the key.
 46        /// </summary>
 47        /// <remarks>
 48        /// See http://tools.ietf.org/html/draft-ietf-jose-json-web-key-18 for specifications of a JSON web key.
 49        /// </remarks>
 7250        public JsonWebKey Key { get; }
 51
 52        /// <summary>
 53        /// Gets or sets a value indicating whether to import the key into a hardware security module (HSM).
 54        /// </summary>
 055        public bool? HardwareProtected { get; set; }
 56
 57        /// <summary>
 58        /// Gets additional properties of the <see cref="KeyVaultKey"/>.
 59        /// </summary>
 7260        public KeyProperties Properties { get; }
 61
 62        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
 63        {
 3664            if (Key != null)
 65            {
 3666                json.WriteStartObject(s_keyPropertyNameBytes);
 67
 3668                Key.WriteProperties(json);
 69
 3670                json.WriteEndObject();
 71            }
 72
 3673            Properties.WriteAttributes(json);
 74
 3675            if (Properties._tags != null && Properties._tags.Count > 0)
 76            {
 077                json.WriteStartObject(s_tagsPropertyNameBytes);
 78
 079                foreach (KeyValuePair<string, string> kvp in Properties._tags)
 80                {
 081                    json.WriteString(kvp.Key, kvp.Value);
 82                }
 83
 084                json.WriteEndObject();
 85            }
 86
 3687            if (HardwareProtected.HasValue)
 88            {
 089                json.WriteBoolean(s_hsmPropertyNameBytes, HardwareProtected.Value);
 90            }
 3691        }
 92    }
 93}