@@ -476,16 +476,6 @@ func (ctx *verifyCtx) verifyCompact(signed []byte) ([]byte, error) {
476
476
return nil , errors .Wrap (err , `failed extract from compact serialization format` )
477
477
}
478
478
479
- verifyBuf := pool .GetBytesBuffer ()
480
- defer pool .ReleaseBytesBuffer (verifyBuf )
481
-
482
- verifyBuf .Write (protected )
483
- verifyBuf .WriteByte ('.' )
484
- if len (payload ) == 0 && ctx .detachedPayload != nil {
485
- payload = ctx .detachedPayload
486
- }
487
- verifyBuf .Write (payload )
488
-
489
479
decodedSignature , err := base64 .Decode (signature )
490
480
if err != nil {
491
481
return nil , errors .Wrap (err , `failed to decode signature` )
@@ -501,6 +491,20 @@ func (ctx *verifyCtx) verifyCompact(signed []byte) ([]byte, error) {
501
491
return nil , errors .Wrap (err , `failed to decode headers` )
502
492
}
503
493
494
+ verifyBuf := pool .GetBytesBuffer ()
495
+ defer pool .ReleaseBytesBuffer (verifyBuf )
496
+
497
+ verifyBuf .Write (protected )
498
+ verifyBuf .WriteByte ('.' )
499
+ if len (payload ) == 0 && ctx .detachedPayload != nil {
500
+ if getB64Value (hdr ) {
501
+ payload = base64 .Encode (ctx .detachedPayload )
502
+ } else {
503
+ payload = ctx .detachedPayload
504
+ }
505
+ }
506
+ verifyBuf .Write (payload )
507
+
504
508
if ! ctx .useJKU {
505
509
if hdr .KeyID () != "" {
506
510
if jwkKey , ok := ctx .key .(jwk.Key ); ok {
0 commit comments