Kv cleanup (#6519)

* Certs stage1

* keys part 1

* screts part 1

* Keys part2

* keys step3

* QFT

* clang

* Preserve Cert order

* recored tests add checks for preserve
This commit is contained in:
gearama 2025-04-14 10:46:16 -07:00 committed by GitHub
parent 27c2e5d335
commit 45c02dc359
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 106 additions and 1706 deletions

View File

@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/keyvault",
"Tag": "cpp/keyvault_963756fe61"
"Tag": "cpp/keyvault_b73050ec79"
}

View File

@ -82,10 +82,8 @@ set(
src/certificate_client_models.cpp
src/certificate_client_operations.cpp
src/certificate_client_paged_response.cpp
src/keyvault_certificates_common_request.cpp
src/private/certificate_constants.hpp
src/private/certificate_serializers.hpp
src/private/keyvault_certificates_common_request.hpp
src/private/package_version.hpp
#generated code
src/generated/certificates_models.hpp

View File

@ -144,6 +144,13 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
*/
Azure::Nullable<bool> Enabled;
/**
* @brief Specifies whether the certificate chain preserves its original order. The default
* value is false, which sets the leaf certificate at index 0.
*
*/
Azure::Nullable<bool> PreserveCertificateOrder;
/**
* @brief Construct a new Certificate Properties object
*
@ -1260,6 +1267,13 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
*/
Azure::Nullable<ServerError> Error;
/**
* @brief Specifies whether the certificate chain preserves its original order. The default
* value is false, which sets the leaf certificate at index 0.
*
*/
Azure::Nullable<bool> PreserveCertificateOrder;
~CertificateOperationProperties() = default;
/**
* @brief Default constructor.

View File

@ -29,7 +29,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
* @brief Service Version used.
*
*/
std::string ApiVersion{"7.5"};
std::string ApiVersion{"7.6-preview.2"};
};
}}}} // namespace Azure::Security::KeyVault::Certificates

View File

@ -8,7 +8,6 @@
#include "generated/key_vault_client.hpp"
#include "private/certificate_constants.hpp"
#include "private/certificate_serializers.hpp"
#include "private/keyvault_certificates_common_request.hpp"
#include "private/package_version.hpp"
#include <azure/core/credentials/credentials.hpp>
@ -28,7 +27,6 @@ using namespace Azure::Core::Http;
using namespace Azure::Core::Http::Policies;
using namespace Azure::Core::Http::Policies::_internal;
using namespace Azure::Core::Http::_internal;
using namespace Azure::Security::KeyVault::_detail;
CertificateClient::CertificateClient(
std::string const& vaultUrl,

View File

@ -113,6 +113,8 @@ CertificateProperties::CertificateProperties(
{
X509Thumbprint = bundle.X509Thumbprint.Value();
}
PreserveCertificateOrder = bundle.PreserveCertOrder;
}
CertificateProperties::CertificateProperties(_detail::Models::CertificateItem const& item)
@ -167,6 +169,7 @@ CertificateProperties::CertificateProperties(_detail::Models::CertificateBundle
{
X509Thumbprint = bundle.X509Thumbprint.Value();
}
PreserveCertificateOrder = bundle.PreserveCertOrder;
}
_detail::Models::CertificateUpdateParameters CertificateProperties::ToCertificateUpdateParameters()
@ -672,6 +675,7 @@ DeletedCertificate::DeletedCertificate(_detail::Models::DeletedCertificateBundle
{
ScheduledPurgeDate = bundle.ScheduledPurgeDate.Value();
}
Properties.PreserveCertificateOrder = bundle.PreserveCertOrder;
}
DeletedCertificate::DeletedCertificate(_detail::Models::DeletedCertificateItem const& item)
{
@ -748,7 +752,7 @@ ImportCertificateOptions::ToCertificateImportParameters()
parameters.CertificateAttributes = attributes;
}
parameters.CertificatePolicy = Policy.ToCertificatePolicy();
// parameters.PreserveCertOrder;
parameters.PreserveCertOrder = Properties.PreserveCertificateOrder;
return parameters;
}
@ -779,6 +783,7 @@ CertificateCreateOptions::ToCertificateCreateParameters()
attributes.Updated = Properties.UpdatedOn;
parameters.CertificateAttributes = attributes;
}
parameters.PreserveCertOrder = Properties.PreserveCertificateOrder;
return parameters;
}
@ -831,11 +836,7 @@ CertificateOperationProperties::CertificateOperationProperties(
Error.Value().Message = operation.Error.Value().Message.Value();
}
}
/*if (operation.PreserveCertOrder.HasValue())
{
PreserveCertOrder = operation.PreserveCertOrder.Value();
}*/
PreserveCertificateOrder = operation.PreserveCertOrder;
}
CertificateIssuerItem::CertificateIssuerItem(_detail::Models::CertificateIssuerItem const& item)

View File

@ -1,60 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "private/keyvault_certificates_common_request.hpp"
#include <azure/core/exception.hpp>
#include <azure/core/http/http.hpp>
#include <memory>
using namespace Azure::Security::KeyVault;
using namespace Azure::Core::Http::_internal;
std::unique_ptr<Azure::Core::Http::RawResponse>
_detail::KeyVaultCertificatesCommonRequest::SendRequest(
Azure::Core::Http::_internal::HttpPipeline const& pipeline,
Azure::Core::Http::Request& request,
Azure::Core::Context const& context)
{
auto response = pipeline.Send(request, context);
auto responseCode = response->GetStatusCode();
switch (responseCode)
{
// 200, 201, 202, 204 are accepted responses
case Azure::Core::Http::HttpStatusCode::Ok:
case Azure::Core::Http::HttpStatusCode::Created:
case Azure::Core::Http::HttpStatusCode::Accepted:
case Azure::Core::Http::HttpStatusCode::NoContent:
break;
default:
throw Azure::Core::RequestFailedException(response);
}
return response;
}
Azure::Core::Http::Request _detail::KeyVaultCertificatesCommonRequest::CreateRequest(
Azure::Core::Url url,
std::string const& apiVersion,
Azure::Core::Http::HttpMethod method,
std::vector<std::string> const& path,
Azure::Core::IO::BodyStream* content)
{
using namespace Azure::Core::Http;
Request request = content == nullptr ? Request(std::move(method), std::move(url))
: Request(std::move(method), std::move(url), content);
request.SetHeader(ContentHeaderName, ApplicationJsonValue);
request.GetUrl().AppendQueryParameter(ApiVersionQueryParamName, apiVersion);
for (std::string const& p : path)
{
if (!p.empty())
{
request.GetUrl().AppendPath(p);
}
}
return request;
}

View File

