Loading [MathJax]/extensions/tex2jax.js
azure-storage-common
All Classes Functions Variables Pages
shared_key_policy.hpp
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6#include "azure/storage/common/storage_credential.hpp"
7
8#include <azure/core/http/policies/policy.hpp>
9
10#include <memory>
11#include <string>
12
13namespace Azure { namespace Storage { namespace _internal {
14
15 class SharedKeyPolicy final : public Core::Http::Policies::HttpPolicy {
16 public:
17 explicit SharedKeyPolicy(std::shared_ptr<StorageSharedKeyCredential> credential)
18 : m_credential(std::move(credential))
19 {
20 }
21
22 ~SharedKeyPolicy() override {}
23
24 std::unique_ptr<HttpPolicy> Clone() const override
25 {
26 return std::make_unique<SharedKeyPolicy>(m_credential);
27 }
28
29 std::unique_ptr<Core::Http::RawResponse> Send(
30 Core::Http::Request& request,
31 Core::Http::Policies::NextHttpPolicy nextPolicy,
32 Core::Context const& context) const override
33 {
34 request.SetHeader(
35 "Authorization", "SharedKey " + m_credential->AccountName + ":" + GetSignature(request));
36 return nextPolicy.Send(request, context);
37 }
38
39 private:
40 std::string GetSignature(const Core::Http::Request& request) const;
41
42 std::shared_ptr<StorageSharedKeyCredential> m_credential;
43 };
44
45}}} // namespace Azure::Storage::_internal