SolidSyslog coverage report
Current view: top level - Core/Source - SolidSyslogCrc16Policy.c (source / functions) Coverage Total Hit
Test: SolidSyslog Lines: 100.0 % 13 13
Test Date: 2026-11-12 23:14:35 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
       2              :  * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
       3              :  */
       4              : 
       5              : #include "SolidSyslogCrc16Policy.h"
       6              : 
       7              : #include <stdbool.h>
       8              : #include <stdint.h>
       9              : 
      10              : #include "SolidSyslogCrc16.h"
      11              : #include "SolidSyslogSecurityPolicyDefinition.h"
      12              : 
      13              : enum
      14              : {
      15              :     CRC16_SIZE = 2
      16              : };
      17              : 
      18              : static bool Crc16Policy_Crc16SealRecord(
      19              :     struct SolidSyslogSecurityPolicy* self,
      20              :     const struct SolidSyslogSecurityRecord* record
      21              : );
      22              : static enum SolidSyslogSecurityPolicyOpenResult Crc16Policy_Crc16OpenRecord(
      23              :     struct SolidSyslogSecurityPolicy* self,
      24              :     const struct SolidSyslogSecurityRecord* record
      25              : );
      26              : 
      27         3235 : struct SolidSyslogSecurityPolicy* SolidSyslogCrc16Policy_Create(void)
      28              : {
      29              :     static struct SolidSyslogSecurityPolicy instance = {
      30              :         CRC16_SIZE,
      31              :         Crc16Policy_Crc16SealRecord,
      32              :         Crc16Policy_Crc16OpenRecord,
      33              :     };
      34         3235 :     return &instance;
      35              : }
      36              : 
      37           21 : void SolidSyslogCrc16Policy_Destroy(void)
      38              : {
      39           21 : }
      40              : 
      41              : /* CRC-16 is a checksum, not an AEAD - it covers the whole content and has no
      42              :  * use for the header/body split, so HeaderLength is ignored. It detects
      43              :  * accidental corruption; it authenticates nothing. */
      44       128860 : static bool Crc16Policy_Crc16SealRecord(
      45              :     struct SolidSyslogSecurityPolicy* self,
      46              :     const struct SolidSyslogSecurityRecord* record
      47              : )
      48              : {
      49              :     (void) self;
      50       128860 :     uint16_t crc = SolidSyslogCrc16_Compute(record->Content, record->ContentLength);
      51       128860 :     record->Trailer[0] = (uint8_t) (crc >> 8U);
      52       128860 :     record->Trailer[1] = (uint8_t) (crc & 0xFFU);
      53       128860 :     return true;
      54              : }
      55              : 
      56       116175 : static enum SolidSyslogSecurityPolicyOpenResult Crc16Policy_Crc16OpenRecord(
      57              :     struct SolidSyslogSecurityPolicy* self,
      58              :     const struct SolidSyslogSecurityRecord* record
      59              : )
      60              : {
      61              :     (void) self;
      62       116175 :     uint16_t crc = SolidSyslogCrc16_Compute(record->Content, record->ContentLength);
      63       116175 :     uint16_t expected = (uint16_t) ((uint16_t) (record->Trailer[0] << 8U) | record->Trailer[1]);
      64       116175 :     return (crc == expected) ? SOLIDSYSLOG_SECURITY_POLICY_OPEN_OPENED : SOLIDSYSLOG_SECURITY_POLICY_OPEN_REJECTED;
      65              : }
        

Generated by: LCOV version 2.0-1