@ -11,71 +11,6 @@
namespace Azure { namespace Security { namespace KeyVault { namespace Certificates {
namespace _detail {
/***************** Certificates Requests *****************/
constexpr static const char KeyVaultServicePackageName[] = "keyvault-certificates";
constexpr static const char CertificatesPath[] = "certificates";
constexpr static const char CertificatesCreatePath[] = "create";
constexpr static const char IssuersPath[] = "issuers";
constexpr static const char ContactsPath[] = "contacts";
constexpr static const char PendingPath[] = "pending";
constexpr static const char DeletedCertificatesPath[] = "deletedcertificates";
constexpr static const char RecoverPath[] = "recover";
constexpr static const char PolicyPath[] = "policy";
constexpr static const char BackupPath[] = "backup";
constexpr static const char RestorePath[] = "restore";
constexpr static const char IncludePendingQuery[] = "includePending";
constexpr static const char VersionsPath[] = "versions";
constexpr static const char ImportPath[] = "import";
constexpr static const char MergePath[] = "merge";
/***************** Certificates Properties *****************/
constexpr static const char IdName[] = "id";
constexpr static const char X5tName[] = "x5t";
constexpr static const char TagsPropertyName[] = "tags";
constexpr static const char AttributesPropertyName[] = "attributes";
constexpr static const char EnabledPropertyName[] = "enabled";
constexpr static const char NbfPropertyName[] = "nbf";
constexpr static const char ExpPropertyName[] = "exp";
constexpr static const char CreatedPropertyName[] = "created";
constexpr static const char UpdatedPropertyName[] = "updated";
constexpr static const char RecoverableDaysPropertyName[] = "recoverableDays";
constexpr static const char RecoveryLevelPropertyName[] = "recoveryLevel";
constexpr static const char KidPropertyName[] = "kid";
constexpr static const char SidPropertyName[] = "sid";
constexpr static const char CerPropertyName[] = "cer";
/***************** Certificates Policy *****************/
// cspell: ignore ekus upns
constexpr static const char PolicyPropertyName[] = "policy";
constexpr static const char KeyPropsPropertyName[] = "key_props";
constexpr static const char KeyTypePropertyName[] = "kty";
constexpr static const char ReuseKeyPropertyName[] = "reuse_key";
constexpr static const char ExportablePropertyName[] = "exportable";
constexpr static const char CurveNamePropertyName[] = "crv";
constexpr static const char KeySizePropertyName[] = "key_size";
constexpr static const char SecretPropsPropertyName[] = "secret_props";
constexpr static const char ContentTypePropertyName[] = "contentType";
constexpr static const char X509PropsPropertyName[] = "x509_props";
constexpr static const char SubjectPropertyName[] = "subject";
constexpr static const char SansPropertyName[] = "sans";
constexpr static const char DnsPropertyName[] = "dns_names";
constexpr static const char EmailsPropertyName[] = "emails";
constexpr static const char UserPrincipalNamesPropertyName[] = "upns";
constexpr static const char KeyUsagePropertyName[] = "key_usage";
constexpr static const char EkusPropertyName[] = "ekus";
constexpr static const char ValidityMonthsPropertyName[] = "validity_months";
constexpr static const char IssuerPropertyName[] = "issuer";
constexpr static const char CertTransparencyPropertyName[] = "cert_transparency";
constexpr static const char CtyPropertyName[] = "cty";
constexpr static const char IssuerNamePropertyName[] = "name";
constexpr static const char LifetimeActionsPropertyName[] = "lifetime_actions";
constexpr static const char TriggerPropertyName[] = "trigger";
constexpr static const char ActionPropertyName[] = "action";
constexpr static const char LifetimePercentagePropertyName[] = "lifetime_percentage";
constexpr static const char DaysBeforeExpiryPropertyName[] = "days_before_expiry";
constexpr static const char ActionTypePropertyName[] = "action_type";
/***************** Certificates Key Usage *****************/
constexpr static const char DigitalSignatureValue[] = "digitalSignature";
constexpr static const char NonRepudiationValue[] = "nonRepudiation";
@ -107,51 +42,8 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Certificat
constexpr static const char AutoRenewValue[] = "AutoRenew";
constexpr static const char EmailContactsValue[] = "EmailContacts";
/***************** Certificates Issuer Action *****************/
constexpr static const char CredentialsPropertyValue[] = "credentials";
constexpr static const char AccountIdValue[] = "account_id";
constexpr static const char PwdPropertyValue[] = "pwd";
constexpr static const char ProviderPropertyValue[] = "provider";
constexpr static const char OrgDetailsPropertyValue[] = "org_details";
constexpr static const char AdminDetailsPropertyValue[] = "admin_details";
constexpr static const char FirstNamePropertyValue[] = "first_name";
constexpr static const char LastNamePropertyValue[] = "last_name";
constexpr static const char EmailPropertyValue[] = "email";
constexpr static const char PhonePropertyValue[] = "phone";
/***************** Certificates Contact *****************/
constexpr static const char EmailPropertyName[] = "email";
constexpr static const char NamePropertyName[] = "name";
constexpr static const char PhonePropertyName[] = "phone";
constexpr static const char ContactsPropertyName[] = "contacts";
/****************** Certificate Operation Properties **********/
constexpr static const char CsrPropertyName[] = "csr";
constexpr static const char StatusPropertyName[] = "status";
constexpr static const char ErrorPropertyName[] = "error";
constexpr static const char CodePropertyName[] = "code";
constexpr static const char RequestIdPropertyName[] = "request_id";
constexpr static const char TargetPropertyName[] = "target";
constexpr static const char MessagePropertyName[] = "message";
constexpr static const char InnerErrorPropertyName[] = "innererror";
constexpr static const char StatusDetailsPropertyName[] = "status_details";
constexpr static const char CancelationRequestedPropertyName[] = "cancellation_requested";
constexpr static const char CompletedValue[] = "completed";
constexpr static const char DeletedValue[] = "deleted";
/**************** Deleted Certificate property names ********/
constexpr static const char RecoveryIdPropertyName[] = "recoveryId";
constexpr static const char ScheduledPurgeDatePropertyName[] = "scheduledPurgeDate";
constexpr static const char DeletedDatePropertyName[] = "deletedDate";
/****************** Certificate Backup/Restore Properties **********/
constexpr static const char ValuePropertyName[] = "value";
/****************** Paged Properties **********/
constexpr static const char TrueQueryValue[] = "true";
constexpr static const char FalseQueryValue[] = "false";
constexpr static const char NextLinkPropertyName[] = "nextLink";
/****************** Certificate Backup/Restore Properties **********/
constexpr static const char X5cPropertyName[] = "x5c";
}}}}} // namespace Azure::Security::KeyVault::Certificates::_detail

View File

@ -1,44 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @brief Provides a wrapper class for the Azure Core Pipeline for all Key Vault services where
* common functionality is set up.
*
*/
#pragma once
#include <azure/core/context.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/internal/http/pipeline.hpp>
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_serializable.hpp>
#include <azure/core/response.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace _detail {
constexpr static const char ContentHeaderName[] = "content-type";
constexpr static const char ApplicationJsonValue[] = "application/json";
constexpr static const char ApiVersionQueryParamName[] = "api-version";
struct KeyVaultCertificatesCommonRequest final
{
static Azure::Core::Http::Request CreateRequest(
Azure::Core::Url url,
std::string const& apiVersion,
Azure::Core::Http::HttpMethod method,
std::vector<std::string> const& path,
Azure::Core::IO::BodyStream* content);
static std::unique_ptr<Azure::Core::Http::RawResponse> SendRequest(
Azure::Core::Http::_internal::HttpPipeline const& pipeline,
Azure::Core::Http::Request& request,
Azure::Core::Context const& context);
};
}}}} // namespace Azure::Security::KeyVault::_detail

View File

