@@ -211,14 +211,25 @@ def countersign(
211211 payload = detached_payload
212212
213213 if abbreviated :
214- to_be_signed = ["CounterSignature0V2" , self ._protected , aad , payload ]
214+ to_be_signed = [
215+ "CounterSignature0V2" if len (self ._other_fields ) > 0 else "CounterSignature0" ,
216+ self ._protected ,
217+ aad ,
218+ payload ,
219+ ]
215220 for other_field in self ._other_fields :
216221 to_be_signed .append (other_field )
217222 signer .sign (self ._dumps (to_be_signed ))
218223 self ._unprotected [12 ] = signer .signature
219224 return self
220225
221- to_be_signed = ["CounterSignatureV2" , self ._protected , signer .protected , aad , payload ]
226+ to_be_signed = [
227+ "CounterSignatureV2" if len (self ._other_fields ) > 0 else "CounterSignature" ,
228+ self ._protected ,
229+ signer .protected ,
230+ aad ,
231+ payload ,
232+ ]
222233 for other_field in self ._other_fields :
223234 to_be_signed .append (other_field )
224235 signer .sign (self ._dumps (to_be_signed ))
@@ -261,7 +272,12 @@ def counterverify(
261272 err : Exception = ValueError ("Countersignature not found." )
262273 acs = self ._unprotected .get (12 , None )
263274 if acs :
264- to_be_signed = ["CounterSignature0V2" , self ._protected , aad , payload ]
275+ to_be_signed = [
276+ "CounterSignature0V2" if len (self ._other_fields ) > 0 else "CounterSignature0" ,
277+ self ._protected ,
278+ aad ,
279+ payload ,
280+ ]
265281 for other_field in self ._other_fields :
266282 to_be_signed .append (other_field )
267283 try :
@@ -273,7 +289,13 @@ def counterverify(
273289 cs = self ._unprotected .get (11 , None )
274290 if not cs :
275291 raise err
276- to_be_signed = ["CounterSignatureV2" , self ._protected , b"" , aad , payload ]
292+ to_be_signed = [
293+ "CounterSignatureV2" if len (self ._other_fields ) > 0 else "CounterSignature" ,
294+ self ._protected ,
295+ b"" ,
296+ aad ,
297+ payload ,
298+ ]
277299 for other_field in self ._other_fields :
278300 to_be_signed .append (other_field )
279301 if isinstance (cs [0 ], bytes ):
0 commit comments