CCF
Loading...
Searching...
No Matches
cose_utils.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3
4#pragma once
5
6#include "crypto/cbor.h"
7
9{
10 inline std::vector<std::vector<uint8_t>> parse_x5chain(
11 const ccf::cbor::Value& x5chain_value)
12 {
13 std::vector<std::vector<uint8_t>> chain;
14 // x5chain can be either an array of byte strings or a single byte string
15 try
16 {
17 for (size_t i = 0; i < x5chain_value->size(); ++i)
18 {
19 const auto x5chain_ctx = "x5chain[" + std::to_string(i) + "]";
20 const auto& bytes = ccf::cbor::rethrow_with_msg(
21 [&]() { return x5chain_value->array_at(i)->as_bytes(); },
22 x5chain_ctx);
23 chain.emplace_back(bytes.begin(), bytes.end());
24 }
25 }
26 catch (const ccf::cbor::CBORDecodeError&)
27 {
28 auto bytes = ccf::cbor::rethrow_with_msg(
29 [&]() { return x5chain_value->as_bytes(); }, "x5chain");
30 chain.emplace_back(bytes.begin(), bytes.end());
31 }
32 return chain;
33 }
34}
Definition cbor.h:84
decltype(auto) rethrow_with_msg(auto &&f, std::string_view msg={})
Definition cbor.h:123
std::shared_ptr< ValueImpl > Value
Definition cbor.h:26
Definition cose_utils.h:9
std::vector< std::vector< uint8_t > > parse_x5chain(const ccf::cbor::Value &x5chain_value)
Definition cose_utils.h:10