BSL v0.0.0
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
SecResult.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 The Johns Hopkins University Applied Physics
3 * Laboratory LLC.
4 *
5 * This file is part of the Bundle Protocol Security Library (BSL).
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * This work was performed for the Jet Propulsion Laboratory, California
18 * Institute of Technology, sponsored by the United States Government under
19 * the prime contract 80NM0018D0004 between the Caltech and NASA under
20 * subcontract 1700763.
21 */
26#include "SecResult.h"
27
28int BSL_SecResult_Init(BSL_SecResult_t *self, uint64_t result_id, uint64_t context_id, uint64_t target_block_num,
29 BSL_Data_t content)
30{
31 CHK_ARG_NONNULL(self);
32 CHK_ARG_EXPR(content.len > 0);
33 CHK_ARG_NONNULL(content.ptr);
34
35 memset(self, 0, sizeof(*self));
36 self->result_id = result_id;
37 self->context_id = context_id;
38 self->target_block_num = target_block_num;
39 CHK_PROPERTY(content.len < sizeof(self->_bytes));
40 self->_bytelen = content.len;
41 memcpy(self->_bytes, content.ptr, self->_bytelen);
42
43 CHK_POSTCONDITION(BSL_SecResult_IsConsistent(self));
44 return BSL_SUCCESS;
45}
46
48{
49 CHK_AS_BOOL(self != NULL);
50 CHK_AS_BOOL(self->context_id > 0);
51 CHK_AS_BOOL(self->result_id > 0);
52 // Check that the target block num is sane (not junk)
53 CHK_AS_BOOL(self->target_block_num < 10000);
54 CHK_AS_BOOL(self->_bytelen > 0);
55 // TODO (Confirm any bytes in the buffer after _bytelen are all zeroes)
56 return true;
57}
58
60{
61 return sizeof(BSL_SecResult_t);
62}
struct BSL_SecResult_s BSL_SecResult_t
Represents a security result, being a 2-tuple of (result-id, bytes).
@ BSL_SUCCESS
Placeholder for non-error code.
int BSL_SecResult_Init(BSL_SecResult_t *self, uint64_t result_id, uint64_t context_id, uint64_t target_block_num, BSL_Data_t content)
Populate a pre-allocated SecResult.
Definition SecResult.c:28
bool BSL_SecResult_IsConsistent(const BSL_SecResult_t *self)
Return true when internal invariant checks pass.
Definition SecResult.c:47
size_t BSL_SecResult_Sizeof(void)
Returns size in bytes of BSL_SecResult_t.
Definition SecResult.c:59
Defines the RFC 9172 Security Result.
Heap data storage and views.
size_t len
Size of the data buffer.
BSL_DataPtr_t ptr
Pointer to the front of the buffer.
uint8_t _bytes[BSL_DEFAULT_BYTESTR_LEN+1]
Result as byte array, up to a given maximum.
Definition SecResult.h:90
uint64_t target_block_num
Target block id, put in here for convenience.
Definition SecResult.h:87
uint64_t result_id
Result ID, which is context depdendent, based on security context.
Definition SecResult.h:81
size_t _bytelen
Length of data (in bytes) of the contained bytestring. Always less than BSL_DEFAULT_BYTESTR_LEN.
Definition SecResult.h:93
uint64_t context_id
Context ID, put in here for convenience.
Definition SecResult.h:84