CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
LargeBlobStore.cpp
Go to the documentation of this file.
1
6
8
9#include <cstring>
10
11namespace cdc::mod_fido2 {
12
13// 0x80 (empty CBOR array) followed by the first 16 bytes of SHA-256(0x80).
15 0x80,
16 0x76, 0xbe, 0x8b, 0x52, 0x8d, 0x00, 0x75, 0xf7,
17 0xaa, 0xe9, 0x8d, 0x6f, 0xa5, 0x7a, 0x6d, 0x3c,
18};
19
21 buffer_ = nullptr;
22 capacity_ = 0;
23 expected_ = 0;
24 received_ = 0;
25 active_ = false;
26}
27
28LbResult LargeBlobWriteSession::begin(uint8_t* buffer, uint16_t capacity, uint32_t totalLength) {
29 uint16_t limit = capacity < kLargeBlobMaxArray ? capacity : kLargeBlobMaxArray;
30 if (totalLength > limit) {
32 }
33 if (totalLength < kLargeBlobEmptyLen) {
35 }
36 buffer_ = buffer;
37 capacity_ = capacity;
38 expected_ = static_cast<uint16_t>(totalLength);
39 received_ = 0;
40 active_ = true;
41 return LbResult::Ok;
42}
43
44LbResult LargeBlobWriteSession::append(uint32_t offset, const uint8_t* data, uint16_t len) {
45 if (!active_) {
46 return LbResult::BadSeq;
47 }
48 if (offset != received_) {
49 return LbResult::BadSeq;
50 }
51 if (offset + static_cast<uint32_t>(len) > expected_) {
53 }
54 if (len && data) {
55 memcpy(buffer_ + offset, data, len);
56 }
57 received_ = static_cast<uint16_t>(received_ + len);
58 return LbResult::Ok;
59}
60
61} // namespace cdc::mod_fido2
Portable authenticatorLargeBlobs write-session accumulator and the canonical empty large-blob array c...
LbResult begin(uint8_t *buffer, uint16_t capacity, uint32_t totalLength)
Begins a write declaring the full serialized length.
LbResult append(uint32_t offset, const uint8_t *data, uint16_t len)
Appends one fragment at offset.
void reset()
Discards any partial write and returns to the idle state.
const uint8_t * data() const
Pointer to the accumulated buffer (valid after begin).
constexpr uint16_t kLargeBlobEmptyLen
LbResult
Outcome of a write-session step, mapped to a CTAP status by the caller.
@ StorageFull
declared total length exceeds the buffer / kLargeBlobMaxArray
@ BadSeq
fragment offset out of order, or no active session
@ BadLength
declared total too small, or a fragment overruns the total
constexpr uint16_t kLargeBlobMaxArray
Largest serialized large-blob array, advertised as maxSerializedLargeBlobArray.
const uint8_t kLargeBlobEmpty[kLargeBlobEmptyLen]
Canonical empty large-blob array bytes.