@ -205,7 +205,7 @@ namespace Azure {
action.LifetimePercentage = 80;
action.Action = CertificatePolicyAction::AutoRenew;
options.Policy.LifetimeActions.emplace_back(action);
options.Properties.PreserveCertificateOrder = true;
auto response = client.StartCreateCertificate(name, options);
auto pollResult = response.PollUntilDone(defaultWait);
EXPECT_TRUE(pollResult.Value.Status.HasValue());
@ -228,6 +228,7 @@ namespace Azure {
result.Value.Policy.LifetimeActions[0].LifetimePercentage.Value(),
action.LifetimePercentage.Value());
EXPECT_EQ(result.Value.Policy.KeyUsage.size(), size_t(2));
EXPECT_TRUE(result.Value.Properties.PreserveCertificateOrder.Value());
auto keyUsage = result.Value.Policy.KeyUsage;
EXPECT_TRUE(
(keyUsage[0] == CertificateKeyUsage::DigitalSignature

View File

@ -71,8 +71,7 @@ TEST_F(KeyVaultCertificateClientTest, CreateCertificateResumeToken)
result = fromToken.PollUntilDone(m_defaultWait);
auto cert = client.GetCertificate(certificateName);
// TODO: 6510
// EXPECT_EQ(cert.Value.Name(), options.Properties.Name);
EXPECT_EQ(cert.Value.Properties.Enabled.Value(), true);
}
}
@ -86,7 +85,6 @@ TEST_F(KeyVaultCertificateClientTest, GetCertificate)
auto cert = CreateCertificate(certificateName, client, m_defaultWait);
EXPECT_EQ(cert.Name(), cert.Properties.Name);
// EXPECT_EQ(cert.Properties.Name, certificateName);
// x5t
EXPECT_NE(cert.Properties.X509Thumbprint.size(), 0);
@ -788,14 +786,15 @@ TEST_F(KeyVaultCertificateClientTest, DownloadImportPkcs)
options.Policy.ContentType = CertificateContentType::Pkcs12;
options.Policy.Exportable = true;
options.Properties.Name = importName;
options.Properties.PreserveCertificateOrder = true;
auto imported = client.ImportCertificate(importName, options).Value;
// TODO: 6510
// EXPECT_EQ(imported.Properties.Name, importName);
EXPECT_EQ(imported.Policy.ContentType.Value(), originalCertificate.Policy.ContentType.Value());
EXPECT_EQ(imported.Policy.Enabled.Value(), originalCertificate.Policy.Enabled.Value());
EXPECT_EQ(imported.Policy.KeySize.Value(), originalCertificate.Policy.KeySize.Value());
EXPECT_EQ(imported.Policy.Subject, originalCertificate.Policy.Subject);
EXPECT_EQ(imported.Cer, originalCertificate.Cer);
EXPECT_TRUE(imported.Properties.PreserveCertificateOrder.Value());
}
}
@ -820,14 +819,15 @@ TEST_F(KeyVaultCertificateClientTest, DownloadImportPem)
options.Policy.ContentType = CertificateContentType::Pem;
options.Policy.Exportable = true;
options.Properties.Name = importName;
options.Properties.PreserveCertificateOrder = true;
auto imported = client.ImportCertificate(importName, options).Value;
// TODO: 6510
// EXPECT_EQ(imported.Properties.Name, importName);
EXPECT_EQ(imported.Policy.ContentType.Value(), originalCertificate.Policy.ContentType.Value());
EXPECT_EQ(imported.Policy.Enabled.Value(), originalCertificate.Policy.Enabled.Value());
EXPECT_EQ(imported.Policy.KeySize.Value(), originalCertificate.Policy.KeySize.Value());
EXPECT_EQ(imported.Policy.Subject, originalCertificate.Policy.Subject);
EXPECT_EQ(imported.Cer, originalCertificate.Cer);
EXPECT_TRUE(imported.Properties.PreserveCertificateOrder.Value());
}
{
auto response = client.StartDeleteCertificate(pem);
@ -919,7 +919,7 @@ TEST_F(KeyVaultCertificateClientTest, ServiceVersion)
// Default - 7.5
EXPECT_NO_THROW(auto options = CertificateClientOptions(); CertificateClient certificateClient(
"http://account.vault.azure.net", credential, options);
EXPECT_EQ(options.ApiVersion, "7.5"););
EXPECT_EQ(options.ApiVersion, "7.6-preview.2"););
// 7.4
EXPECT_NO_THROW(

View File

@ -95,24 +95,14 @@ set(
src/cryptography/verify_result.cpp
src/cryptography/wrap_result.cpp
src/delete_key_operation.cpp
src/deleted_key.cpp
src/import_key_options.cpp
src/json_web_key.cpp
src/key_backup.cpp
src/key_client.cpp
src/key_client_models.cpp
src/key_client_options.cpp
src/key_client_paged_responses.cpp
src/key_curve_name.cpp
src/key_encryption_algorithm.cpp
src/key_get_random_bytes.cpp
src/key_operation.cpp
src/key_release_options.cpp
src/key_release_policy.cpp
src/key_request_parameters.cpp
src/key_rotation_policy.cpp
src/key_type.cpp
src/keyvault_key.cpp
src/keyvault_protocol.cpp
src/generated/get_deleted_keys_paged_response.cpp
src/generated/get_keys_paged_response.cpp
@ -125,9 +115,7 @@ set(
src/generated/key_vault_client_paged_responses.hpp
src/private/cryptography_internal_access.hpp
src/private/cryptography_serializers.hpp
src/private/key_backup.hpp
src/private/key_constants.hpp
src/private/key_request_parameters.hpp
src/private/key_serializers.hpp
src/private/key_sign_parameters.hpp
src/private/key_verify_parameters.hpp

View File

@ -19,35 +19,35 @@ Azure::Security::KeyVault::Keys::DeleteKeyOperation::PollInternal(
try
{
rawResponse = m_keyClient->GetDeletedKey(m_value.Name(), context).RawResponse;
auto result = m_keyClient->GetDeletedKey(m_value.Name(), context);
rawResponse = std::move(result.RawResponse);
switch (rawResponse->GetStatusCode())
{
case Azure::Core::Http::HttpStatusCode::Ok:
case Azure::Core::Http::HttpStatusCode::Forbidden: // Access denied but proof the key was
// deleted.
{
m_status = Azure::Core::OperationStatus::Succeeded;
break;
}
case Azure::Core::Http::HttpStatusCode::NotFound: {
m_status = Azure::Core::OperationStatus::Running;
break;
}
default:
throw Azure::Core::RequestFailedException(rawResponse);
}
if (m_status == Azure::Core::OperationStatus::Succeeded)
{
m_value = std::move(result.Value);
}
}
catch (Azure::Core::RequestFailedException& error)
{
rawResponse = std::move(error.RawResponse);
}
switch (rawResponse->GetStatusCode())
{
case Azure::Core::Http::HttpStatusCode::Ok:
case Azure::Core::Http::HttpStatusCode::Forbidden: // Access denied but proof the key was
// deleted.
{
m_status = Azure::Core::OperationStatus::Succeeded;
break;
}
case Azure::Core::Http::HttpStatusCode::NotFound: {
m_status = Azure::Core::OperationStatus::Running;
break;
}
default:
throw Azure::Core::RequestFailedException(rawResponse);
}
if (m_status == Azure::Core::OperationStatus::Succeeded)
{
m_value = _detail::DeletedKeySerializer::DeletedKeyDeserialize(m_value.Name(), *rawResponse);
}
// To ensure the success of calling Poll multiple times, even after operation is completed, a
// copy of the raw HTTP response is returned instead of transferring the ownership of the raw
// response inside the Operation.

View File

@ -1,50 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_models.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_optional.hpp>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::Json::_internal;
using Azure::Core::_internal::PosixTimeConverter;
DeletedKey _detail::DeletedKeySerializer::DeletedKeyDeserialize(
std::string const& name,
Azure::Core::Http::RawResponse const& rawResponse)
{
auto body = rawResponse.GetBody();
auto jsonParser = Azure::Core::Json::_internal::json::parse(body);
// "Key"
DeletedKey deletedKey(name);
_detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(deletedKey, rawResponse);
// recoveryId
// deletedDate
// scheduledPurgeDate
if (!jsonParser[_detail::RecoveryIdPropertyName].is_null())
{
deletedKey.RecoveryId = jsonParser[_detail::RecoveryIdPropertyName].get<std::string>();
}
if (!jsonParser[_detail::RecoveryLevelPropertyName].is_null())
{
deletedKey.Properties.RecoveryLevel
= jsonParser[_detail::RecoveryLevelPropertyName].get<std::string>();
}
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
deletedKey.DeletedDate,
jsonParser,
_detail::DeletedOnPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
deletedKey.ScheduledPurgeDate,
jsonParser,
_detail::ScheduledPurgeDatePropertyName,
PosixTimeConverter::PosixTimeToDateTime);
return deletedKey;
}

View File

@ -1,79 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_options.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_optional.hpp>
#include <string>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Security::KeyVault::Keys::_detail;
using namespace Azure::Core::Json::_internal;
std::string
Azure::Security::KeyVault::Keys::_detail::ImportKeyOptionsSerializer::ImportKeyOptionsSerialize(
ImportKeyOptions const& importKeyOptions)
{
using Azure::Core::_internal::PosixTimeConverter;
Azure::Core::Json::_internal::json payload;
// key
JsonWebKeySerializer::JsonWebKeySerialize(
importKeyOptions.Key, payload[_detail::KeyPropertyName]);
// hsm
JsonOptional::SetFromNullable(
importKeyOptions.HardwareProtected, payload, _detail::HsmPropertyName);
// attributes
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
importKeyOptions.Properties.CreatedOn,
payload[_detail::AttributesPropertyName],
_detail::CreatedPropertyName,
PosixTimeConverter::DateTimeToPosixTime);
JsonOptional::SetFromNullable(
importKeyOptions.Properties.Enabled,
payload[_detail::AttributesPropertyName],
_detail::EnabledPropertyName);
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
importKeyOptions.Properties.ExpiresOn,
payload[_detail::AttributesPropertyName],
_detail::ExpPropertyName,
PosixTimeConverter::DateTimeToPosixTime);
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
importKeyOptions.Properties.NotBefore,
payload[_detail::AttributesPropertyName],
_detail::NbfPropertyName,
PosixTimeConverter::DateTimeToPosixTime);
JsonOptional::SetFromNullable(
importKeyOptions.Properties.RecoverableDays,
payload[_detail::AttributesPropertyName],
_detail::RecoverableDaysPropertyName);
payload[_detail::RecoveryLevelPropertyName] = importKeyOptions.Properties.RecoveryLevel;
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
importKeyOptions.Properties.UpdatedOn,
payload[_detail::AttributesPropertyName],
_detail::UpdatedPropertyName,
PosixTimeConverter::DateTimeToPosixTime);
// tags
for (auto& tag : importKeyOptions.Properties.Tags)
{
payload[_detail::TagsPropertyName][tag.first] = tag.second;
}
// release_policy
JsonOptional::SetFromNullable<KeyReleasePolicy, Azure::Core::Json::_internal::json>(
importKeyOptions.Properties.ReleasePolicy,
payload,
_detail::ReleasePolicyPropertyName,
KeyReleasePolicySerializer::KeyReleasePolicySerialize);
return payload.dump();
}

View File

