/ include / constantine / core / serialization.h
serialization.h
 1  /** Constantine
 2   *  Copyright (c) 2018-2019    Status Research & Development GmbH
 3   *  Copyright (c) 2020-Present Mamy André-Ratsimbazafy
 4   *  Licensed and distributed under either of
 5   *    * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
 6   *    * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
 7   *  at your option. This file may not be copied, modified, or distributed except according to those terms.
 8   */
 9  #ifndef __CTT_H_SERIALIZATION__
10  #define __CTT_H_SERIALIZATION__
11  
12  #include "constantine/core/datatypes.h"
13  
14  #ifdef __cplusplus
15  extern "C" {
16  #endif
17  
18  typedef enum __attribute__((__packed__)) {
19      cttCodecScalar_Success,
20      cttCodecScalar_Zero,
21      cttCodecScalar_ScalarLargerThanCurveOrder,
22  } ctt_codec_scalar_status;
23  
24  static const char* ctt_codec_scalar_status_to_string(ctt_codec_scalar_status status) {
25    static const char* const statuses[] = {
26      "cttCodecScalar_Success",
27      "cttCodecScalar_Zero",
28      "cttCodecScalar_ScalarLargerThanCurveOrder",
29    };
30    size_t length = sizeof statuses / sizeof *statuses;
31    if (0 <= status && status < length) {
32      return statuses[status];
33    }
34    return "cttCodecScalar_InvalidStatusCode";
35  }
36  
37  typedef enum __attribute__((__packed__)) {
38      cttCodecEcc_Success,
39      cttCodecEcc_InvalidEncoding,
40      cttCodecEcc_CoordinateGreaterThanOrEqualModulus,
41      cttCodecEcc_PointNotOnCurve,
42      cttCodecEcc_PointNotInSubgroup,
43      cttCodecEcc_PointAtInfinity,
44  } ctt_codec_ecc_status;
45  
46  static const char* ctt_codec_ecc_status_to_string(ctt_codec_ecc_status status) {
47    static const char* const statuses[] = {
48      "cttCodecEcc_Success",
49      "cttCodecEcc_InvalidEncoding",
50      "cttCodecEcc_CoordinateGreaterThanOrEqualModulus",
51      "cttCodecEcc_PointNotOnCurve",
52      "cttCodecEcc_PointNotInSubgroup",
53      "cttCodecEcc_PointAtInfinity",
54    };
55    size_t length = sizeof statuses / sizeof *statuses;
56    if (0 <= status && status < length) {
57      return statuses[status];
58    }
59    return "cttCodecEcc_InvalidStatusCode";
60  }
61  
62  #ifdef __cplusplus
63  }
64  #endif
65  
66  #endif