NZCP.c  0.0.4
An implementation of the New Zealand COVID Pass specification in C
Typedefs | Enumerations | Functions
Verify a New Zealand COVID Pass

A group of functions for verifying New Zealand COVID Passes. More...

Typedefs

typedef enum nzcp_error nzcp_error
 The nzcp_error enum used for verfication errors. More...
 

Enumerations

enum  nzcp_error {
  NZCP_E_SUCCESS = 0, NZCP_E_EMPTY_URI = 1, NZCP_E_BAD_URI_PREFIX = 2, NZCP_E_BAD_VERSION_IDENTIFIER = 3,
  NZCP_E_CBOR_ERROR = 4, NZCP_E_BAD_TAG = 5, NZCP_E_MALFORMED_CWT = 6, NZCP_E_MALFORMED_CWT_HEADER = 7,
  NZCP_E_WRONG_KID = 8, NZCP_E_WRONG_ALG = 9, NZCP_E_MALFORMED_CWT_CLAIMS = 10, NZCP_E_MALFORMED_CWT_ISSUER = 11,
  NZCP_E_MALFORMED_CWT_NBF = 12, NZCP_E_MALFORMED_CWT_EXP = 13, NZCP_E_MALFORMED_CWT_CTI = 14, NZCP_E_MALFORMED_CWT_VC = 15,
  NZCP_E_MALFORMED_VC_CONTEXT = 16, NZCP_E_MALFORMED_VC_VERSION = 17, NZCP_E_MALFORMED_VC_TYPE = 18, NZCP_E_MALFORMED_CREDENTIAL_SUBJECT = 19,
  NZCP_E_MALFORMED_GIVEN_NAME = 20, NZCP_E_MALFORMED_FAMILY_NAME = 21, NZCP_E_MALFORMED_DOB = 22, NZCP_E_WRONG_TRUSTED_ISSUER = 23,
  NZCP_E_BAD_CTI = 24, NZCP_E_BAD_ISS = 25, NZCP_E_BAD_NBF = 26, NZCP_E_BAD_EXP = 27,
  NZCP_E_PASS_NOT_ACTIVE = 28, NZCP_E_PASS_EXPIRED = 29, NZCP_E_BAD_VC_CONTEXT = 30, NZCP_E_BAD_VC_TYPE = 31,
  NZCP_E_BAD_VC_VERSION = 32, NZCP_E_BAD_GIVEN_NAME = 33, NZCP_E_BAD_DOB = 34, NZCP_E_FAILED_SIGNATURE_VERIFICATION = 35,
  NZCP_E_UNKNOWN = 36, NZCP_E_BAD_INTEGRATION = 37
}
 The nzcp_error enum used for verfication errors. More...
 

Functions

nzcp_error nzcp_verify_pass_uri (uint8_t *pass_uri, nzcp_verification_result *verification_result, bool is_example)
 Verifies New Zealand COVID Pass URI. More...
 
void nzcp_free_verification_result (nzcp_verification_result *verification_result)
 Frees nzcp_verification_result struct. Run this after you're done with the result. More...
 
const char * nzcp_error_string (nzcp_error error)
 Returns the error description for the given error code. More...
 

Detailed Description

A group of functions for verifying New Zealand COVID Passes.

Example Usage

#include <nzcp.h>
// initiate verification result on stack
nzcp_verification_result verification_result;
// verify pass
// last argument determines if it's example or live MOH DID document
nzcp_error error = nzcp_verify_pass_uri(PASS_URI, &verification_result, 1);
// check for error
if (error == NZCP_E_SUCCESS) {
printf("jti: %s\n", verification_result.jti);
printf("iss: %s\n", verification_result.iss);
printf("nbf: %d\n", verification_result.nbf);
printf("exp: %d\n", verification_result.exp);
printf("given_name: %s\n", verification_result.given_name);
printf("family_name: %s\n", verification_result.family_name);
printf("dob: %s\n", verification_result.dob);
}
else {
printf("error: %s\n", nzcp_error_string(error));
}
// free memory of verification result properties
nzcp_free_verification_result(&verification_result);