@ -1,130 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_models.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/base64.hpp>
#include <azure/core/internal/json/json_optional.hpp>
#include <map>
#include <string>
#include <vector>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::_internal;
using namespace Azure::Core::Json::_internal;
namespace {
void ParseStringOperationsToKeyOperations(
std::vector<KeyOperation>& keyOperations,
std::vector<std::string> const& stringOperations)
{
for (std::string const& operation : stringOperations)
{
keyOperations.emplace_back(KeyOperation(operation));
}
}
inline void AssignBytesIfExists(
Azure::Core::Json::_internal::json const& jsonKey,
std::string const& keyName,
std::vector<uint8_t>& destBytes)
{
JsonOptional::SetIfExists<std::string, std::vector<uint8_t>>(
destBytes, jsonKey, keyName, [](std::string const& value) {
return Base64Url::Base64UrlDecode(value);
});
}
inline void WriteJsonIfVectorHasData(
std::vector<uint8_t> const& srcVector,
Azure::Core::Json::_internal::json& jsonKey,
std::string const& keyName)
{
JsonOptional::SetFromIfPredicate<std::vector<uint8_t> const&>(
srcVector,
[](std::vector<uint8_t> const& value) { return !value.empty(); },
jsonKey,
keyName,
Base64Url::Base64UrlEncode);
}
} // namespace
void Azure::Security::KeyVault::Keys::_detail::JsonWebKeySerializer::JsonWebKeySerialize(
JsonWebKey const& jwk,
Azure::Core::Json::_internal::json& destJson)
{
// kty
destJson[_detail::KeyTypePropertyName] = jwk.KeyType.ToString();
// ops
for (KeyOperation const& op : jwk.KeyOperations())
{
destJson[_detail::KeyOpsPropertyName].push_back(op.ToString());
}
// curve name
JsonOptional::SetFromNullable<KeyCurveName, std::string>(
jwk.CurveName, destJson, _detail::CurveNamePropertyName, [](KeyCurveName const& value) {
return value.ToString();
});
if (!jwk.Id.empty())
{
destJson[_detail::KeyIdPropertyName] = jwk.Id;
}
// fields
WriteJsonIfVectorHasData(jwk.N, destJson, _detail::NPropertyName);
WriteJsonIfVectorHasData(jwk.E, destJson, _detail::EPropertyName);
WriteJsonIfVectorHasData(jwk.D, destJson, _detail::DPropertyName);
WriteJsonIfVectorHasData(jwk.DP, destJson, _detail::DPPropertyName);
WriteJsonIfVectorHasData(jwk.DQ, destJson, _detail::DQPropertyName);
WriteJsonIfVectorHasData(jwk.QI, destJson, _detail::QIPropertyName);
WriteJsonIfVectorHasData(jwk.P, destJson, _detail::PPropertyName);
WriteJsonIfVectorHasData(jwk.Q, destJson, _detail::QPropertyName);
WriteJsonIfVectorHasData(jwk.X, destJson, _detail::XPropertyName);
WriteJsonIfVectorHasData(jwk.Y, destJson, _detail::YPropertyName);
WriteJsonIfVectorHasData(jwk.K, destJson, _detail::KPropertyName);
WriteJsonIfVectorHasData(jwk.T, destJson, _detail::TPropertyName);
}
void Azure::Security::KeyVault::Keys::_detail::JsonWebKeySerializer::JsonWebDeserialize(
JsonWebKey& srcKey,
Azure::Core::Json::_internal::json const& jsonParser)
{
// "Key"
if (jsonParser.contains(_detail::KeyPropertyName))
{
auto const& jsonKey = jsonParser[_detail ::KeyPropertyName];
{
// key_ops
auto keyOperationVector
= jsonKey[_detail::KeyOpsPropertyName].get<std::vector<std::string>>();
std::vector<KeyOperation> keyOperations;
ParseStringOperationsToKeyOperations(keyOperations, keyOperationVector);
srcKey.SetKeyOperations(keyOperations);
}
srcKey.Id = jsonKey[_detail::KeyIdPropertyName].get<std::string>();
srcKey.KeyType = KeyVaultKeyType(jsonKey[_detail::KeyTypePropertyName].get<std::string>());
JsonOptional::SetIfExists<std::string, KeyCurveName>(
srcKey.CurveName, jsonKey, _detail::CurveNamePropertyName, [](std::string const& keyName) {
return KeyCurveName(keyName);
});
AssignBytesIfExists(jsonKey, _detail::NPropertyName, srcKey.N);
AssignBytesIfExists(jsonKey, _detail::EPropertyName, srcKey.E);
AssignBytesIfExists(jsonKey, _detail::DPPropertyName, srcKey.DP);
AssignBytesIfExists(jsonKey, _detail::DQPropertyName, srcKey.DQ);
AssignBytesIfExists(jsonKey, _detail::QIPropertyName, srcKey.QI);
AssignBytesIfExists(jsonKey, _detail::PPropertyName, srcKey.P);
AssignBytesIfExists(jsonKey, _detail::QPropertyName, srcKey.Q);
AssignBytesIfExists(jsonKey, _detail::DPropertyName, srcKey.D);
AssignBytesIfExists(jsonKey, _detail::KPropertyName, srcKey.K);
AssignBytesIfExists(jsonKey, _detail::TPropertyName, srcKey.T);
AssignBytesIfExists(jsonKey, _detail::XPropertyName, srcKey.X);
AssignBytesIfExists(jsonKey, _detail::YPropertyName, srcKey.Y);
}
}

View File

@ -1,36 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "private/key_backup.hpp"
#include <azure/core/base64.hpp>
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_optional.hpp>
#include <string>
using namespace Azure::Security::KeyVault::Keys::_detail;
using namespace Azure::Core::_internal;
using namespace Azure::Core::Json::_internal;
std::string KeyBackup::Serialize() const
{
Azure::Core::Json::_internal::json payload;
payload["value"] = Base64Url::Base64UrlEncode(Value);
// release_policy
return payload.dump();
}
KeyBackup KeyBackup::Deserialize(Azure::Core::Http::RawResponse const& rawResponse)
{
auto const& body = rawResponse.GetBody();
auto jsonParser = json::parse(body);
KeyBackup keyBackup;
JsonOptional::SetIfExists<std::string, std::vector<uint8_t>>(
keyBackup.Value, jsonParser, "value", [](std::string const& value) {
return Base64Url::Base64UrlDecode(value);
});
return keyBackup;
}

View File

@ -5,9 +5,7 @@
#include "./generated/key_vault_client.hpp"
#include "private/cryptography_internal_access.hpp"
#include "private/key_backup.hpp"
#include "private/key_constants.hpp"
#include "private/key_request_parameters.hpp"
#include "private/key_serializers.hpp"
#include "private/keyvault_protocol.hpp"
#include "private/package_version.hpp"

View File

@ -14,122 +14,6 @@
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::Json::_internal;
KeyPropertiesPagedResponse
_detail::KeyPropertiesPagedResultSerializer::KeyPropertiesPagedResultDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
using Azure::Core::_internal::PosixTimeConverter;
KeyPropertiesPagedResponse result;
auto const& body = rawResponse.GetBody();
auto jsonParser = json::parse(body);
JsonOptional::SetIfExists(result.NextPageToken, jsonParser, "nextLink");
// Key properties
auto keyPropertiesJson = jsonParser["value"];
for (auto const& key : keyPropertiesJson)
{
KeyProperties keyProperties;
keyProperties.Id = key[_detail::KeyIdPropertyName].get<std::string>();
_detail::KeyVaultKeySerializer::ParseKeyUrl(keyProperties, keyProperties.Id);
// "Attributes"
if (key.contains(_detail::AttributesPropertyName))
{
auto attributes = key[_detail::AttributesPropertyName];
JsonOptional::SetIfExists(keyProperties.Enabled, attributes, _detail::EnabledPropertyName);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
keyProperties.NotBefore,
attributes,
_detail::NbfPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
keyProperties.ExpiresOn,
attributes,
_detail::ExpPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
keyProperties.CreatedOn,
attributes,
_detail::CreatedPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
keyProperties.UpdatedOn,
attributes,
_detail::UpdatedPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
}
// "Tags"
if (key.contains(_detail::TagsPropertyName))
{
auto const& tags = key[_detail::TagsPropertyName];
for (auto tag = tags.begin(); tag != tags.end(); ++tag)
{
keyProperties.Tags.emplace(tag.key(), tag.value().get<std::string>());
}
}
// managed
if (key.contains(_detail::ManagedPropertyName))
{
keyProperties.Managed = key[_detail::ManagedPropertyName].get<bool>();
}
result.Items.emplace_back(keyProperties);
}
return result;
}
DeletedKeyPagedResponse
_detail::KeyPropertiesPagedResultSerializer::DeletedKeyPagedResultDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
using Azure::Core::_internal::PosixTimeConverter;
auto const& body = rawResponse.GetBody();
auto jsonParser = Azure::Core::Json::_internal::json::parse(body);
DeletedKeyPagedResponse deletedKeyPagedResult;
JsonOptional::SetIfExists(deletedKeyPagedResult.NextPageToken, jsonParser, "nextLink");
auto deletedKeys = jsonParser["value"];
for (auto const& key : deletedKeys)
{
DeletedKey deletedKey;
deletedKey.Properties.Id = key[_detail::KeyIdPropertyName].get<std::string>();
_detail::KeyVaultKeySerializer::ParseKeyUrl(deletedKey.Properties, deletedKey.Properties.Id);
if (!key[_detail::RecoveryIdPropertyName].is_null())
{
deletedKey.RecoveryId = key[_detail::RecoveryIdPropertyName].get<std::string>();
}
if (!key[_detail::AttributesPropertyName][_detail::RecoveryLevelPropertyName].is_null())
{
deletedKey.Properties.RecoveryLevel
= key[_detail::AttributesPropertyName][_detail::RecoveryLevelPropertyName]
.get<std::string>();
}
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
deletedKey.DeletedDate,
key,
_detail::DeletedOnPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
deletedKey.ScheduledPurgeDate,
key,
_detail::ScheduledPurgeDatePropertyName,
PosixTimeConverter::PosixTimeToDateTime);
deletedKeyPagedResult.Items.emplace_back(deletedKey);
}
return deletedKeyPagedResult;
}
void DeletedKeyPagedResponse::OnNextPage(const Azure::Core::Context& context)
{
// Before calling `OnNextPage` pagedResponse validates there is a next page, so we are sure

View File

@ -1,32 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_models.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/base64.hpp>
#include <azure/core/internal/json/json.hpp>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::Json::_internal;
std::string _detail::GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(
GetRandomBytesOptions const& options)
{
json payload;
payload[_detail::CountPropertiesValue] = options.Count;
return payload.dump();
}
std::vector<uint8_t> _detail::GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
auto const& body = rawResponse.GetBody();
auto const jsonParser = Azure::Core::Json::_internal::json::parse(body);
auto value = jsonParser[_detail::ValueParameterValue].get<std::string>();
return Azure::Core::_internal::Base64Url::Base64UrlDecode(value);
}

View File

