/*
 * Copyright (c) 2025-2026 The Johns Hopkins University Applied Physics
 * Laboratory LLC.
 *
 * This file is part of the Bundle Protocol Security Library (BSL).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * This work was performed for the Jet Propulsion Laboratory, California
 * Institute of Technology, sponsored by the United States Government under
 * the prime contract 80NM0018D0004 between the Caltech and NASA under
 * subcontract 1700763.
 */

/**
 * @file SecResult.h
 * @ingroup backend_dyn
 * @brief Defines the RFC 9172 Security Result
 *
 * @details
 * This represents the Security Result field of the Abstract Security Block. As
 * defined in RFC 9172.
 *
 * <blockquote>
 * An individual result is represented as a CBOR array comprising a 2-tuple of a result
 * Id and a result value, defined as follows.
 *
 * Result Id:
 *
 *   * This field identifies which security result is being specified.
 *   * Some security results capture the primary output of a cipher suite.
 *   * Other security results contain additional annotative information from cipher suite processing.
 *   * This field SHALL be represented as a CBOR unsigned integer.
 *   * Security result Ids will be as specified in Section 3.10.
 *
 * Result Value:
 *
 *   * This field captures the value associated with the result.
 *   * This field SHALL be represented by the applicable CBOR representation of the result value, in accordance with
 * Section 3.10.
 * </blockquote>
 *
 * RFC 9172 **Section 3.10**
 * <blockquote>
 *  * Each security context MUST define its own context parameters and results.
 *  * Each defined parameter and result is represented as the tuple of an identifier and a value.
 *  * Identifiers are always represented as a CBOR unsigned integer.
 *  * The CBOR encoding of values is as defined by the security context specification.
 *  * Identifiers MUST be unique for a given security context but do not need to be unique amongst all security
 * contexts.
 * </blockquote>
 *
 * https://www.rfc-editor.org/rfc/rfc9172.html#section-3.6-3.12.1
 *
 * @author Bill.Van.Besien@jhuapl.edu
 */
/** @file
 * @brief Implementation of a RFC9172 Result
 * @ingroup backend_dyn
 */
#ifndef BSLB_SECRESULT_H_
#define BSLB_SECRESULT_H_

#include <stdint.h>

#include <m-array.h>
#include <m-bstring.h>

#include <BPSecLib_Private.h>

struct BSL_SecResult_s
{
    /// @brief Result ID, which is context dependent, based on security context.
    uint64_t result_id;

    /// @brief Context ID, put in here for convenience.
    int64_t context_id;

    /// @brief Target block id, put in here for convenience.
    uint64_t target_block_num;

    /// @brief Result as byte array
    m_bstring_t _bytes;
};

/// OPLIST for ::BSL_SecParam_t
#define M_OPL_BSL_SecResult_t()                                                                                   \
    (INIT(API_2(BSL_SecResult_Init)), INIT_SET(API_6(BSL_SecResult_InitSet)), CLEAR(API_2(BSL_SecResult_Deinit)), \
     SET(API_6(BSL_SecResult_Set)))

/** @struct BSLB_SecResultList_t
 * Defines a basic list of Security Results (::BSL_SecResult_t).
 */
/// @cond Doxygen_Suppress
// NOLINTBEGIN
// GCOV_EXCL_START
M_ARRAY_DEF(BSLB_SecResultList, BSL_SecResult_t, M_OPL_BSL_SecResult_t())
// GCOV_EXCL_STOP
// NOLINTEND
/// @endcond

#endif /* BSLB_SECRESULT_H_ */
