@@ -23,4 +23,30 @@ describe('preAuthEncoding', () => {
2323 const pae = preAuthEncoding ( payloadType , payload ) ;
2424 expect ( pae ) . toEqual ( Buffer . from ( 'DSSEv1 10 text/plain 13 Hello, World!' ) ) ;
2525 } ) ;
26+
27+ it ( 'should use utf-8 byte length for non-ASCII payloadType' , ( ) => {
28+ // U+00E9 (é) is 2 bytes in UTF-8
29+ const nonAsciiType = 'application/typ\u00e9' ;
30+ const pae = preAuthEncoding ( nonAsciiType , payload ) ;
31+
32+ const typeBytes = Buffer . from ( nonAsciiType , 'utf-8' ) ;
33+ expect ( typeBytes . length ) . toBe ( 17 ) ; // 16 ASCII chars + 2 byte é = 17
34+
35+ const expected = Buffer . concat ( [
36+ Buffer . from ( `DSSEv1 ${ typeBytes . length } ` , 'ascii' ) ,
37+ typeBytes ,
38+ Buffer . from ( ` ${ payload . length } ` , 'ascii' ) ,
39+ payload ,
40+ ] ) ;
41+ expect ( pae ) . toEqual ( expected ) ;
42+ } ) ;
43+
44+ it ( 'should produce distinct PAE for Unicode payloadType variants' , ( ) => {
45+ // U+0174 has same low byte as 't' (0x74) — the old ascii
46+ // encoding would have mapped both to the same byte
47+ const original = preAuthEncoding ( 'text/plain' , payload ) ;
48+ const mutant = preAuthEncoding ( '\u0174ext/plain' , payload ) ;
49+
50+ expect ( original ) . not . toEqual ( mutant ) ;
51+ } ) ;
2652} ) ;
0 commit comments