@ -1,50 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_options.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/base64.hpp>
#include <azure/core/internal/json/json_optional.hpp>
#include <map>
#include <string>
#include <vector>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::_internal;
using namespace Azure::Core::Json::_internal;
std::string
Azure::Security::KeyVault::Keys::_detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(
KeyReleaseOptions const& keyReleaseOptions)
{
Azure::Core::Json::_internal::json payload;
payload[_detail::TargetValue] = keyReleaseOptions.Target;
JsonOptional::SetFromNullable<KeyEncryptionAlgorithm, std::string>(
keyReleaseOptions.Encryption,
payload,
_detail::EncryptionValue,
[](KeyEncryptionAlgorithm const& enc) { return enc.ToString(); });
JsonOptional::SetFromNullable(keyReleaseOptions.Nonce, payload, _detail::NonceValue);
return payload.dump();
}
ReleaseKeyResult
Azure::Security::KeyVault::Keys::_detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
ReleaseKeyResult result;
auto const& body = rawResponse.GetBody();
auto jsonParser = Azure::Core::Json::_internal::json::parse(body);
result.Value = jsonParser[_detail::ValueParameterValue].get<std::string>();
return result;
}

View File

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_options.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/internal/json/json_optional.hpp>
#include <string>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::_internal;
using namespace Azure::Core::Json::_internal;
Azure::Core::Json::_internal::json
Azure::Security::KeyVault::Keys::_detail::KeyReleasePolicySerializer::KeyReleasePolicySerialize(
KeyReleasePolicy const& policy)
{
Azure::Core::Json::_internal::json payload;
payload[_detail::ContentTypeValue] = policy.ContentType.ValueOr(_detail::ContentTypeDefaultValue);
payload[_detail::ImmutableValue] = policy.Immutable;
payload[_detail::DataValue] = policy.EncodedPolicy;
return payload;
}
KeyReleasePolicy
Azure::Security::KeyVault::Keys::_detail::KeyReleasePolicySerializer::KeyReleasePolicyDeserialize(
Azure::Core::Json::_internal::json const& rawResponse)
{
KeyReleasePolicy policy;
policy.ContentType = rawResponse[_detail::ContentTypeValue].get<std::string>();
policy.Immutable = rawResponse[_detail::ImmutableValue].get<bool>();
policy.EncodedPolicy = rawResponse[_detail::DataValue].get<std::string>();
return policy;
}

View File

@ -1,80 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "private/key_request_parameters.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_optional.hpp>
#include <string>
using namespace Azure::Security::KeyVault::Keys::_detail;
using namespace Azure::Core::Json::_internal;
std::string KeyRequestParameters::Serialize() const
{
using Azure::Core::_internal::PosixTimeConverter;
Azure::Core::Json::_internal::json payload;
// kty
JsonOptional::SetFromNullable<KeyVaultKeyType, std::string>(
m_keyType, payload, _detail::KeyTypePropertyName, [](KeyVaultKeyType const& type) {
return type.ToString();
});
// attributes
JsonOptional::SetFromNullable(
m_options.Enabled, payload[_detail::AttributesPropertyName], _detail::EnabledPropertyName);
// exportable attribute
JsonOptional::SetFromNullable(
m_options.Exportable,
payload[_detail::AttributesPropertyName],
_detail::ExportablePropertyName);
/* Optional */
// key_size
// public_exponent
// key_ops
for (KeyOperation const& op : m_options.KeyOperations)
{
payload[_detail::KeyOpsPropertyName].push_back(op.ToString());
}
// attributes
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
m_options.ExpiresOn,
payload[_detail::AttributesPropertyName],
_detail::ExpPropertyName,
PosixTimeConverter::DateTimeToPosixTime);
JsonOptional::SetFromNullable<Azure::DateTime, int64_t>(
m_options.NotBefore,
payload[_detail::AttributesPropertyName],
_detail::NbfPropertyName,
PosixTimeConverter::DateTimeToPosixTime);
// tags
for (auto const& tag : m_options.Tags)
{
payload[_detail::TagsPropertyName][tag.first] = tag.second;
}
// crv
if (Curve.HasValue())
{
payload[_detail::CurveNamePropertyName] = Curve.Value().ToString();
}
// release_policy
JsonOptional::SetFromNullable<KeyReleasePolicy, Azure::Core::Json::_internal::json>(
m_options.ReleasePolicy,
payload,
_detail::ReleasePolicyPropertyName,
KeyReleasePolicySerializer::KeyReleasePolicySerialize);
return payload.dump();
}

View File

@ -1,125 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_models.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_optional.hpp>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::Json::_internal;
using Azure::Core::_internal::PosixTimeConverter;
KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
return KeyRotationPolicyDeserialize(rawResponse.GetBody());
}
KeyRotationPolicy _detail::KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(
std::vector<uint8_t> const& body)
{
auto const jsonParser = Azure::Core::Json::_internal::json::parse(body);
KeyRotationPolicy policy;
policy.Id = jsonParser[_detail::IdValue].get<std::string>();
if (!jsonParser[_detail::AttributesPropertyName].is_null())
{
auto jsonFragment = jsonParser[_detail::AttributesPropertyName];
policy.Attributes.ExpiryTime = jsonFragment[_detail::ExpiryTimeValue].get<std::string>();
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
policy.Attributes.Created,
jsonFragment,
_detail::CreatedPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
policy.Attributes.Updated,
jsonFragment,
_detail::UpdatedPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
}
if (!jsonParser[_detail::LifeTimeActionsValue].is_null())
{
auto lifeTimeActions = jsonParser[_detail::LifeTimeActionsValue];
for (auto action : lifeTimeActions)
{
LifetimeActionsType currentAction;
JsonOptional::SetIfExists(
currentAction.Trigger.TimeAfterCreate,
action[_detail::TriggerActionsValue],
_detail::TACActionsValue);
JsonOptional::SetIfExists(
currentAction.Trigger.TimeBeforeExpiry,
action[_detail::TriggerActionsValue],
_detail::TBEActionsValue);
auto const actionType
= action[_detail::ActionActionsValue][TypeActionsValue].get<std::string>();
if (Azure::Core::_internal::StringExtensions::LocaleInvariantCaseInsensitiveEqual(
actionType, _detail::RotateActionsValue))
{
currentAction.Action = LifetimeActionType::Rotate;
}
else if (Azure::Core::_internal::StringExtensions::LocaleInvariantCaseInsensitiveEqual(
actionType, _detail::NotifyActionsValue))
{
currentAction.Action = LifetimeActionType::Notify;
}
policy.LifetimeActions.emplace_back(currentAction);
}
}
return policy;
}
std::string _detail::KeyRotationPolicySerializer::KeyRotationPolicySerialize(
KeyRotationPolicy const& rotationPolicy)
{
json payload;
JsonOptional::SetFromNullable(
rotationPolicy.Attributes.ExpiryTime,
payload[_detail::AttributesPropertyName],
_detail::ExpiryTimeValue);
for (auto const& lifetimeAction : rotationPolicy.LifetimeActions)
{
json oneAction;
JsonOptional::SetFromNullable(
lifetimeAction.Trigger.TimeAfterCreate,
oneAction[_detail::TriggerActionsValue],
_detail::TACActionsValue);
JsonOptional::SetFromNullable(
lifetimeAction.Trigger.TimeBeforeExpiry,
oneAction[_detail::TriggerActionsValue],
_detail::TBEActionsValue);
if (lifetimeAction.Action == LifetimeActionType::Notify)
{
oneAction[_detail::ActionActionsValue][_detail::TypeActionsValue]
= _detail::NotifyActionsValue;
}
else
{
oneAction[_detail::ActionActionsValue][_detail::TypeActionsValue]
= _detail::RotateActionsValue;
}
payload[_detail::LifeTimeActionsValue].emplace_back(oneAction);
}
return payload.dump();
}

View File

@ -1,110 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "azure/keyvault/keys/key_client_models.hpp"
#include "private/key_constants.hpp"
#include "private/key_serializers.hpp"
#include <azure/core/internal/json/json.hpp>
#include <azure/core/internal/json/json_optional.hpp>
#include <azure/core/internal/json/json_serializable.hpp>
using namespace Azure::Security::KeyVault::Keys;
using namespace Azure::Core::Json::_internal;
using Azure::Core::_internal::PosixTimeConverter;
KeyVaultKey _detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(
std::string const& name,
Azure::Core::Http::RawResponse const& rawResponse)
{
KeyVaultKey key(name);
_detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(key, rawResponse);
return key;
}
KeyVaultKey _detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(
Azure::Core::Http::RawResponse const& rawResponse)
{
KeyVaultKey key;
_detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(key, rawResponse);
return key;
}
void _detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(
KeyVaultKey& key,
Azure::Core::Http::RawResponse const& rawResponse)
{
auto const& body = rawResponse.GetBody();
auto jsonParser = json::parse(body);
_detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(key, jsonParser);
}
void _detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(
KeyVaultKey& key,
Azure::Core::Json::_internal::json const& jsonParser)
{
using Azure::Core::_internal::PosixTimeConverter;
// Deserialize jwk
_detail::JsonWebKeySerializer::JsonWebDeserialize(key.Key, jsonParser);
// Parse URL for the vaultUri, keyVersion
_detail::KeyVaultKeySerializer::ParseKeyUrl(key.Properties, key.Key.Id);
// "Attributes"
if (jsonParser.contains(_detail::AttributesPropertyName))
{
auto const& attributes = jsonParser[_detail::AttributesPropertyName];
JsonOptional::SetIfExists(key.Properties.Enabled, attributes, _detail::EnabledPropertyName);
JsonOptional::SetIfExists(
key.Properties.Exportable, attributes, _detail::ExportablePropertyName);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
key.Properties.NotBefore,
attributes,
_detail::NbfPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
key.Properties.ExpiresOn,
attributes,
_detail::ExpPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
key.Properties.CreatedOn,
attributes,
_detail::CreatedPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<int64_t, Azure::DateTime>(
key.Properties.UpdatedOn,
attributes,
_detail::UpdatedPropertyName,
PosixTimeConverter::PosixTimeToDateTime);
JsonOptional::SetIfExists<std::string>(
key.Properties.HsmPlatform, attributes, _detail::HsmPlatformPropertyName);
}
JsonOptional::SetIfExists<json, KeyReleasePolicy>(
key.Properties.ReleasePolicy,
jsonParser,
_detail::ReleasePolicyPropertyName,
KeyReleasePolicySerializer::KeyReleasePolicyDeserialize);
// "Tags"
if (jsonParser.contains(_detail::TagsPropertyName))
{
auto const& tags = jsonParser[_detail::TagsPropertyName];
{
for (auto tag = tags.begin(); tag != tags.end(); ++tag)
{
key.Properties.Tags.emplace(tag.key(), tag.value().get<std::string>());
}
}
}
// managed
if (jsonParser.contains(_detail::ManagedPropertyName))
{
key.Properties.Managed = jsonParser[_detail::ManagedPropertyName].get<bool>();
}
}

