CCF
Loading...
Searching...
No Matches
cose_common.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 <qcbor/qcbor.h>
7#include <stdexcept>
8#include <string>
9#include <t_cose/t_cose_common.h>
10
11namespace ccf::cose
12{
13 namespace headers
14 {
15 static constexpr int64_t PARAM_ALG = 1;
16 static constexpr int64_t PARAM_CONTENT_TYPE = 3;
17 static constexpr int64_t PARAM_KID = 4;
18 static constexpr int64_t PARAM_X5CHAIN = 33;
19
20 static constexpr auto CONTENT_TYPE_APPLICATION_JSON_VALUE =
21 "application/json";
22 }
23
24 using Signature = std::span<const uint8_t>;
25
26 static std::string qcbor_buf_to_string(const UsefulBufC& buf)
27 {
28 return std::string(reinterpret_cast<const char*>(buf.ptr), buf.len);
29 }
30
31 static std::vector<uint8_t> qcbor_buf_to_byte_vector(const UsefulBufC& buf)
32 {
33 auto ptr = static_cast<const uint8_t*>(buf.ptr);
34 return {ptr, ptr + buf.len};
35 }
36
37 static bool is_ecdsa_alg(int64_t cose_alg)
38 {
39 return cose_alg == T_COSE_ALGORITHM_ES256 ||
40 cose_alg == T_COSE_ALGORITHM_ES384 || cose_alg == T_COSE_ALGORITHM_ES512;
41 }
42
43 static bool is_rsa_alg(int64_t cose_alg)
44 {
45 return cose_alg == T_COSE_ALGORITHM_PS256 ||
46 cose_alg == T_COSE_ALGORITHM_PS384 || cose_alg == T_COSE_ALGORITHM_PS512;
47 }
48
49 struct COSEDecodeError : public std::runtime_error
50 {
51 COSEDecodeError(const std::string& msg) : std::runtime_error(msg) {}
52 };
53
54 struct COSESignatureValidationError : public std::runtime_error
55 {
56 COSESignatureValidationError(const std::string& msg) :
57 std::runtime_error(msg)
58 {}
59 };
60
61}
Definition cose_auth.cpp:21
std::span< const uint8_t > Signature
Definition cose_common.h:24
STL namespace.
Definition cose_common.h:50
COSEDecodeError(const std::string &msg)
Definition cose_common.h:51
Definition cose_common.h:55
COSESignatureValidationError(const std::string &msg)
Definition cose_common.h:56