diff --git a/sign/pdfsignature.go b/sign/pdfsignature.go index c6b2401..0f19ff4 100644 --- a/sign/pdfsignature.go +++ b/sign/pdfsignature.go @@ -81,7 +81,7 @@ func (context *SignContext) createSignature() ([]byte, error) { file_content = file_content[:len(file_content)-1] // Collect the parts to sign. - sign_content := make([]byte, context.ByteRangeValues[1]+context.ByteRangeValues[3]) + sign_content := make([]byte, 0) sign_content = append(sign_content, file_content[context.ByteRangeValues[0]:(context.ByteRangeValues[0]+context.ByteRangeValues[1])]...) sign_content = append(sign_content, file_content[context.ByteRangeValues[2]:(context.ByteRangeValues[2]+context.ByteRangeValues[3])]...) diff --git a/verify/verify.go b/verify/verify.go index 4635a0e..5533e17 100644 --- a/verify/verify.go +++ b/verify/verify.go @@ -123,10 +123,12 @@ func Verify(file *os.File) (apiResp *Response, err error) { // Read the byte range from the raw file and add it to the contents. // This content will be hashed with the corresponding algorithm to // verify the signature. + content, err := ioutil.ReadAll(io.NewSectionReader(file, v.Key("ByteRange").Index(i-1).Int64(), v.Key("ByteRange").Index(i).Int64())) if err != nil { apiResp.Error = fmt.Sprintln("Failed to get ByteRange:", i, err) } + p7.Content = append(p7.Content, content...) } @@ -178,7 +180,7 @@ func Verify(file *os.File) (apiResp *Response, err error) { signer.ValidSignature = true signer.TrustedIssuer = false } - //apiResp.Error = fmt.Sprintln("Failed to verify signature:", err) + apiResp.Error = fmt.Sprintln("Failed to verify signature:", err) } else { signer.ValidSignature = true signer.TrustedIssuer = true