blob: 407453a9ac7fc56e2cd6d4abe38c6b15230f44d3 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/memory/ptr_util.h"
#include "device/fido/u2f_apdu_response.h"
namespace device {
std::unique_ptr<U2fApduResponse> U2fApduResponse::CreateFromMessage(
const std::vector<uint8_t>& message) {
uint16_t status_bytes;
Status response_status;
// Invalid message size, data is appended by status byte
if (message.size() < 2)
return nullptr;
status_bytes = message[message.size() - 2] << 8;
status_bytes |= message[message.size() - 1];
response_status = static_cast<Status>(status_bytes);
std::vector<uint8_t> data(message.begin(), message.end() - 2);
return std::make_unique<U2fApduResponse>(std::move(data), response_status);
}
U2fApduResponse::U2fApduResponse(std::vector<uint8_t> message,
Status response_status)
: response_status_(response_status), data_(std::move(message)) {}
U2fApduResponse::~U2fApduResponse() = default;
} // namespace device