< Summary

Class:Azure.Storage.StorageSharedKeyCredential
Assembly:Azure.Storage.Common
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\StorageSharedKeyCredential.cs
Covered lines:12
Uncovered lines:0
Coverable lines:12
Total lines:78
Line coverage:100% (12 of 12)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_AccountName()-100%100%
get_AccountKeyValue()-100%100%
set_AccountKeyValue(...)-100%100%
.ctor(...)-100%100%
SetAccountKey(...)-100%100%
ComputeHMACSHA256(...)-100%100%
ComputeSasSignature(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\StorageSharedKeyCredential.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Security.Cryptography;
 6using System.Text;
 7using System.Threading;
 8
 9namespace Azure.Storage
 10{
 11    /// <summary>
 12    /// A <see cref="StorageSharedKeyCredential"/> is a credential backed by
 13    /// a Storage Account's name and one of its access keys.
 14    /// </summary>
 15    public class StorageSharedKeyCredential
 16    {
 17        /// <summary>
 18        /// Gets the name of the Storage Account.
 19        /// </summary>
 8070820        public string AccountName { get; }
 21
 22        /// <summary>
 23        /// The value of a Storage Account access key.
 24        /// </summary>
 25        private byte[] _accountKeyValue;
 26
 27        /// <summary>
 28        /// Gets the value of a Storage Account access key.
 29        /// </summary>
 30        private byte[] AccountKeyValue
 31        {
 4060632            get => Volatile.Read(ref _accountKeyValue);
 835733            set => Volatile.Write(ref _accountKeyValue, value);
 34        }
 35
 36        /// <summary>
 37        /// Initializes a new instance of the
 38        /// <see cref="StorageSharedKeyCredential"/> class.
 39        /// </summary>
 40        /// <param name="accountName">The name of the Storage Account.</param>
 41        /// <param name="accountKey">A Storage Account access key.</param>
 834142        public StorageSharedKeyCredential(
 834143            string accountName,
 834144            string accountKey)
 45        {
 834146            AccountName = accountName;
 834147            SetAccountKey(accountKey);
 834148        }
 49
 50        /// <summary>
 51        /// Update the Storage Account's access key.  This intended to be used
 52        /// when you've regenerated your Storage Account's access keys and want
 53        /// to update long lived clients.
 54        /// </summary>
 55        /// <param name="accountKey">A Storage Account access key.</param>
 56        public void SetAccountKey(string accountKey) =>
 835757            AccountKeyValue = Convert.FromBase64String(accountKey);
 58
 59        /// <summary>
 60        /// Generates a base-64 hash signature string for an HTTP request or
 61        /// for a SAS.
 62        /// </summary>
 63        /// <param name="message">The message to sign.</param>
 64        /// <returns>The signed message.</returns>
 65        internal string ComputeHMACSHA256(string message) =>
 4053666            Convert.ToBase64String(new HMACSHA256(AccountKeyValue).ComputeHash(Encoding.UTF8.GetBytes(message)));
 67
 68        /// <summary>
 69        /// Generates a base-64 hash signature string for an HTTP request or
 70        /// for a SAS.
 71        /// </summary>
 72        /// <param name="credential">The credential.</param>
 73        /// <param name="message">The message to sign.</param>
 74        /// <returns>The signed message.</returns>
 75        protected static string ComputeSasSignature(StorageSharedKeyCredential credential, string message) =>
 4040476            credential.ComputeHMACSHA256(message);
 77    }
 78}