View File

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @file
* @brief Internal wrapper layer on top of a uint_8 array.
*
*/
#pragma once
#include <azure/core/http/http.hpp>
#include <azure/core/internal/json/json_serializable.hpp>
#include <string>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace _detail {
class KeyBackup final : public Azure::Core::Json::_internal::JsonSerializable {
public:
std::vector<uint8_t> Value;
std::string Serialize() const override;
static KeyBackup Deserialize(Azure::Core::Http::RawResponse const& rawResponse);
};
}}}}} // namespace Azure::Security::KeyVault::Keys::_detail

View File

@ -13,48 +13,17 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
constexpr static const char KeyVaultServicePackageName[] = "keyvault-keys";
/***************** KeyVault Key *****************/
constexpr static const char KeyPropertyName[] = "key";
// constexpr static const char KeyPropertyName[] = "key";
/***************** Key Client *****************/
constexpr static const char KeysPath[] = "keys";
constexpr static const char DeletedKeysPath[] = "deletedkeys";
// constexpr static const char DeletedKeysPath[] = "deletedkeys";
/***************** Key Properties *****************/
constexpr static const char ManagedPropertyName[] = "managed";
constexpr static const char AttributesPropertyName[] = "attributes";
constexpr static const char TagsPropertyName[] = "tags";
constexpr static const char ReleasePolicyPropertyName[] = "release_policy";
constexpr static const char EnabledPropertyName[] = "enabled";
constexpr static const char ExportablePropertyName[] = "exportable";
constexpr static const char NbfPropertyName[] = "nbf";
constexpr static const char ExpPropertyName[] = "exp";
constexpr static const char CreatedPropertyName[] = "created";
constexpr static const char UpdatedPropertyName[] = "updated";
constexpr static const char RecoverableDaysPropertyName[] = "recoverableDays";
constexpr static const char RecoveryLevelPropertyName[] = "recoveryLevel";
constexpr static const char HsmPlatformPropertyName[] = "hsmPlatform";
/***************** Key Request Parameters *****************/
constexpr static const char KeyTypePropertyName[] = "kty";
constexpr static const char KeySizePropertyName[] = "key_size";
constexpr static const char KeyOpsPropertyName[] = "key_ops";
constexpr static const char CurveNamePropertyName[] = "crv";
constexpr static const char PublicExponentPropertyName[] = "public_exponent";
/***************** JsonWebKey *****************/
constexpr static const char KeyIdPropertyName[] = "kid";
constexpr static const char NPropertyName[] = "n";
constexpr static const char EPropertyName[] = "e";
constexpr static const char DPPropertyName[] = "dp";
constexpr static const char DQPropertyName[] = "dq";
constexpr static const char QIPropertyName[] = "qi";
constexpr static const char PPropertyName[] = "p";
constexpr static const char QPropertyName[] = "q";
constexpr static const char XPropertyName[] = "x";
constexpr static const char YPropertyName[] = "y";
constexpr static const char DPropertyName[] = "d";
constexpr static const char KPropertyName[] = "k";
constexpr static const char TPropertyName[] = "key_hsm";
/***************** KeyType *****************/
constexpr static const char EcValue[] = "EC";
@ -64,11 +33,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
constexpr static const char OctValue[] = "oct";
constexpr static const char OctHsmValue[] = "oct-HSM";
/***************** Deleted Key *****************/
constexpr static const char RecoveryIdPropertyName[] = "recoveryId";
constexpr static const char DeletedOnPropertyName[] = "deletedDate";
constexpr static const char ScheduledPurgeDatePropertyName[] = "scheduledPurgeDate";
/***************** Curve Names *****************/
constexpr static const char P256Value[] = "P-256";
constexpr static const char P256KValue[] = "P-256K";
@ -80,9 +44,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
constexpr static const char P384OidValue[] = "1.3.132.0.34";
constexpr static const char P521OidValue[] = "1.3.132.0.35";
/***************** Import Key *****************/
constexpr static const char HsmPropertyName[] = "hsm";
/***************** Encryption Algorithm *********/
// cspell: ignore CBCPAD
constexpr static const char Rsa15Value[] = "RSA1_5";
@ -132,33 +93,11 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
/***************** Service *********/
constexpr static const char ApiVersionValue[] = "api-version";
/***************** Rotation Policy *********/
constexpr static const char IdValue[] = "id";
constexpr static const char ExpiryTimeValue[] = "expiryTime";
constexpr static const char LifeTimeActionsValue[] = "lifetimeActions";
constexpr static const char RotateActionsValue[] = "rotate";
constexpr static const char NotifyActionsValue[] = "notify";
constexpr static const char ActionActionsValue[] = "action";
constexpr static const char TriggerActionsValue[] = "trigger";
constexpr static const char TypeActionsValue[] = "type";
constexpr static const char TBEActionsValue[] = "timeBeforeExpiry";
constexpr static const char TACActionsValue[] = "timeAfterCreate";
constexpr static const char RotationPolicyPath[] = "rotationpolicy";
constexpr static const char ContentTypeValue[] = "contentType";
constexpr static const char ContentTypeDefaultValue[] = "application/json; charset=utf-8";
constexpr static const char ImmutableValue[] = "immutable";
constexpr static const char DataValue[] = "data";
/***************** Get Random Bytes *********/
constexpr static const char CountPropertiesValue[] = "count";
/***************** Release *********/
constexpr static const char ReleaseValue[] = "release";
constexpr static const char CKM_RSA_AES_KEY_WRAP_Value[] = "CKM_RSA_AES_KEY_WRAP";
constexpr static const char RSA_AES_KEY_WRAP_256_Value[] = "RSA_AES_KEY_WRAP_256";
constexpr static const char RSA_AES_KEY_WRAP_384_Value[] = "RSA_AES_KEY_WRAP_384";
constexpr static const char TargetValue[] = "target";
constexpr static const char NonceValue[] = "nonce";
constexpr static const char EncryptionValue[] = "enc";
constexpr static const char PropertiesValue[] = "properties";
}}}}} // namespace Azure::Security::KeyVault::Keys::_detail

View File

@ -1,110 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* @file
* @brief Internal implementation for sending the HTTP request.
*
*/
#pragma once
#include "azure/keyvault/keys/key_client_models.hpp"
#include "azure/keyvault/keys/key_client_options.hpp"
#include <azure/core/internal/json/json_serializable.hpp>
#include <azure/core/nullable.hpp>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace Keys { namespace _detail {
class KeyRequestParameters final : public Azure::Core::Json::_internal::JsonSerializable {
private:
Azure::Nullable<KeyVaultKeyType> m_keyType;
CreateKeyOptions m_options;
public:
Azure::Nullable<KeyCurveName> Curve;
Azure::Nullable<int64_t> KeySize;
Azure::Nullable<int64_t> PublicExponent;
explicit KeyRequestParameters(
KeyProperties const& key,
Azure::Nullable<std::vector<KeyOperation>> const& operations)
: m_options(CreateKeyOptions())
{
if (key.Enabled)
{
m_options.Enabled = key.Enabled.Value();
}
if (key.ExpiresOn)
{
m_options.ExpiresOn = key.ExpiresOn.Value();
}
if (key.NotBefore)
{
m_options.NotBefore = key.NotBefore.Value();
}
if (!key.Tags.empty())
{
m_options.Tags = std::unordered_map<std::string, std::string>(key.Tags);
}
if (key.ReleasePolicy)
{
m_options.ReleasePolicy = key.ReleasePolicy;
}
if (key.Exportable)
{
m_options.Exportable = key.Exportable.Value();
}
if (operations)
{
m_options.KeyOperations = std::vector<KeyOperation>(operations.Value());
}
}
explicit KeyRequestParameters(KeyVaultKeyType keyType, CreateKeyOptions const& options)
: m_keyType(std::move(keyType)), m_options(options)
{
}
explicit KeyRequestParameters(CreateEcKeyOptions const& ecKey)
: KeyRequestParameters(ecKey.GetKeyType(), ecKey)
{
if (ecKey.CurveName.HasValue())
{
Curve = ecKey.CurveName.Value();
}
}
explicit KeyRequestParameters(CreateRsaKeyOptions const& rsaKey)
: KeyRequestParameters(rsaKey.GetKeyType(), rsaKey)
{
if (rsaKey.KeySize.HasValue())
{
KeySize = rsaKey.KeySize.Value();
}
if (rsaKey.PublicExponent.HasValue())
{
PublicExponent = rsaKey.PublicExponent.Value();
}
}
explicit KeyRequestParameters(CreateOctKeyOptions const& octKey)
: KeyRequestParameters(octKey.GetKeyType(), octKey)
{
if (octKey.KeySize.HasValue())
{
KeySize = octKey.KeySize.Value();
}
}
std::string Serialize() const override;
};
}}}}} // namespace Azure::Security::KeyVault::Keys::_detail

