Keyvault api review beta.1 updates (#2117)

* Remove to_json for jsonWebKey

* parse N

* Deserialize JWK for EC and OCT

* change log

* format

* fix live tests

* remove KeyVaultException

* Remove clientOptions from keyvault common

* use ext enum pattern

* rename JsonWebKeyType to KeyVaultKeyType

* Move singlePage base classes to shared internal

* rename maxResults

* format

* missing rename

* minor

* fix doxygen

* Make Service Version an ext enum
This commit is contained in:
Victor Vazquez 2021-04-15 11:53:45 -07:00 committed by GitHub
parent 6b50feb0d4
commit fbe7d51349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 379 additions and 315 deletions

View File

@ -2,6 +2,10 @@
## 4.0.0-beta.2 (Unreleased)
### Breaking Changes
- Removed `KeyVaultException`.
- Removed `ClientOptions`.
## 4.0.0-beta.1 (2021-04-07)

View File

@ -30,8 +30,8 @@ set(
AZURE_KEYVAULT_COMMON_HEADER
inc/azure/keyvault/common/internal/base64url.hpp
inc/azure/keyvault/common/internal/keyvault_pipeline.hpp
inc/azure/keyvault/common/internal/single_page.hpp
inc/azure/keyvault/common/internal/unix_time_helper.hpp
inc/azure/keyvault/common/client_options.hpp
inc/azure/keyvault/common/keyvault_constants.hpp
inc/azure/keyvault/common/keyvault_exception.hpp
inc/azure/keyvault/common/version.hpp

View File

@ -1,75 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @file
* @brief Defines the base options to create a Key Vault client.
*
*/
#pragma once
#include <azure/core/internal/client_options.hpp>
#include <stdexcept>
#include <string>
namespace Azure { namespace Security { namespace KeyVault {
/**
* @brief Available and supported service versions.
*
*/
enum class ServiceVersion
{
/**
* @brief Use to send request to the 7.0 version of Key Vault service.
*
*/
V7_0,
/**
* @brief Use to send request to the 7.1 version of Key Vault service.
*
*/
V7_1,
/**
* @brief Use to send request to the 7.2 version of Key Vault service.
*
*/
V7_2
};
/**
* @brief Define the base options to create an KeyVault SDK client.
*
*/
struct ClientOptions : public Azure::Core::_internal::ClientOptions
{
/**
* @brief The service version. All request are created with this version.
*
*/
ServiceVersion Version;
ClientOptions(ServiceVersion version)
: Azure::Core::_internal::ClientOptions(), Version(version)
{
}
std::string GetVersionString() const
{
switch (Version)
{
case ServiceVersion::V7_0:
return "7.0";
case ServiceVersion::V7_1:
return "7.1";
case ServiceVersion::V7_2:
return "7.2";
default:
throw std::runtime_error("Version not found");
}
}
};
}}} // namespace Azure::Security::KeyVault

View File

@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
/**
* @brief Define the base classes for using single page responses.
*
*/
#pragma once
#include <azure/core/nullable.hpp>
#include <string>
namespace Azure { namespace Security { namespace KeyVault { namespace _internal {
struct SinglePage
{
Azure::Nullable<std::string> ContinuationToken;
};
struct GetSinglePageOptions
{
Azure::Nullable<std::string> ContinuationToken;
Azure::Nullable<uint32_t> MaxPageResults;
};
}}}} // namespace Azure::Security::KeyVault::_internal

View File

@ -11,35 +11,24 @@
#include <azure/core/exception.hpp>
#include <azure/core/http/http.hpp>
#include <memory>
#include <stdexcept>
#include <string>
namespace Azure { namespace Security { namespace KeyVault {
namespace Azure { namespace Security { namespace KeyVault { namespace _detail {
/**
* @brief The general exception thrown by the Key Vault SDK clients.
* @brief Container for static methods to parse keyvault payloads to Azure Core Exception.
*
*/
class KeyVaultException : public Azure::Core::RequestFailedException {
public:
struct KeyVaultException
{
/**
* @brief Construct a new Key Vault Exception object without an Http raw response.
* @brief Parsed the http payload into an #Azure::Core::RequestFailedException
*
* @remark A Key Vault Exception without an Http raw response represent an exception happend
* before sending the request to the server. There is no response yet.
*
* @param message An error message for the exception.
* @param rawResponse The Http raw response.
* @return Azure::Core::RequestFailedException
*/
explicit KeyVaultException(const std::string& message) : RequestFailedException(message) {}
/**
* @brief Construct a new Key Vault Exception object with an Http raw response.
*
* @param message An error message for the exception.
* @param rawResponse The Http raw response from the service.
*/
explicit KeyVaultException(
const std::string& message,
static Azure::Core::RequestFailedException CreateException(
std::unique_ptr<Azure::Core::Http::RawResponse> rawResponse);
};
}}} // namespace Azure::Security::KeyVault
}}}} // namespace Azure::Security::KeyVault::_detail

View File

@ -12,24 +12,27 @@
using namespace Azure::Security::KeyVault;
using namespace Azure::Core::Http::_internal;
KeyVaultException::KeyVaultException(
const std::string& message,
Azure::Core::RequestFailedException _detail::KeyVaultException::CreateException(
std::unique_ptr<Azure::Core::Http::RawResponse> rawResponse)
: RequestFailedException(message, std::move(rawResponse))
{
std::vector<uint8_t> bodyBuffer = std::move(RawResponse->GetBody());
auto& headers = RawResponse->GetHeaders();
std::vector<uint8_t> bodyBuffer = std::move(rawResponse->GetBody());
auto& headers = rawResponse->GetHeaders();
std::string contentType = HttpShared::GetHeaderOrEmptyString(headers, HttpShared::ContentType);
std::string message;
std::string errorCode;
if (contentType.find("json") != std::string::npos)
{
auto jsonParser = Azure::Core::Json::_internal::json::parse(bodyBuffer);
auto& error = jsonParser["error"];
ErrorCode = error["code"].get<std::string>();
Message = error["message"].get<std::string>();
errorCode = error["code"].get<std::string>();
message = error["message"].get<std::string>();
}
else
{
Message = std::string(bodyBuffer.begin(), bodyBuffer.end());
message = std::string(bodyBuffer.begin(), bodyBuffer.end());
}
Azure::Core::RequestFailedException exception(message, std::move(rawResponse));
exception.ErrorCode = std::move(errorCode);
return exception;
}

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/core/http/http.hpp"
#include <azure/core/http/http.hpp>
#include "azure/keyvault/common/internal/keyvault_pipeline.hpp"
#include "azure/keyvault/common/keyvault_constants.hpp"
@ -70,7 +70,8 @@ std::unique_ptr<Azure::Core::Http::RawResponse> _internal::KeyVaultPipeline::Sen
case Azure::Core::Http::HttpStatusCode::NoContent:
break;
default:
throw KeyVaultException("Key Vault Keys error response received: ", std::move(response));
throw Azure::Security::KeyVault::_detail::KeyVaultException::CreateException(
std::move(response));
}
return response;
}

View File

@ -9,6 +9,9 @@
### Breaking Changes
- Removed `Azure::Security::KeyVault::Keys::JsonWebKey::to_json`.
- Replaced static functions from `KeyOperation` and `KeyCurveName` for static const members.
- Replaced the enum `JsonWebKeyType` for a class with static const members as ext enum.
- Renamed `MaxResults` to `MaxPageResults` for `GetSinglePageOptions`.
### Bug Fixes

View File

@ -55,8 +55,10 @@ set(
src/import_key_options.cpp
src/json_web_key.cpp
src/key_backup.cpp
src/key_client_options.cpp
src/key_client.cpp
src/key_curve_name.cpp
src/key_operation.cpp
src/key_request_parameters.cpp
src/key_type.cpp
src/key_vault_key.cpp

View File

@ -15,7 +15,6 @@
#include <azure/core/response.hpp>
#include <azure/keyvault/common/internal/keyvault_pipeline.hpp>
#include <azure/keyvault/common/keyvault_exception.hpp>
#include "azure/keyvault/keys/deleted_key.hpp"

View File

@ -27,7 +27,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
class KeyRequestParameters : public Azure::Core::Json::_internal::JsonSerializable {
private:
Azure::Nullable<JsonWebKeyType> m_keyType;
Azure::Nullable<KeyVaultKeyType> m_keyType;
CreateKeyOptions m_options;
public:
@ -62,7 +62,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
}
}
explicit KeyRequestParameters(JsonWebKeyType keyType, CreateKeyOptions const& options)
explicit KeyRequestParameters(KeyVaultKeyType keyType, CreateKeyOptions const& options)
: m_keyType(keyType), m_options(options)
{
}

View File

@ -37,7 +37,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* @brief They type of the key.
*
*/
JsonWebKeyType KeyType;
KeyVaultKeyType KeyType;
/**
* @brief Construct a new Json Web Key object.

View File

@ -97,7 +97,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
*
* @param name The name of the key.
* @param keyType The type of key to create. See
* #Azure::Security::KeyVault::Keys::JsonWebKeyType.
* #Azure::Security::KeyVault::Keys::KeyVaultKeyType.
* @param options Optional parameters for this operation. See
* #Azure::Security::KeyVault::Keys::CreateKeyOptions.
* @param context The context for the operation can be used for request cancellation.
@ -105,7 +105,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
*/
Azure::Response<KeyVaultKey> CreateKey(
std::string const& name,
JsonWebKeyType keyType,
KeyVaultKeyType keyType,
CreateKeyOptions const& options = CreateKeyOptions(),
Azure::Core::Context const& context = Azure::Core::Context()) const;

View File

@ -9,29 +9,75 @@
#pragma once
#include <azure/keyvault/common/client_options.hpp>
#include <azure/core/internal/client_options.hpp>
#include "azure/keyvault/keys/dll_import_export.hpp"
#include "azure/keyvault/keys/key_vault_key.hpp"
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
class ServiceVersion {
private:
std::string m_version;
public:
/**
* @brief Construct a new Service Version object
*
* @param version The string version for the Key Vault keys service.
*/
ServiceVersion(std::string version) : m_version(std::move(version)) {}
/**
* @brief Enable comparing the ext enum.
*
* @param other Another #ServiceVersion to be compared.
*/
bool operator==(ServiceVersion const& other) const { return m_version == other.m_version; }
/**
* @brief Return the #ServiceVersion string representation.
*
*/
std::string const& ToString() const { return m_version; }
/**
* @brief Use to send request to the 7.0 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const ServiceVersion V7_0;
/**
* @brief Use to send request to the 7.1 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const ServiceVersion V7_1;
/**
* @brief Use to send request to the 7.2 version of Key Vault service.
*
*/
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const ServiceVersion V7_2;
};
/**
* @brief Define the options to create an SDK Keys client.
*
*/
struct KeyClientOptions : public Azure::Security::KeyVault::ClientOptions
struct KeyClientOptions : public Azure::Core::_internal::ClientOptions
{
ServiceVersion Version;
/**
* @brief Construct a new Key Client Options object.
*
* @param version Optional version for the client.
*/
KeyClientOptions(
Azure::Security::KeyVault::ServiceVersion version
= Azure::Security::KeyVault::ServiceVersion::V7_2)
: ClientOptions(version)
KeyClientOptions(ServiceVersion version = ServiceVersion::V7_2)
: Azure::Core::_internal::ClientOptions(), Version(version)
{
}
};
std::string GetVersionString() const { return Version.ToString(); }
};
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -68,7 +68,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
private:
std::string m_name;
bool m_hardwareProtected;
JsonWebKeyType m_keyType;
KeyVaultKeyType m_keyType;
public:
/**
@ -98,11 +98,11 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
m_name = name;
if (hardwareProtected)
{
m_keyType = JsonWebKeyType::EcHsm;
m_keyType = KeyVaultKeyType::EcHsm;
}
else
{
m_keyType = JsonWebKeyType::Ec;
m_keyType = KeyVaultKeyType::Ec;
}
}
@ -116,7 +116,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* @brief Gets the key type to create, including Ec and EcHsm.
*
*/
JsonWebKeyType GetKeyType() const { return m_keyType; }
KeyVaultKeyType GetKeyType() const { return m_keyType; }
/**
* @brief Gets a value indicating whether to create a hardware-protected key in a hardware
@ -134,7 +134,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
private:
std::string m_name;
bool m_hardwareProtected;
JsonWebKeyType m_keyType;
KeyVaultKeyType m_keyType;
public:
/**
@ -170,11 +170,11 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
m_name = name;
if (hardwareProtected)
{
m_keyType = JsonWebKeyType::RsaHsm;
m_keyType = KeyVaultKeyType::RsaHsm;
}
else
{
m_keyType = JsonWebKeyType::Rsa;
m_keyType = KeyVaultKeyType::Rsa;
}
}
@ -188,7 +188,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* @brief Gets the key type to create, including Rsa and RsaHsm.
*
*/
JsonWebKeyType GetKeyType() const { return m_keyType; }
KeyVaultKeyType GetKeyType() const { return m_keyType; }
/**
* @brief Gets a value indicating whether to create a hardware-protected key in a hardware
@ -206,7 +206,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
private:
std::string m_name;
bool m_hardwareProtected;
JsonWebKeyType m_keyType;
KeyVaultKeyType m_keyType;
public:
/**
@ -234,11 +234,11 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
m_name = name;
if (hardwareProtected)
{
m_keyType = JsonWebKeyType::OctHsm;
m_keyType = KeyVaultKeyType::OctHsm;
}
else
{
m_keyType = JsonWebKeyType::Oct;
m_keyType = KeyVaultKeyType::Oct;
}
}
@ -252,7 +252,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* @brief Gets the key type to create, including Oct and OctHsm.
*
*/
JsonWebKeyType GetKeyType() const { return m_keyType; }
KeyVaultKeyType GetKeyType() const { return m_keyType; }
/**
* @brief Gets a value indicating whether to create a hardware-protected key in a hardware

View File

@ -9,6 +9,8 @@
#pragma once
#include "azure/keyvault/keys/dll_import_export.hpp"
#include <stdexcept>
#include <string>
@ -28,15 +30,28 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
*
* @param value The string value of the instance.
*/
KeyCurveName(std::string const& value)
explicit KeyCurveName(std::string value)
{
if (value.empty())
{
throw std::invalid_argument("The value for the curve name can not be empty");
}
m_value = value;
m_value = std::move(value);
}
/**
* @brief Construct a default key curve.
*
*/
KeyCurveName() = default;
/**
* @brief Enables using the equal operator for key curve.
*
* @param other A key curve to be compared.
*/
bool operator==(const KeyCurveName& other) const noexcept { return m_value == other.m_value; }
/**
* @brief Get the string value of the key curve.
*
@ -51,7 +66,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* types</a>.
*
*/
static KeyCurveName P256();
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyCurveName P256;
/**
* @brief Gets the SECG SECP256K1 elliptic curve.
@ -61,7 +76,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* types</a>.
*
*/
static KeyCurveName P256K();
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyCurveName P256K;
/**
* @brief Gets the NIST P-384 elliptic curve, AKA SECG curve SECP384R1.
@ -71,7 +86,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* types</a>.
*
*/
static KeyCurveName P384();
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyCurveName P384;
/**
* @brief Gets the NIST P-521 elliptic curve, AKA SECG curve SECP521R1.
@ -81,7 +96,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* types</a>.
*
*/
static KeyCurveName P521();
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyCurveName P521;
};
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -9,6 +9,8 @@
#pragma once
#include "azure/keyvault/keys/dll_import_export.hpp"
#include <string>
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
@ -27,7 +29,23 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
*
* @param operation The operation for the key as string.
*/
KeyOperation(std::string const& operation) : m_operation(operation) {}
explicit KeyOperation(std::string operation) : m_operation(std::move(operation)) {}
/**
* @brief Construct a default Key operation.
*
*/
KeyOperation() = default;
/**
* @brief Enables using the equal operator for key operations.
*
* @param other A key operation to be compared.
*/
bool operator==(const KeyOperation& other) const noexcept
{
return m_operation == other.m_operation;
}
/**
* @brief Returns the fully qualified type name of this instance.
@ -39,58 +57,44 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
/**
* @brief The key can be used to encrypt with the #Encrypt(EncryptionAlgorithm, Byte[],
* CancellationToken) method.
*
* @return Encrypt KeyOperation.
*/
static KeyOperation Encrypt() { return KeyOperation("encrypt"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation Encrypt;
/**
* @brief The key can be used to decrypt with the #Decrypt(EncryptionAlgorithm, Byte[],
* CancellationToken) method.
*
* @return Decrypt KeyOperation.
*/
static KeyOperation Decrypt() { return KeyOperation("decrypt"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation Decrypt;
/**
* @brief The key can be used to sign with the Sign(SignatureAlgorithm, Byte[],
* CancellationToken) method.
*
* @return Sign KeyOperation.
*/
static KeyOperation Sign() { return KeyOperation("sign"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation Sign;
/**
* @brief The key can be used to verify with the Verify(SignatureAlgorithm, Byte[], Byte[],
* CancellationToken) method.
*
* @return Verify KeyOperation.
*/
static KeyOperation Verify() { return KeyOperation("verify"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation Verify;
/**
* @brief The key can be used to wrap another key with the WrapKey(KeyWrapAlgorithm, Byte[],
* CancellationToken) method.
*
* @return WrapKey KeyOperation.
*/
static KeyOperation WrapKey() { return KeyOperation("wrapKey"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation WrapKey;
/**
* @brief The key can be used to unwrap another key with the UnwrapKey(KeyWrapAlgorithm, Byte[],
* CancellationToken) method.
*
* @return UnwrapKey KeyOperation.
*/
static KeyOperation UnwrapKey() { return KeyOperation("unwrapKey"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation UnwrapKey;
/**
* @brief The key can be imported during creation using the ImportKey(ImportKeyOptions,
* CancellationToken) method.
*
* @return Import KeyOperation.
*/
static KeyOperation Import() { return KeyOperation("import"); }
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyOperation Import;
};
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -9,6 +9,8 @@
#pragma once
#include "azure/keyvault/keys/dll_import_export.hpp"
#include <string>
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
@ -17,45 +19,77 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
* @brief The JsonWebKey types.
*
*/
enum class JsonWebKeyType
{
class KeyVaultKeyType {
private:
std::string m_value;
public:
/**
* @brief Construct a new JWT Type object
*
* @param jwt The JWT as string.
*/
explicit KeyVaultKeyType(std::string jwt) : m_value(std::move(jwt)) {}
/**
* @brief Construct a default JWT.
*
*/
KeyVaultKeyType() = default;
/**
* @brief Enables using the equal operator for JWT.
*
* @param other A JWT to be compared.
*/
bool operator==(const KeyVaultKeyType& other) const noexcept
{
return m_value == other.m_value;
}
/**
* @brief Return the JWK as string.
*
* @return The JWK represented as string.
*/
std::string const& ToString() const { return m_value; }
/**
* @brief An Elliptic Curve Cryptographic (ECC) algorithm.
*
*/
Ec,
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyVaultKeyType Ec;
/**
* @brief An Elliptic Curve Cryptographic (ECC) algorithm backed by a Hardware Security Module
* (HSM).
*
*/
EcHsm,
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyVaultKeyType EcHsm;
/**
* @brief An RSA cryptographic algorithm.
*
*/
Rsa,
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyVaultKeyType Rsa;
/**
* @brief An RSA cryptographic algorithm backed by a Hardware Security Module (HSM).
*
*/
RsaHsm,
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyVaultKeyType RsaHsm;
/**
* @brief An AES cryptographic algorithm.
*
*/
Oct,
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyVaultKeyType Oct;
/**
* @brief An AES cryptographic algorithm backed by a Hardware Security Module (HSM).
*
*/
OctHsm,
};
struct KeyType
{
static JsonWebKeyType KeyTypeFromString(std::string const& name);
static std::string KeyTypeToString(JsonWebKeyType kty);
AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyVaultKeyType OctHsm;
};
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -69,7 +69,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
*
* @return The type of the key.
*/
JsonWebKeyType const& GetKeyType() const { return Key.KeyType; }
KeyVaultKeyType const& GetKeyType() const { return Key.KeyType; }
/**
* @brief Gets the operations you can perform using the key.

View File

@ -13,41 +13,36 @@
#include "azure/keyvault/keys/json_web_key.hpp"
#include "azure/keyvault/keys/key_vault_key.hpp"
#include <azure/keyvault/common/internal/single_page.hpp>
#include <azure/core/http/http.hpp>
#include <vector>
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
struct SinglePage
{
Azure::Nullable<std::string> ContinuationToken;
};
struct KeyPropertiesSinglePage : public SinglePage
struct KeyPropertiesSinglePage : public Azure::Security::KeyVault::_internal::SinglePage
{
std::vector<KeyProperties> Items;
};
struct DeletedKeySinglePage : public SinglePage
struct DeletedKeySinglePage : public Azure::Security::KeyVault::_internal::SinglePage
{
std::vector<DeletedKey> Items;
};
struct GetSinglePageOptions
{
Azure::Nullable<std::string> ContinuationToken;
Azure::Nullable<uint32_t> MaxResults;
};
struct GetPropertiesOfKeysSinglePageOptions : public GetSinglePageOptions
struct GetPropertiesOfKeysSinglePageOptions
: public Azure::Security::KeyVault::_internal::GetSinglePageOptions
{
};
struct GetPropertiesOfKeyVersionsSinglePageOptions : public GetSinglePageOptions
struct GetPropertiesOfKeyVersionsSinglePageOptions
: public Azure::Security::KeyVault::_internal::GetSinglePageOptions
{
};
struct GetDeletedKeysSinglePageOptions : public GetSinglePageOptions
struct GetDeletedKeysSinglePageOptions
: public Azure::Security::KeyVault::_internal::GetSinglePageOptions
{
};
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -9,13 +9,13 @@
#pragma once
#include <azure/core/exception.hpp>
#include <azure/core/http/http.hpp>
#include <azure/core/operation.hpp>
#include <azure/core/operation_status.hpp>
#include <azure/core/response.hpp>
#include <azure/keyvault/common/internal/keyvault_pipeline.hpp>
#include <azure/keyvault/common/keyvault_exception.hpp>
#include "azure/keyvault/keys/key_vault_key.hpp"

View File

@ -1,7 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/keyvault/common/keyvault_exception.hpp"
#include <azure/core/exception.hpp>
#include <azure/keyvault/common/keyvault_exception.hpp>
#include "azure/keyvault/keys/delete_key_operation.hpp"
#include "azure/keyvault/keys/details/key_constants.hpp"
@ -33,8 +35,8 @@ Azure::Security::KeyVault::Keys::DeleteKeyOperation::PollInternal(Azure::Core::C
break;
}
default:
throw KeyVaultException(
"Unexpected operation status from Service response.", std::move(rawResponse));
throw Azure::Security::KeyVault::_detail::KeyVaultException::CreateException(
std::move(rawResponse));
}
if (m_status == Azure::Core::OperationStatus::Succeeded)

View File

@ -58,7 +58,7 @@ void Azure::Security::KeyVault::Keys::_detail::JsonWebKeySerializer::JsonWebKeyS
Azure::Core::Json::_internal::json& destJson)
{
// kty
destJson[_detail::KeyTypePropertyName] = KeyType::KeyTypeToString(jwk.KeyType);
destJson[_detail::KeyTypePropertyName] = jwk.KeyType.ToString();
// ops
for (KeyOperation op : jwk.KeyOperations())
@ -104,8 +104,7 @@ void Azure::Security::KeyVault::Keys::_detail::JsonWebKeySerializer::JsonWebDese
srcKey.SetKeyOperations(keyOperations);
}
srcKey.Id = jsonKey[_detail::KeyIdPropertyName].get<std::string>();
srcKey.KeyType
= KeyType::KeyTypeFromString(jsonKey[_detail::KeyTypePropertyName].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) {

View File

@ -5,6 +5,8 @@
#include <azure/core/http/http.hpp>
#include <azure/core/http/policies/policy.hpp>
#include <azure/keyvault/common/internal/single_page.hpp>
#include "azure/keyvault/keys/details/key_backup.hpp"
#include "azure/keyvault/keys/details/key_constants.hpp"
#include "azure/keyvault/keys/details/key_request_parameters.hpp"
@ -28,7 +30,7 @@ struct RequestWithContinuationToken
};
static inline RequestWithContinuationToken BuildRequestFromContinuationToken(
GetSinglePageOptions const& options,
Azure::Security::KeyVault::_internal::GetSinglePageOptions const& options,
std::vector<std::string>&& defaultPath)
{
RequestWithContinuationToken request;
@ -43,13 +45,13 @@ static inline RequestWithContinuationToken BuildRequestFromContinuationToken(
request.Path.clear();
request.Path.emplace_back(nextPageUrl.GetPath());
}
if (options.MaxResults)
if (options.MaxPageResults)
{
if (request.Query == nullptr)
{
request.Query = std::make_unique<std::map<std::string, std::string>>();
}
request.Query->emplace("maxResults", std::to_string(options.MaxResults.Value()));
request.Query->emplace("maxResults", std::to_string(options.MaxPageResults.Value()));
}
return request;
}
@ -94,7 +96,7 @@ Azure::Response<KeyVaultKey> KeyClient::GetKey(
Azure::Response<KeyVaultKey> KeyClient::CreateKey(
std::string const& name,
JsonWebKeyType keyType,
KeyVaultKeyType keyType,
CreateKeyOptions const& options,
Azure::Core::Context const& context) const
{

View File

@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/keyvault/keys/key_client_options.hpp"
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
const ServiceVersion ServiceVersion::V7_0("7.0");
const ServiceVersion ServiceVersion::V7_1("7.1");
const ServiceVersion ServiceVersion::V7_2("7.2");
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -4,12 +4,14 @@
#include "azure/keyvault/keys/key_curve_name.hpp"
#include "azure/keyvault/keys/details/key_constants.hpp"
using namespace Azure::Security::KeyVault::Keys;
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
KeyCurveName KeyCurveName::P256() { return KeyCurveName(_detail::P256Value); }
const KeyCurveName KeyCurveName::P256(_detail::P256Value);
KeyCurveName KeyCurveName::P256K() { return KeyCurveName(_detail::P256KValue); }
const KeyCurveName KeyCurveName::P256K(_detail::P256KValue);
KeyCurveName KeyCurveName::P384() { return KeyCurveName(_detail::P384Value); }
const KeyCurveName KeyCurveName::P384(_detail::P384Value);
KeyCurveName KeyCurveName::P521() { return KeyCurveName(_detail::P521Value); }
const KeyCurveName KeyCurveName::P521(_detail::P521Value);
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/keyvault/keys/key_operation.hpp"
namespace Azure { namespace Security { namespace KeyVault { namespace Keys {
const KeyOperation KeyOperation::Encrypt("encrypt");
const KeyOperation KeyOperation::Decrypt("decrypt");
const KeyOperation KeyOperation::Sign("sign");
const KeyOperation KeyOperation::Verify("verify");
const KeyOperation KeyOperation::WrapKey("wrapKey");
const KeyOperation KeyOperation::UnwrapKey("unwrapKey");
const KeyOperation KeyOperation::Import("import");
}}}} // namespace Azure::Security::KeyVault::Keys

View File

@ -20,9 +20,9 @@ std::string KeyRequestParameters::Serialize() const
Azure::Core::Json::_internal::json payload;
// kty
JsonOptional::SetFromNullable<JsonWebKeyType, std::string>(
m_keyType, payload, _detail::KeyTypePropertyName, [](JsonWebKeyType type) {
return KeyType::KeyTypeToString(type);
JsonOptional::SetFromNullable<KeyVaultKeyType, std::string>(
m_keyType, payload, _detail::KeyTypePropertyName, [](KeyVaultKeyType type) {
return type.ToString();
});
// attributes

View File

@ -8,60 +8,9 @@
using namespace Azure::Security::KeyVault::Keys;
JsonWebKeyType KeyType::KeyTypeFromString(std::string const& name)
{
if (name == _detail::EcValue)
{
return JsonWebKeyType::Ec;
}
if (name == _detail::EcHsmValue)
{
return JsonWebKeyType::EcHsm;
}
if (name == _detail::OctValue)
{
return JsonWebKeyType::Oct;
}
if (name == _detail::OctHsmValue)
{
return JsonWebKeyType::OctHsm;
}
if (name == _detail::RsaValue)
{
return JsonWebKeyType::Rsa;
}
if (name == _detail::RsaHsmValue)
{
return JsonWebKeyType::RsaHsm;
}
throw std::runtime_error("cannot convert " + name + " to key type (kty)");
}
std::string KeyType::KeyTypeToString(JsonWebKeyType kty)
{
if (kty == JsonWebKeyType::Ec)
{
return _detail::EcValue;
}
if (kty == JsonWebKeyType::EcHsm)
{
return _detail::EcHsmValue;
}
if (kty == JsonWebKeyType::Oct)
{
return _detail::OctValue;
}
if (kty == JsonWebKeyType::OctHsm)
{
return _detail::OctHsmValue;
}
if (kty == JsonWebKeyType::Rsa)
{
return _detail::RsaValue;
}
if (kty == JsonWebKeyType::RsaHsm)
{
return _detail::RsaHsmValue;
}
return std::string();
}
const KeyVaultKeyType KeyVaultKeyType::Ec(_detail::EcValue);
const KeyVaultKeyType KeyVaultKeyType::EcHsm(_detail::EcHsmValue);
const KeyVaultKeyType KeyVaultKeyType::Rsa(_detail::RsaValue);
const KeyVaultKeyType KeyVaultKeyType::RsaHsm(_detail::RsaHsmValue);
const KeyVaultKeyType KeyVaultKeyType::Oct(_detail::OctValue);
const KeyVaultKeyType KeyVaultKeyType::OctHsm(_detail::OctHsmValue);

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "azure/keyvault/common/keyvault_exception.hpp"
#include <azure/keyvault/common/keyvault_exception.hpp>
#include "azure/keyvault/keys/details/key_constants.hpp"
#include "azure/keyvault/keys/details/key_serializers.hpp"
@ -35,8 +35,8 @@ Azure::Security::KeyVault::Keys::RecoverDeletedKeyOperation::PollInternal(
break;
}
default:
throw KeyVaultException(
"Unexpected operation status from Service response.", std::move(rawResponse));
throw Azure::Security::KeyVault::_detail::KeyVaultException::CreateException(
std::move(rawResponse));
}
if (m_status == Azure::Core::OperationStatus::Succeeded)
{

View File

@ -49,7 +49,7 @@ int main()
KeyVaultKey cloudRsaKey = keyClient.GetKey(rsaKeyName).Value;
std::cout << "Key is returned with name " << cloudRsaKey.Name() << " and type "
<< KeyType::KeyTypeToString(cloudRsaKey.GetKeyType()) << std::endl;
<< cloudRsaKey.GetKeyType().ToString() << std::endl;
cloudRsaKey.Properties.ExpiresOn
= cloudRsaKey.Properties.ExpiresOn.Value() + std::chrono::hours(24 * 365);
@ -75,7 +75,7 @@ int main()
std::cout << "Authentication Exception happened:" << std::endl << e.what() << std::endl;
return 1;
}
catch (Azure::Security::KeyVault::KeyVaultException const& e)
catch (Azure::Core::RequestFailedException const& e)
{
std::cout << "KeyVault Client Exception happened:" << std::endl << e.Message << std::endl;
return 1;

View File

@ -100,7 +100,7 @@ int main()
std::cout << "Authentication Exception happened:" << std::endl << e.what() << std::endl;
return 1;
}
catch (Azure::Security::KeyVault::KeyVaultException const& e)
catch (Azure::Core::RequestFailedException const& e)
{
std::cout << "KeyVault Client Exception happened:" << std::endl << e.Message << std::endl;
return 1;

View File

@ -66,8 +66,7 @@ int main()
}
auto keyWithType = keyClient.GetKey(key.Name).Value;
std::cout << "Key is returned with name: " << keyWithType.Name()
<< " and type: " << KeyType::KeyTypeToString(keyWithType.GetKeyType())
<< std::endl;
<< " and type: " << keyWithType.GetKeyType().ToString() << std::endl;
}
if (!keysSinglePage.ContinuationToken.HasValue())
@ -155,7 +154,7 @@ int main()
std::cout << "Authentication Exception happened:" << std::endl << e.what() << std::endl;
return 1;
}
catch (Azure::Security::KeyVault::KeyVaultException const& e)
catch (Azure::Core::RequestFailedException const& e)
{
std::cout << "KeyVault Client Exception happened:" << std::endl << e.Message << std::endl;
return 1;

View File

@ -33,7 +33,7 @@ TEST_F(KeyVaultClientTest, BackupKey)
{
std::cout << std::endl << "- Create key";
auto response = keyClient.CreateKey(keyName, JsonWebKeyType::Ec);
auto response = keyClient.CreateKey(keyName, KeyVaultKeyType::Ec);
CheckValidResponse(response);
}
@ -56,7 +56,7 @@ TEST_F(KeyVaultClientTest, BackupKey)
std::this_thread::sleep_for(std::chrono::minutes(2));
}
{ // Check key is gone
EXPECT_THROW(keyClient.GetKey(keyName), Azure::Security::KeyVault::KeyVaultException);
EXPECT_THROW(keyClient.GetKey(keyName), Azure::Core::RequestFailedException);
}
{
// Restore

View File

@ -23,7 +23,7 @@ TEST_F(KeyVaultClientTest, CreateKey)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
@ -43,16 +43,18 @@ TEST_F(KeyVaultClientTest, CreateKeyWithOptions)
auto keyName = GetUniqueName();
Azure::Security::KeyVault::Keys::CreateKeyOptions options;
options.KeyOperations.push_back(Azure::Security::KeyVault::Keys::KeyOperation::Sign());
options.KeyOperations.push_back(Azure::Security::KeyVault::Keys::KeyOperation::Verify());
options.KeyOperations.push_back(Azure::Security::KeyVault::Keys::KeyOperation::Sign);
options.KeyOperations.push_back(Azure::Security::KeyVault::Keys::KeyOperation::Verify);
{
auto keyResponse = keyClient.CreateKey(
keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec, options);
keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec, options);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
EXPECT_EQ(keyVaultKey.GetKeyType(), Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
EXPECT_EQ(
keyVaultKey.GetKeyType().ToString(),
Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec.ToString());
auto& keyOperations = keyVaultKey.KeyOperations();
uint16_t expectedSize = 2;
EXPECT_EQ(keyOperations.size(), expectedSize);
@ -67,8 +69,8 @@ TEST_F(KeyVaultClientTest, CreateKeyWithOptions)
}
return false;
};
EXPECT_PRED1(findOperation, Azure::Security::KeyVault::Keys::KeyOperation::Sign());
EXPECT_PRED1(findOperation, Azure::Security::KeyVault::Keys::KeyOperation::Verify());
EXPECT_PRED1(findOperation, Azure::Security::KeyVault::Keys::KeyOperation::Sign);
EXPECT_PRED1(findOperation, Azure::Security::KeyVault::Keys::KeyOperation::Verify);
}
}
@ -83,12 +85,12 @@ TEST_F(KeyVaultClientTest, CreateKeyWithTags)
{
auto keyResponse = keyClient.CreateKey(
keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Rsa, options);
keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Rsa, options);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
EXPECT_EQ(keyVaultKey.GetKeyType(), Azure::Security::KeyVault::Keys::JsonWebKeyType::Rsa);
EXPECT_EQ(keyVaultKey.GetKeyType(), Azure::Security::KeyVault::Keys::KeyVaultKeyType::Rsa);
auto findTag = [keyVaultKey](std::string key, std::string value) {
// Will throw if key is not found
@ -127,7 +129,7 @@ TEST_F(KeyVaultClientTest, CreateEcKeyWithCurve)
{
auto ecKey = Azure::Security::KeyVault::Keys::CreateEcKeyOptions(keyName);
ecKey.CurveName = Azure::Security::KeyVault::Keys::KeyCurveName::P384();
ecKey.CurveName = Azure::Security::KeyVault::Keys::KeyCurveName::P384;
auto keyResponse = keyClient.CreateEcKey(ecKey);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
@ -143,7 +145,7 @@ TEST_F(KeyVaultClientTest, CreateEcKeyWithCurve)
EXPECT_TRUE(keyVaultKey.Key.CurveName.HasValue());
EXPECT_EQ(
keyVaultKey.Key.CurveName.Value().ToString(),
Azure::Security::KeyVault::Keys::KeyCurveName::P384().ToString());
Azure::Security::KeyVault::Keys::KeyCurveName::P384.ToString());
}
}

View File

@ -48,7 +48,7 @@ TEST_F(KeyVaultClientTest, DeleteKey)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
@ -91,7 +91,7 @@ TEST_F(KeyVaultClientTest, DeleteKeyOperationPoll)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
@ -118,7 +118,7 @@ TEST_F(KeyVaultClientTest, DeleteInvalidKey)
{
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
}
catch (Azure::Security::KeyVault::KeyVaultException const& error)
catch (Azure::Core::RequestFailedException const& error)
{
EXPECT_EQ(
static_cast<typename std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
@ -142,7 +142,7 @@ TEST_F(KeyVaultClientTest, DoubleDelete)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
}
{
auto duration = std::chrono::system_clock::now() + std::chrono::minutes(3);
@ -156,7 +156,7 @@ TEST_F(KeyVaultClientTest, DoubleDelete)
{
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
}
catch (Azure::Security::KeyVault::KeyVaultException const& error)
catch (Azure::Core::RequestFailedException const& error)
{
EXPECT_EQ(
static_cast<typename std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
@ -180,7 +180,7 @@ TEST_F(KeyVaultClientTest, DoubleDeleteBeforePollComplete)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
}
{
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
@ -191,7 +191,7 @@ TEST_F(KeyVaultClientTest, DoubleDeleteBeforePollComplete)
{
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
}
catch (Azure::Security::KeyVault::KeyVaultException const& error)
catch (Azure::Core::RequestFailedException const& error)
{
EXPECT_EQ(
static_cast<typename std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
@ -216,7 +216,7 @@ TEST_F(KeyVaultClientTest, CreateDeletedKey)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
}
{
auto duration = std::chrono::system_clock::now() + std::chrono::minutes(3);
@ -229,9 +229,9 @@ TEST_F(KeyVaultClientTest, CreateDeletedKey)
try
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
}
catch (Azure::Security::KeyVault::KeyVaultException const& error)
catch (Azure::Core::RequestFailedException const& error)
{
EXPECT_EQ(
static_cast<typename std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
@ -256,7 +256,7 @@ TEST_F(KeyVaultClientTest, CreateDeletedKeyBeforePollComplete)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
}
{
auto keyResponseLRO = keyClient.StartDeleteKey(keyName);
@ -266,9 +266,9 @@ TEST_F(KeyVaultClientTest, CreateDeletedKeyBeforePollComplete)
try
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
}
catch (Azure::Security::KeyVault::KeyVaultException const& error)
catch (Azure::Core::RequestFailedException const& error)
{
EXPECT_EQ(
static_cast<typename std::underlying_type<Azure::Core::Http::HttpStatusCode>::type>(
@ -293,7 +293,7 @@ TEST_F(KeyVaultClientTest, GetDeletedKey)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
@ -313,10 +313,8 @@ TEST_F(KeyVaultClientTest, GetDeletedKey)
auto deletedKey = keyClient.GetDeletedKey(keyName).Value;
EXPECT_FALSE(deletedKey.RecoveryId.empty());
EXPECT_EQ(deletedKey.Name(), keyName);
auto expectedType = Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec;
EXPECT_EQ(
Azure::Security::KeyVault::Keys::KeyType::KeyTypeToString(expectedType),
Azure::Security::KeyVault::Keys::KeyType::KeyTypeToString(deletedKey.Key.KeyType));
auto expectedType = Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec;
EXPECT_EQ(expectedType, deletedKey.Key.KeyType);
}
}
@ -327,7 +325,7 @@ TEST_F(KeyVaultClientTest, DeleteOperationResumeToken)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);
@ -365,7 +363,7 @@ TEST_F(KeyVaultClientTest, RecoverOperationResumeToken)
{
auto keyResponse
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::JsonWebKeyType::Ec);
= keyClient.CreateKey(keyName, Azure::Security::KeyVault::Keys::KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);

View File

@ -30,7 +30,7 @@ TEST_F(KeyVaultClientTest, GetSingleKey)
auto key = keyResponse.Value;
EXPECT_EQ(key.Name(), keyName);
EXPECT_EQ(key.GetKeyType(), JsonWebKeyType::Ec);
EXPECT_EQ(key.GetKeyType(), KeyVaultKeyType::Ec);
}
TEST_F(KeyVaultClientTest, GetPropertiesOfKeysOnePage)

View File

@ -7,6 +7,8 @@
#include "gtest/gtest.h"
#include <azure/core/exception.hpp>
#include <azure/keyvault/common/internal/base64url.hpp>
#include <azure/keyvault/common/keyvault_exception.hpp>
#include <azure/keyvault/key_vault.hpp>
@ -24,7 +26,7 @@ TEST_F(KeyVaultClientTest, ImportKey)
{
KeyClient keyClient(m_keyVaultUrl, m_credential);
JsonWebKey key;
key.KeyType = JsonWebKeyType::Rsa;
key.KeyType = KeyVaultKeyType::Rsa;
// Values from https://docs.microsoft.com/en-us/rest/api/keyvault/importkey/importkey
key.N = Base64Url::Base64UrlDecode(
"nKAwarTrOpzd1hhH4cQNdVTgRF-b0ubPD8ZNVf0UXjb62QuAk3Dn68ESThcF7SoDYRx2QVcfoMC9WCcuQUQDieJF-"
@ -56,8 +58,8 @@ TEST_F(KeyVaultClientTest, ImportKey)
"Uyf9s52ywLylhcVE3jfbjOgEozlSwKyhqfXkLpMLWHqOKj9fcfYd4PWKPOgpzWsqjA6fJbBUM"
"Yo0CU2G9cWCtVodO7sBJVSIZunWrAlBc");
std::string keyName(GetUniqueName());
key.CurveName = KeyCurveName::P521();
key.SetKeyOperations({KeyOperation::Sign()});
key.CurveName = KeyCurveName::P521;
key.SetKeyOperations({KeyOperation::Sign});
auto response = keyClient.ImportKey(keyName, key);
CheckValidResponse(response);
@ -66,7 +68,7 @@ TEST_F(KeyVaultClientTest, ImportKey)
EXPECT_EQ(key.E, returnedkey.Key.E);
EXPECT_EQ(key.CurveName.Value().ToString(), returnedkey.Key.CurveName.Value().ToString());
EXPECT_EQ(returnedkey.KeyOperations().size(), 1);
EXPECT_EQ(returnedkey.KeyOperations()[0].ToString(), KeyOperation::Sign().ToString());
EXPECT_EQ(returnedkey.KeyOperations()[0].ToString(), KeyOperation::Sign.ToString());
{
// delete + purge

View File

@ -7,6 +7,7 @@
#include <azure/identity/client_secret_credential.hpp>
#include <azure/keyvault/key_vault.hpp>
#include <exception>
#include <memory>
using namespace Azure::Security::KeyVault::Keys;
@ -21,6 +22,36 @@ TEST(KeyClient, initClient)
{
KeyClientOptions options;
options.Retry.MaxRetries = 10;
EXPECT_NO_THROW(KeyClient keyClient("vaultUrl", credential));
EXPECT_NO_THROW(KeyClient keyClient("vaultUrl", credential, options));
}
}
TEST(KeyClient, ServiceVersion)
{
auto credential
= std::make_shared<Azure::Identity::ClientSecretCredential>("tenantID", "AppId", "SecretId");
{
// 7.0
EXPECT_NO_THROW(auto options = KeyClientOptions(ServiceVersion::V7_0);
KeyClient keyClient("vaultUrl", credential, options);
EXPECT_EQ(options.GetVersionString(), "7.0"););
}
{
// 7.1
EXPECT_NO_THROW(auto options = KeyClientOptions(ServiceVersion::V7_1);
KeyClient keyClient("vaultUrl", credential, options);
EXPECT_EQ(options.GetVersionString(), "7.1"););
}
{
// 7.2
EXPECT_NO_THROW(auto options = KeyClientOptions(ServiceVersion::V7_2);
KeyClient keyClient("vaultUrl", credential, options);
EXPECT_EQ(options.GetVersionString(), "7.2"););
}
{
// arbitrary version
EXPECT_NO_THROW(auto options = KeyClientOptions(ServiceVersion("1.0"));
KeyClient keyClient("vaultUrl", credential, options);
EXPECT_EQ(options.GetVersionString(), "1.0"););
}
}

View File

@ -25,7 +25,7 @@ TEST_F(KeyVaultClientTest, UpdateProperties)
auto keyName = GetUniqueName();
auto updateTo = DateTime::Parse("20301031T00:00:00Z", DateTime::DateFormat::Rfc3339);
{
auto keyResponse = keyClient.CreateKey(keyName, JsonWebKeyType::Ec);
auto keyResponse = keyClient.CreateKey(keyName, KeyVaultKeyType::Ec);
CheckValidResponse(keyResponse);
auto keyVaultKey = keyResponse.Value;
EXPECT_EQ(keyVaultKey.Name(), keyName);