NZCP.c  0.0.4
An implementation of the New Zealand COVID Pass specification in C
nzcp.h
1 /* Copyright (C) 1991-2020 Free Software Foundation, Inc.
2  This file is part of the GNU C Library.
3 
4  The GNU C Library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  The GNU C Library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with the GNU C Library; if not, see
16  <https://www.gnu.org/licenses/>. */
17 /* This header is separate from features.h so that the compiler can
18  include it implicitly at the start of every compilation. It must
19  not itself include <features.h> or any other header that includes
20  <features.h> because the implicit include comes before any feature
21  test macros that may be defined in a source file before it first
22  explicitly includes a system header. GCC knows the name of this
23  header in order to preinclude it. */
24 /* glibc's intent is to support the IEC 559 math functionality, real
25  and complex. If the GCC (4.9 and later) predefined macros
26  specifying compiler intent are available, use them to determine
27  whether the overall intent is to support these features; otherwise,
28  presume an older compiler has intent to support these features and
29  define these macros by default. */
30 /* wchar_t uses Unicode 10.0.0. Version 10.0 of the Unicode Standard is
31  synchronized with ISO/IEC 10646:2017, fifth edition, plus
32  the following additions from Amendment 1 to the fifth edition:
33  - 56 emoji characters
34  - 285 hentaigana
35  - 3 additional Zanabazar Square characters */
36 #ifndef __NZCP_H_
37 #define __NZCP_H_
38 #include <stdlib.h>
39 #include <stdint.h>
40 #include <stdbool.h>
41 #define NZCP_VERSION_MAJOR 0
42 #define NZCP_VERSION_MINOR 0
43 #define NZCP_VERSION_PATCH 4
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
55 typedef struct nzcp_verification_result { char* jti; char* iss; int nbf; int exp; char* given_name; char* family_name; char* dob;
105 typedef enum nzcp_error {
106 ERROR_DEF(E_SUCCESS,0,Success)
107 ERROR_DEF(E_EMPTY_URI,1,Empty URI)
108 ERROR_DEF(E_BAD_URI_PREFIX,2,Bad URI prefix)
109 ERROR_DEF(E_BAD_VERSION_IDENTIFIER,3,Bad version identifier)
110 ERROR_DEF(E_CBOR_ERROR,4,CBOR error)
111 ERROR_DEF(E_BAD_TAG,5,Bad tag)
112 ERROR_DEF(E_MALFORMED_CWT,6,Malformed CWT)
113 ERROR_DEF(E_MALFORMED_CWT_HEADER,7,Malformed CWT header)
114 ERROR_DEF(E_WRONG_KID,8,Wrong kid)
115 ERROR_DEF(E_WRONG_ALG,9,Wrong alg)
116 ERROR_DEF(E_MALFORMED_CWT_CLAIMS,10,Malformed CWT claims)
117 ERROR_DEF(E_MALFORMED_CWT_ISSUER,11,Malformed CWT issuer)
118 ERROR_DEF(E_MALFORMED_CWT_NBF,12,Malformed CWT nbf)
119 ERROR_DEF(E_MALFORMED_CWT_EXP,13,Malformed CWT exp)
120 ERROR_DEF(E_MALFORMED_CWT_CTI,14,Malformed CWT cti)
121 ERROR_DEF(E_MALFORMED_CWT_VC,15,Malformed CWT VC)
122 ERROR_DEF(E_MALFORMED_VC_CONTEXT,16,Malformed VC context)
123 ERROR_DEF(E_MALFORMED_VC_VERSION,17,Malformed VC version)
124 ERROR_DEF(E_MALFORMED_VC_TYPE,18,Malformed VC type)
125 ERROR_DEF(E_MALFORMED_CREDENTIAL_SUBJECT,19,Malformed credential subject)
126 ERROR_DEF(E_MALFORMED_GIVEN_NAME,20,Malformed given name)
127 ERROR_DEF(E_MALFORMED_FAMILY_NAME,21,Malformed family name)
128 ERROR_DEF(E_MALFORMED_DOB,22,Malformed DOB)
129 ERROR_DEF(E_WRONG_TRUSTED_ISSUER,23,Wrong trusted issuer)
130 ERROR_DEF(E_BAD_CTI,24,Bad cti)
131 ERROR_DEF(E_BAD_ISS,25,Bad iss)
132 ERROR_DEF(E_BAD_NBF,26,Bad nbf)
133 ERROR_DEF(E_BAD_EXP,27,Bad exp)
134 ERROR_DEF(E_PASS_NOT_ACTIVE,28,Pass not active)
135 ERROR_DEF(E_PASS_EXPIRED,29,Pass expired)
136 ERROR_DEF(E_BAD_VC_CONTEXT,30,Bad VC context)
137 ERROR_DEF(E_BAD_VC_TYPE,31,Bad VC type)
138 ERROR_DEF(E_BAD_VC_VERSION,32,Bad VC version)
139 ERROR_DEF(E_BAD_GIVEN_NAME,33,Bad given name)
140 ERROR_DEF(E_BAD_DOB,34,Bad DOB)
141 ERROR_DEF(E_FAILED_SIGNATURE_VERIFICATION,35,Failed signature verification)
142 ERROR_DEF(E_UNKNOWN,36,Unknown)
143 ERROR_DEF(E_BAD_INTEGRATION,37,Bad integration)
144 } nzcp_error;
153 nzcp_error nzcp_verify_pass_uri(uint8_t* pass_uri, nzcp_verification_result* verification_result, bool is_example);
167 const char* nzcp_error_string(nzcp_error error);
169 #ifdef __cplusplus
170 }
171 #endif
172 #endif
nzcp_verification_result::family_name
char * family_name
Definition: nzcp.h:61
nzcp_error
nzcp_error
The nzcp_error enum used for verfication errors.
Definition: nzcp.h:105
nzcp_verification_result::exp
int exp
Definition: nzcp.h:59
nzcp_verification_result::iss
char * iss
Definition: nzcp.h:57
nzcp_verification_result::given_name
char * given_name
Definition: nzcp.h:60
nzcp_verification_result::jti
char * jti
Definition: nzcp.h:56
nzcp_error_string
const char * nzcp_error_string(nzcp_error error)
Returns the error description for the given error code.
nzcp_verification_result::nbf
int nbf
Definition: nzcp.h:58
nzcp_verification_result
The nzcp_verification_result structure.
Definition: nzcp.h:55
nzcp_verification_result::dob
char * dob
Definition: nzcp.h:62
nzcp_free_verification_result
void nzcp_free_verification_result(nzcp_verification_result *verification_result)
Frees nzcp_verification_result struct. Run this after you're done with the result.
nzcp_verify_pass_uri
nzcp_error nzcp_verify_pass_uri(uint8_t *pass_uri, nzcp_verification_result *verification_result, bool is_example)
Verifies New Zealand COVID Pass URI.