AuthenticatorGetInfoResponse.cpp [plain text]
#include "config.h"
#include "AuthenticatorGetInfoResponse.h"
#if ENABLE(WEB_AUTHN)
#include "CBORValue.h"
#include "CBORWriter.h"
namespace fido {
template <typename Container>
cbor::CBORValue toArrayValue(const Container& container)
{
cbor::CBORValue::ArrayValue value;
value.reserveInitialCapacity(container.size());
for (const auto& item : container)
value.append(cbor::CBORValue(item));
return cbor::CBORValue(WTFMove(value));
}
AuthenticatorGetInfoResponse::AuthenticatorGetInfoResponse(StdSet<ProtocolVersion>&& versions, Vector<uint8_t>&& aaguid)
: m_versions(WTFMove(versions))
, m_aaguid(WTFMove(aaguid))
{
}
AuthenticatorGetInfoResponse& AuthenticatorGetInfoResponse::setMaxMsgSize(uint32_t maxMsgSize)
{
m_maxMsgSize = maxMsgSize;
return *this;
}
AuthenticatorGetInfoResponse& AuthenticatorGetInfoResponse::setPinProtocols(Vector<uint8_t>&& pinProtocols)
{
m_pinProtocols = WTFMove(pinProtocols);
return *this;
}
AuthenticatorGetInfoResponse& AuthenticatorGetInfoResponse::setExtensions(Vector<String>&& extensions)
{
m_extensions = WTFMove(extensions);
return *this;
}
AuthenticatorGetInfoResponse& AuthenticatorGetInfoResponse::setOptions(AuthenticatorSupportedOptions&& options)
{
m_options = WTFMove(options);
return *this;
}
Vector<uint8_t> encodeAsCBOR(const AuthenticatorGetInfoResponse& response)
{
using namespace cbor;
CBORValue::MapValue deviceInfoMap;
CBORValue::ArrayValue versionArray;
for (const auto& version : response.versions())
versionArray.append(version == ProtocolVersion::kCtap ? kCtap2Version : kU2fVersion);
deviceInfoMap.emplace(CBORValue(1), CBORValue(WTFMove(versionArray)));
if (response.extensions())
deviceInfoMap.emplace(CBORValue(2), toArrayValue(*response.extensions()));
deviceInfoMap.emplace(CBORValue(3), CBORValue(response.aaguid()));
deviceInfoMap.emplace(CBORValue(4), convertToCBOR(response.options()));
if (response.maxMsgSize())
deviceInfoMap.emplace(CBORValue(5), CBORValue(static_cast<int64_t>(*response.maxMsgSize())));
if (response.pinProtocol())
deviceInfoMap.emplace(CBORValue(6), toArrayValue(*response.pinProtocol()));
auto encodedBytes = CBORWriter::write(CBORValue(WTFMove(deviceInfoMap)));
ASSERT(encodedBytes);
return *encodedBytes;
}
}
#endif // ENABLE(WEB_AUTHN)