This commit is contained in:
Mrx
2026-06-01 13:15:37 +08:00
parent 21217f4da1
commit 5d2d49f0e8
16 changed files with 1536 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package pdfvalidate
import (
"bytes"
"errors"
"fmt"
)
// MaxAuthorizePDFBytes 授权类 PDF 大小上限(与汇博等对接约定一致)
const MaxAuthorizePDFBytes = 500 * 1024
var pdfMagic = []byte("%PDF-")
// ValidateDecodedPDFBinary 仅校验已通过 Base64 解码得到的原始字节非空、长度、PDF 魔数头部。
func ValidateDecodedPDFBinary(raw []byte) error {
if len(raw) == 0 {
return errors.New("授权书文件不能为空")
}
if len(raw) > MaxAuthorizePDFBytes {
return fmt.Errorf("授权书文件不能超过500KB当前大小: %d字节", len(raw))
}
if len(raw) < len(pdfMagic) || !bytes.Equal(raw[:len(pdfMagic)], pdfMagic) {
return errors.New("授权书文件必须为PDF格式")
}
return nil
}