View File

@ -20,24 +20,6 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
/***************** KeyVault Key *****************/
class KeyVaultKeySerializer final {
public:
// Creates a new key based on a name and an HTTP raw response.
static KeyVaultKey KeyVaultKeyDeserialize(
std::string const& name,
Azure::Core::Http::RawResponse const& rawResponse);
// Create from HTTP raw response only.
static KeyVaultKey KeyVaultKeyDeserialize(Azure::Core::Http::RawResponse const& rawResponse);
// Updates a Key based on an HTTP raw response.
static void KeyVaultKeyDeserialize(
KeyVaultKey& key,
Azure::Core::Http::RawResponse const& rawResponse);
// Create from json node directly. Used from listKeys
static void KeyVaultKeyDeserialize(
KeyVaultKey& key,
Azure::Core::Json::_internal::json const& json);
static std::string GetUrlAuthorityWithScheme(Azure::Core::Url const& url)
{
std::string urlString;
@ -79,74 +61,4 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
}
}
};
/**************** Deleted Key *******************/
class DeletedKeySerializer final {
public:
static DeletedKey DeletedKeyDeserialize(
std::string const& name,
Azure::Core::Http::RawResponse const& rawResponse);
};
/**************** Import Key Options ***********/
class ImportKeyOptionsSerializer final {
public:
static std::string ImportKeyOptionsSerialize(ImportKeyOptions const& importKeyOptions);
};
/**************** Key Properties ************/
class KeyPropertiesPagedResultSerializer final {
public:
static KeyPropertiesPagedResponse KeyPropertiesPagedResultDeserialize(
Azure::Core::Http::RawResponse const& rawResponse);
static DeletedKeyPagedResponse DeletedKeyPagedResultDeserialize(
Azure::Core::Http::RawResponse const& rawResponse);
};
/**************** JWK ************/
class JsonWebKeySerializer final {
public:
static void JsonWebKeySerialize(
JsonWebKey const& jwk,
Azure::Core::Json::_internal::json& destJson);
static void JsonWebDeserialize(
JsonWebKey& srcKey,
Azure::Core::Json::_internal::json const& jsonParser);
};
/**************** Key Properties ************/
class KeyRotationPolicySerializer final {
public:
static KeyRotationPolicy KeyRotationPolicyDeserialize(
Azure::Core::Http::RawResponse const& rawResponse);
static KeyRotationPolicy KeyRotationPolicyDeserialize(std::vector<uint8_t> const& body);
static std::string KeyRotationPolicySerialize(KeyRotationPolicy const& rotationPolicy);
};
/**************** GetRandomBytes ************/
class GetRandomBytesSerializer final {
public:
static std::string GetRandomBytesOptionsSerialize(GetRandomBytesOptions const& options);
static std::vector<uint8_t> GetRandomBytesResponseDeserialize(
Azure::Core::Http::RawResponse const& rawResponse);
};
/**************** KeyReleaseOptionsSerializer ************/
class KeyReleaseOptionsSerializer final {
public:
static std::string KeyReleaseOptionsSerialize(KeyReleaseOptions const& keyReleaseOptions);
static ReleaseKeyResult KeyReleaseOptionsDeserialize(
Azure::Core::Http::RawResponse const& rawResponse);
};
/**************** KeyReleasePolicySerializer ************/
class KeyReleasePolicySerializer final {
public:
static Azure::Core::Json::_internal::json KeyReleasePolicySerialize(
KeyReleasePolicy const& policy);
static KeyReleasePolicy KeyReleasePolicyDeserialize(
Azure::Core::Json::_internal::json const& rawResponse);
};
}}}}} // namespace Azure::Security::KeyVault::Keys::_detail

View File