Typedef Documentation

◆ nzcp_error

typedef enum nzcp_error nzcp_error

The nzcp_error enum used for verfication errors.

This is the type used to represent NZCP errors in the nzcp_verify_pass_uri function.

Enumeration Type Documentation

◆ nzcp_error

enum nzcp_error

The nzcp_error enum used for verfication errors.

This is the type used to represent NZCP errors in the nzcp_verify_pass_uri function.

Enumerator
NZCP_E_SUCCESS 

Success

NZCP_E_EMPTY_URI 

Empty URI

NZCP_E_BAD_URI_PREFIX 

Bad URI prefix

NZCP_E_BAD_VERSION_IDENTIFIER 

Bad version identifier

NZCP_E_CBOR_ERROR 

CBOR error

NZCP_E_BAD_TAG 

Bad tag

NZCP_E_MALFORMED_CWT 

Malformed CWT

NZCP_E_MALFORMED_CWT_HEADER 

Malformed CWT header

NZCP_E_WRONG_KID 

Wrong kid

NZCP_E_WRONG_ALG 

Wrong alg

NZCP_E_MALFORMED_CWT_CLAIMS 

Malformed CWT claims

NZCP_E_MALFORMED_CWT_ISSUER 

Malformed CWT issuer

NZCP_E_MALFORMED_CWT_NBF 

Malformed CWT nbf

NZCP_E_MALFORMED_CWT_EXP 

Malformed CWT exp

NZCP_E_MALFORMED_CWT_CTI 

Malformed CWT cti

NZCP_E_MALFORMED_CWT_VC 

Malformed CWT VC

NZCP_E_MALFORMED_VC_CONTEXT 

Malformed VC context

NZCP_E_MALFORMED_VC_VERSION 

Malformed VC version

NZCP_E_MALFORMED_VC_TYPE 

Malformed VC type

NZCP_E_MALFORMED_CREDENTIAL_SUBJECT 

Malformed credential subject

NZCP_E_MALFORMED_GIVEN_NAME 

Malformed given name

NZCP_E_MALFORMED_FAMILY_NAME 

Malformed family name

NZCP_E_MALFORMED_DOB 

Malformed DOB

NZCP_E_WRONG_TRUSTED_ISSUER 

Wrong trusted issuer

NZCP_E_BAD_CTI 

Bad cti

NZCP_E_BAD_ISS 

Bad iss

NZCP_E_BAD_NBF 

Bad nbf

NZCP_E_BAD_EXP 

Bad exp

NZCP_E_PASS_NOT_ACTIVE 

Pass not active

NZCP_E_PASS_EXPIRED 

Pass expired

NZCP_E_BAD_VC_CONTEXT 

Bad VC context

NZCP_E_BAD_VC_TYPE 

Bad VC type

NZCP_E_BAD_VC_VERSION 

Bad VC version

NZCP_E_BAD_GIVEN_NAME 

Bad given name

NZCP_E_BAD_DOB 

Bad DOB

NZCP_E_FAILED_SIGNATURE_VERIFICATION 

Failed signature verification

NZCP_E_UNKNOWN 

Unknown

NZCP_E_BAD_INTEGRATION 

Bad integration

Function Documentation

◆ nzcp_error_string()

const char* nzcp_error_string ( nzcp_error  error)

Returns the error description for the given error code.

Parameters
[in]errorerror code
Returns
const char*

◆ 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.

Parameters
[in]verification_resultPointer to verification result struct

◆ 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.

Parameters
[in]pass_uriNull-terminted buffer with the URI
[out]verification_resultPointer to verification result struct
[in]is_exampleWhether the pass_uri uses example or live MOH DID document
Returns
nzcp_error
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_E_SUCCESS
@ NZCP_E_SUCCESS
Definition: nzcp.h:106
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.