11from jwcrypto import jwk , jwt
2- from cwt import COSE , COSEKey
2+ from cwt import COSE , COSEKey , CWTClaims
33from status_list import StatusList
44from datetime import datetime
55from typing import Dict
6+ from cbor2 import dumps
67import json
78
89DEFAULT_ALG = "ES256"
@@ -119,11 +120,11 @@ def buildCWT(
119120 claims = optional_claims
120121 else :
121122 claims = {}
122- claims [2 ] = self .subject
123- claims [1 ] = self .issuer
124- claims [6 ] = int (iat .timestamp ())
123+ claims [CWTClaims . SUB ] = self .subject
124+ claims [CWTClaims . ISS ] = self .issuer
125+ claims [CWTClaims . IAT ] = int (iat .timestamp ())
125126 if exp is not None :
126- claims [4 ] = int (exp .timestamp ())
127+ claims [CWTClaims . EXP ] = int (exp .timestamp ())
127128 claims [65534 ] = self .list .encodeAsCBOR () # no CWT claim key assigned yet by IANA
128129
129130 # build header
@@ -138,15 +139,16 @@ def buildCWT(
138139 unprotected_header = {}
139140
140141 if self ._key .key_id :
141- unprotected_header ["kid" ] = self ._key .key_id
142- protected_header ["alg" ] = self ._alg
142+ unprotected_header [4 ] = self ._key .key_id
143+ protected_header [1 ] = self ._alg
144+ protected_header [16 ] = STATUS_LIST_TYP_CWT
143145
144146 key = COSEKey .from_jwk (self ._key )
145147
146148 # The sender side:
147149 sender = COSE .new ()
148150 encoded = sender .encode (
149- claims ,
151+ dumps ( claims ) ,
150152 key ,
151153 protected = protected_header ,
152154 unprotected = unprotected_header
0 commit comments