@ -18,33 +18,34 @@ Azure::Security::KeyVault::Keys::RecoverDeletedKeyOperation::PollInternal(
try
{
rawResponse = m_keyClient->GetKey(m_value.Name(), {}, context).RawResponse;
auto result = m_keyClient->GetKey(m_value.Name(), {}, context);
rawResponse = std::move(result.RawResponse);
switch (rawResponse->GetStatusCode())
{
case Azure::Core::Http::HttpStatusCode::Ok:
// Access denied but proof the key was deleted.
case Azure::Core::Http::HttpStatusCode::Forbidden: {
m_status = Azure::Core::OperationStatus::Succeeded;
break;
}
case Azure::Core::Http::HttpStatusCode::NotFound: {
m_status = Azure::Core::OperationStatus::Running;
break;
}
default:
throw Azure::Core::RequestFailedException(rawResponse);
}
if (m_status == Azure::Core::OperationStatus::Succeeded)
{
m_value = std::move(result.Value);
}
}
catch (Azure::Core::RequestFailedException& error)
{
rawResponse = std::move(error.RawResponse);
}
switch (rawResponse->GetStatusCode())
{
case Azure::Core::Http::HttpStatusCode::Ok:
// Access denied but proof the key was deleted.
case Azure::Core::Http::HttpStatusCode::Forbidden: {
m_status = Azure::Core::OperationStatus::Succeeded;
break;
}
case Azure::Core::Http::HttpStatusCode::NotFound: {
m_status = Azure::Core::OperationStatus::Running;
break;
}
default:
throw Azure::Core::RequestFailedException(rawResponse);
}
if (m_status == Azure::Core::OperationStatus::Succeeded)
{
m_value = _detail::KeyVaultKeySerializer::KeyVaultKeyDeserialize(m_value.Name(), *rawResponse);
}
// To ensure the success of calling Poll multiple times, even after operation is completed, a
// copy of the raw HTTP response is returned instead of transferring the ownership of the raw
// response inside the Operation.

View File

@ -251,9 +251,7 @@ TEST_F(KeyVaultKeyClient, CreateKeyWithReleasePolicyOptions)
EXPECT_TRUE(keyResponse.Value.Properties.ReleasePolicy.HasValue());
auto policy = keyResponse.Value.Properties.ReleasePolicy.Value();
EXPECT_TRUE(policy.ContentType.HasValue());
EXPECT_EQ(
policy.ContentType.Value(),
Azure::Security::KeyVault::Keys::_detail::ContentTypeDefaultValue);
EXPECT_EQ(policy.ContentType.Value(), "application/json; charset=utf-8");
EXPECT_FALSE(policy.Immutable);
EXPECT_EQ(

View File

@ -284,8 +284,7 @@ TEST_F(KeyVaultKeyClient, GetDeletedKey)
Azure::Core::Context cancelToken{duration};
auto keyResponseLRO = client.StartDeleteKey(keyName);
auto expectedStatusToken = m_keyVaultUrl
+ std::string(Azure::Security::KeyVault::Keys::_detail::DeletedKeysPath) + "/" + keyName;
auto expectedStatusToken = m_keyVaultUrl + std::string("deletedkeys") + "/" + keyName;
auto keyResponse = keyResponseLRO.PollUntilDone(m_testPollingIntervalMs, cancelToken);
}
{

View File

@ -53,136 +53,6 @@ TEST(KeyVaultKeyClientUnitTest, GetUrl)
EXPECT_EQ(url, keyClient.GetUrl());
}
TEST(KeyReleaseOptionsUnitTest, None)
{
KeyReleaseOptions options;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(nullptr, deserialized[_detail::NonceValue]);
EXPECT_EQ(nullptr, deserialized[_detail::EncryptionValue]);
}
TEST(KeyReleaseOptionsUnitTest, One)
{
KeyReleaseOptions options;
options.Target = "xyz";
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(nullptr, deserialized[_detail::NonceValue]);
EXPECT_EQ(nullptr, deserialized[_detail::EncryptionValue]);
}
TEST(KeyReleaseOptionsUnitTest, Most)
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(nullptr, deserialized[_detail::EncryptionValue]);
}
TEST(KeyReleaseOptionsUnitTest, All)
{
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::CkmRsaAesKeyWrap;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RsaAesKeyWrap256;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RsaAesKeyWrap384;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
// Disable deprecation warning
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4996)
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
{
KeyReleaseOptions options;
options.Target = "xyz";
options.Nonce = "abc";
options.Encryption = KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384;
auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options);
auto deserialized = Azure::Core::Json::_internal::json::parse(serialized);
EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]);
EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]);
EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]);
}
#if defined(_MSC_VER)
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // _MSC_VER
}
TEST(KeyEncryptionAlgorithmUnitTest, CheckValues)
{
// Disable deprecation warning

View File

@ -26,15 +26,19 @@ TEST_F(KeyVaultKeyClient, RotateKey)
auto createKeyResponse = client.CreateEcKey(CreateEcKeyOptions(keyName));
CheckValidResponse(createKeyResponse);
std::string input
= "{\"id\":\"https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/"
"rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"},"
"\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":"
"{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765,"
"\"updated\":1649797765}}";
Azure::Security::KeyVault::Keys::KeyRotationPolicy policy;
policy.Attributes.ExpiryTime = "P48M";
auto policy = KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(
std::vector<uint8_t>(input.begin(), input.end()));
LifetimeActionType action1 = LifetimeActionType::Rotate;
LifetimeActionsTrigger trigger1;
trigger1.TimeAfterCreate = "P18M";
LifetimeActionsTrigger trigger2;
trigger2.TimeBeforeExpiry = "P30D";
LifetimeActionType action2 = LifetimeActionType::Notify;
policy.LifetimeActions.push_back(LifetimeActionsType{trigger1, action1});
policy.LifetimeActions.push_back(LifetimeActionsType{trigger2, action2});
auto putPolicy = client.UpdateKeyRotationPolicy(keyName, policy).Value;
auto originalKey = client.GetKey(keyName);
@ -49,16 +53,19 @@ TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy)
auto createKeyResponse = client.CreateEcKey(CreateEcKeyOptions(keyName));
CheckValidResponse(createKeyResponse);
std::string input
= "{\"id\":\"https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/"
"rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"},"
"\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":"
"{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765,"
"\"updated\":1649797765}}";
Azure::Security::KeyVault::Keys::KeyRotationPolicy policy;
policy.Attributes.ExpiryTime = "P48M";
auto policy = KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(
std::vector<uint8_t>(input.begin(), input.end()));
LifetimeActionType action1 = LifetimeActionType::Rotate;
LifetimeActionsTrigger trigger1;
trigger1.TimeAfterCreate = "P18M";
LifetimeActionsTrigger trigger2;
trigger2.TimeBeforeExpiry = "P30D";
LifetimeActionType action2 = LifetimeActionType::Notify;
policy.LifetimeActions.push_back(LifetimeActionsType{trigger1, action1});
policy.LifetimeActions.push_back(LifetimeActionsType{trigger2, action2});
auto putPolicy = client.UpdateKeyRotationPolicy(keyName, policy).Value;
auto rotationPolicy = client.GetKeyRotationPolicy(keyName).Value;
@ -81,95 +88,3 @@ TEST_F(KeyVaultKeyClient, GetKeyRotationPolicy)
EXPECT_TRUE(found);
}
}
TEST(GetRandomBytesOptions, Serialize)
{
GetRandomBytesOptions options;
{
options.Count = 0;
std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options);
EXPECT_EQ(result, "{\"count\":0}");
}
{
options.Count = 5;
std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options);
EXPECT_EQ(result, "{\"count\":5}");
}
{
options.Count = -1;
std::string result = GetRandomBytesSerializer::GetRandomBytesOptionsSerialize(options);
EXPECT_EQ(result, "{\"count\":-1}");
}
}
TEST(GetRandomBytesOptions, Deserialize)
{
std::string inputString = "1234";
auto bytes = Azure::Core::_internal::Base64Url::Base64UrlEncode(
std::vector<uint8_t>(inputString.begin(), inputString.end()));
std::string responseText = "{\"value\": \"" + std::string(bytes.begin(), bytes.end()) + "\" }";
Azure::Core::Http::RawResponse rawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
rawResponse.SetBody(std::vector<uint8_t>(responseText.begin(), responseText.end()));
auto deserialized = GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(rawResponse);
EXPECT_EQ(deserialized.size(), size_t(4));
EXPECT_EQ(deserialized[0], uint8_t('1'));
EXPECT_EQ(deserialized[1], uint8_t('2'));
EXPECT_EQ(deserialized[2], uint8_t('3'));
EXPECT_EQ(deserialized[3], uint8_t('4'));
}
TEST(GetRandomBytesOptions, DeserializeEmpty)
{
std::string inputString = "";
auto bytes = Azure::Core::Convert::Base64Encode(
std::vector<uint8_t>(inputString.begin(), inputString.end()));
std::string responseText = "{\"value\": \"" + std::string(bytes.begin(), bytes.end()) + "\" }";
Azure::Core::Http::RawResponse rawResponse(1, 1, Azure::Core::Http::HttpStatusCode::Ok, "OK");
rawResponse.SetBody(std::vector<uint8_t>(responseText.begin(), responseText.end()));
auto deserialized = GetRandomBytesSerializer::GetRandomBytesResponseDeserialize(rawResponse);
EXPECT_EQ(deserialized.size(), size_t(0));
}
TEST(KeyRotationPolicy, SerializeDeserialize1)
{
std::string input
= "{\"id\":\"https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/"
"rotationpolicy\",\"lifetimeActions\":[{\"trigger\":{\"timeAfterCreate\":\"P18M\"},"
"\"action\":{\"type\":\"Rotate\"}},{\"trigger\":{\"timeBeforeExpiry\":\"P30D\"},\"action\":"
"{\"type\":\"Notify\"}}],\"attributes\":{\"expiryTime\":\"P48M\",\"created\":1649797765,"
"\"updated\":1649797765}}";
auto policy = KeyRotationPolicySerializer::KeyRotationPolicyDeserialize(
std::vector<uint8_t>(input.begin(), input.end()));
EXPECT_EQ(policy.Id, "https://redacted.vault.azure.net/keys/GetKeyRotationPolicy/rotationpolicy");
EXPECT_EQ(policy.Attributes.ExpiryTime.Value(), "P48M");
EXPECT_TRUE(policy.Attributes.Created);
EXPECT_TRUE(policy.Attributes.Updated);
EXPECT_EQ(policy.LifetimeActions.size(), size_t(2));
auto action0 = policy.LifetimeActions[0];
EXPECT_EQ(action0.Action, LifetimeActionType::Rotate);
EXPECT_EQ(action0.Trigger.TimeAfterCreate.Value(), "P18M");
EXPECT_FALSE(action0.Trigger.TimeBeforeExpiry);
auto action1 = policy.LifetimeActions[1];
EXPECT_EQ(action1.Action, LifetimeActionType::Notify);
EXPECT_EQ(action1.Trigger.TimeBeforeExpiry.Value(), "P30D");
EXPECT_FALSE(action1.Trigger.TimeAfterCreate);
auto serialized = KeyRotationPolicySerializer::KeyRotationPolicySerialize(policy);
std::string serializedString
= "{\"attributes\":{\"expiryTime\":\"P48M\"},\"lifetimeActions\":[{\"action\":{\"type\":"
"\"rotate\"},\"trigger\":{\"timeAfterCreate\":\"P18M\"}},{\"action\":{\"type\":\"notify\"},"
"\"trigger\":{\"timeBeforeExpiry\":\"P30D\"}}]}";
EXPECT_EQ(serialized, serializedString);
}

View File

@ -14,41 +14,7 @@
namespace Azure { namespace Security { namespace KeyVault { namespace Secrets { namespace _detail {
constexpr static const char KeyVaultServicePackageName[] = "keyvault-secrets";
/***************** KeyVault Secret *****************/
constexpr static const char SecretPath[] = "secrets";
static constexpr char const DeletedSecretPath[] = "deletedsecrets";
static constexpr char const BackupSecretPath[] = "backup";
static constexpr char const RestoreSecretPath[] = "restore";
static constexpr char const RecoverDeletedSecretPath[] = "recover";
/******************* Secret property names ***********/
constexpr static const char AttributesPropertyName[] = "attributes";
constexpr static const char EnabledPropertyName[] = "enabled";
constexpr static const char NbfPropertyName[] = "nbf";
constexpr static const char ExpPropertyName[] = "exp";
constexpr static const char CreatedPropertyName[] = "created";
constexpr static const char UpdatedPropertyName[] = "updated";
constexpr static const char ManagedPropertyName[] = "managed";
constexpr static const char TagsPropertyName[] = "tags";
constexpr static const char IdPropertyName[] = "id";
constexpr static const char KeyIdPropertyName[] = "kid";
constexpr static const char ValuePropertyName[] = "value";
constexpr static const char RecoveryLevelPropertyName[] = "recoveryLevel";
constexpr static const char ContentTypePropertyName[] = "contentType";
constexpr static const char RecoverableDaysPropertyName[] = "recoverableDays";
/**************** Deleted Secret property names ********/
constexpr static const char RecoveryIdPropertyName[] = "recoveryId";
constexpr static const char ScheduledPurgeDatePropertyName[] = "scheduledPurgeDate";
constexpr static const char DeletedDatePropertyName[] = "deletedDate";
/**************** KeyVault QueryParameters *********/
static constexpr char const ApiVersion[] = "api-version";
/**************** KeyVault Secrets Paged *********/
static constexpr size_t PagedMaxResults = 25;
static constexpr char const PagedMaxResultsName[] = "maxresults";
static constexpr char const VersionsName[] = "versions";
}}}}} // namespace Azure::Security::KeyVault::Secrets::_detail