BSL v0.0.0
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
SecurityActionSet.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 "SecurityActionSet.h"
27
29{
30 CHK_AS_BOOL(self != NULL);
31 CHK_AS_BOOL(self->sec_operations_count <= self->arrays_capacity);
32 if (self->arrays_capacity > 0)
33 {
34 CHK_AS_BOOL(self->arrays_capacity == sizeof(self->sec_operations) / sizeof(BSL_SecOper_t));
35 }
36
37 // Make sure the arrays are in sync (have equal lengths)
38 // 0 means unused.
39 for (size_t i = 0; i < self->arrays_capacity; i++)
40 {
41 if (self->new_block_ids[i] == 0)
42 {
43 CHK_AS_BOOL(self->new_block_types[i] == 0);
44 }
45 }
46 // TODO, make sure every element in the array that
47 // is not a sec oper is set to all zeros.
48 return true;
49}
50
52{
53 return sizeof(BSL_SecurityActionSet_t);
54}
55
57{
58 ASSERT_ARG_NONNULL(self);
59
60 memset(self, 0, sizeof(*self));
61 self->arrays_capacity = sizeof(self->sec_operations) / sizeof(BSL_SecOper_t);
62
63 ASSERT_POSTCONDITION(BSL_SecurityActionSet_IsConsistent(self));
64}
65
67{
68 ASSERT_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
69 self->err_code++;
70}
71
73{
74 ASSERT_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
75
76 return self->err_code;
77}
78
80{
81 ASSERT_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
82
83 for (size_t operation_index = 0; operation_index < self->arrays_capacity; operation_index++)
84 {
85 BSL_SecOper_Deinit(&(self->sec_operations[operation_index]));
86 }
87 memset(self, 0, sizeof(*self));
88}
89
91{
92 CHK_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
93 CHK_PRECONDITION(BSL_SecOper_IsConsistent(sec_oper));
94 CHK_PRECONDITION(self->sec_operations_count < self->arrays_capacity - 1);
95
96 self->sec_operations[self->sec_operations_count++] = *sec_oper;
97
98 CHK_POSTCONDITION(BSL_SecurityActionSet_IsConsistent(self));
99 return BSL_SUCCESS;
100}
101
103{
104 ASSERT_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
105 return self->sec_operations_count;
106}
107
109{
110 ASSERT_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
111 ASSERT_PRECONDITION(index < BSL_SecurityActionSet_CountSecOpers(self));
112 ASSERT_PRECONDITION(index < self->arrays_capacity);
113
114 const BSL_SecOper_t *sec_oper = &self->sec_operations[index];
115
116 // The return security operation should be valid
117 ASSERT_POSTCONDITION(BSL_SecOper_IsConsistent(sec_oper));
118 return sec_oper;
119}
120
122{
123 CHK_PRECONDITION(BSL_SecurityActionSet_IsConsistent(self));
124 return self->err_code;
125}
@ BSL_SUCCESS
Placeholder for non-error code.
struct BSL_SecurityActionSet_s BSL_SecurityActionSet_t
Forward declaration of PolicyActionSet, which contains information for BSL to process the Bundle.
void BSL_SecOper_Deinit(BSL_SecOper_t *self)
Empty and release any resources used internally by this structure.
bool BSL_SecOper_IsConsistent(const BSL_SecOper_t *self)
Returns true if internal consistency and sanity checks pass.
const BSL_SecOper_t * BSL_SecurityActionSet_GetSecOperAtIndex(const BSL_SecurityActionSet_t *self, size_t index)
Returns the Security Operation at the given index.
int BSL_SecurityActionSet_AppendSecOper(BSL_SecurityActionSet_t *self, const BSL_SecOper_t *sec_oper)
Append a security operation to the security action set.
int BSL_SecurityActionSet_GetErrCode(const BSL_SecurityActionSet_t *self)
Get the error code after querying (inspecting) policy actions.
size_t BSL_SecurityActionSet_Sizeof(void)
Returns size of the struct, helpful for dynamic allocation.
bool BSL_SecurityActionSet_IsConsistent(const BSL_SecurityActionSet_t *self)
Return true if internal sanity and consistency checks pass.
void BSL_SecurityActionSet_IncrError(BSL_SecurityActionSet_t *self)
Increment a security failure for this action set.
size_t BSL_SecurityActionSet_CountErrors(const BSL_SecurityActionSet_t *self)
Returns count of failures after processing this action set.
void BSL_SecurityActionSet_Deinit(BSL_SecurityActionSet_t *self)
Zeroize, clear, and release itself and any owned resources.
void BSL_SecurityActionSet_Init(BSL_SecurityActionSet_t *self)
Initialize a new security action set.
size_t BSL_SecurityActionSet_CountSecOpers(const BSL_SecurityActionSet_t *self)
Count number of security operations present in this policy action set.
Implementation of construct holding details of security operations for a bundle.
Contains the populated security operations for this bundle.
uint64_t new_block_ids[BSL_SECURITYACTIONSET_MAX_OPS]
Array for IDs of blocks to be created.
uint64_t new_block_types[BSL_SECURITYACTIONSET_MAX_OPS]
Array for block type codes of blocks to be created.
size_t arrays_capacity
Capacity of sec_operations.
BSL_SecOper_t sec_operations[BSL_SECURITYACTIONSET_MAX_OPS]
Fixed array of security operations (for simpler mem management)
size_t sec_operations_count
Count of sec_operations.
int err_code
General error code.