NZCP.c
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 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
52 typedef struct nzcp_verification_result { char* jti; char* iss; int nbf; int exp; char* given_name; char* family_name; char* dob;
102 typedef enum nzcp_error {
103 ERROR_DEF(E_SUCCESS,0,Success)
104 ERROR_DEF(E_EMPTY_URI,1,Empty URI)
105 ERROR_DEF(E_BAD_URI_PREFIX,2,Bad URI prefix)
106 ERROR_DEF(E_BAD_VERSION_IDENTIFIER,3,Bad version identifier)
107 ERROR_DEF(E_CBOR_ERROR,4,CBOR error)
108 ERROR_DEF(E_BAD_TAG,5,Bad tag)
109 ERROR_DEF(E_MALFORMED_CWT,6,Malformed CWT)
110 ERROR_DEF(E_MALFORMED_CWT_HEADER,7,Malformed CWT header)
111 ERROR_DEF(E_WRONG_KID,8,Wrong kid)
112 ERROR_DEF(E_WRONG_ALG,9,Wrong alg)
113 ERROR_DEF(E_MALFORMED_CWT_CLAIMS,10,Malformed CWT claims)
114 ERROR_DEF(E_MALFORMED_CWT_ISSUER,11,Malformed CWT issuer)
115 ERROR_DEF(E_MALFORMED_CWT_NBF,12,Malformed CWT nbf)
116 ERROR_DEF(E_MALFORMED_CWT_EXP,13,Malformed CWT exp)
117 ERROR_DEF(E_MALFORMED_CWT_CTI,14,Malformed CWT cti)
118 ERROR_DEF(E_MALFORMED_CWT_VC,15,Malformed CWT VC)
119 ERROR_DEF(E_MALFORMED_VC_CONTEXT,16,Malformed VC context)
120 ERROR_DEF(E_MALFORMED_VC_VERSION,17,Malformed VC version)
121 ERROR_DEF(E_MALFORMED_VC_TYPE,18,Malformed VC type)
122 ERROR_DEF(E_MALFORMED_CREDENTIAL_SUBJECT,19,Malformed credential subject)
123 ERROR_DEF(E_MALFORMED_GIVEN_NAME,20,Malformed given name)
124 ERROR_DEF(E_MALFORMED_FAMILY_NAME,21,Malformed family name)
125 ERROR_DEF(E_MALFORMED_DOB,22,Malformed DOB)
126 ERROR_DEF(E_WRONG_TRUSTED_ISSUER,23,Wrong trusted issuer)
127 ERROR_DEF(E_BAD_CTI,24,Bad cti)
128 ERROR_DEF(E_BAD_ISS,25,Bad iss)
129 ERROR_DEF(E_BAD_NBF,26,Bad nbf)
130 ERROR_DEF(E_BAD_EXP,27,Bad exp)
131 ERROR_DEF(E_PASS_NOT_ACTIVE,28,Pass not active)
132 ERROR_DEF(E_PASS_EXPIRED,29,Pass expired)
133 ERROR_DEF(E_BAD_VC_CONTEXT,30,Bad VC context)
134 ERROR_DEF(E_BAD_VC_TYPE,31,Bad VC type)
135 ERROR_DEF(E_BAD_VC_VERSION,32,Bad VC version)
136 ERROR_DEF(E_BAD_GIVEN_NAME,33,Bad given name)
137 ERROR_DEF(E_BAD_DOB,34,Bad DOB)
138 ERROR_DEF(E_FAILED_SIGNATURE_VERIFICATION,35,Failed signature verification)
139 ERROR_DEF(E_UNKNOWN,36,Unknown)
140 ERROR_DEF(E_BAD_INTEGRATION,37,Bad integration)
141 } nzcp_error;
150 nzcp_error nzcp_verify_pass_uri(uint8_t* pass_uri, nzcp_verification_result* verification_result, bool is_example);
164 const char* nzcp_error_string(nzcp_error error);
166 #ifdef __cplusplus
167 }
168 #endif
169 #endif
nzcp_verification_result::family_name
char * family_name
Definition: nzcp.h:58
nzcp_error
nzcp_error
The nzcp_error enum used for verfication errors.
Definition: nzcp.h:102
nzcp_verification_result::exp
int exp
Definition: nzcp.h:56
nzcp_verification_result::iss
char * iss
Definition: nzcp.h:54
nzcp_verification_result::given_name
char * given_name
Definition: nzcp.h:57
nzcp_verification_result::jti
char * jti
Definition: nzcp.h:53
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:55
nzcp_verification_result
The nzcp_verification_result structure.
Definition: nzcp.h:52
nzcp_verification_result::dob
char * dob
Definition: nzcp.h:59
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.