Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vanbroup committed Nov 14, 2024
1 parent 7946d52 commit bacc810
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 108 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/digitorus/pdfsign

go 1.17
go 1.22

require (
github.com/digitorus/pdf v0.1.2
Expand Down
62 changes: 0 additions & 62 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,9 @@ github.com/digitorus/pkcs7 v0.0.0-20230818184609-3a137a874352 h1:ge14PCmCvPjpMQM
github.com/digitorus/pkcs7 v0.0.0-20230818184609-3a137a874352/go.mod h1:SKVExuS+vpu2l9IoOc0RwqE7NYnb0JlcFHFnEJkVDzc=
github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7 h1:lxmTCgmHE1GUYL7P0MlNa00M67axePTq+9nBSGddR8I=
github.com/digitorus/timestamp v0.0.0-20231217203849-220c5c2851b7/go.mod h1:GvWntX9qiTlOud0WkQ6ewFm0LPy5JUR1Xo0Ngbd1w6Y=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattetti/filebuffer v1.0.1 h1:gG7pyfnSIZCxdoKq+cPa8T0hhYtD9NxCdI4D7PTjRLM=
github.com/mattetti/filebuffer v1.0.1/go.mod h1:YdMURNDOttIiruleeVr6f56OrMc+MydEnTcXwtkxNVs=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6 changes: 3 additions & 3 deletions revocation/revocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *InfoArchival) AddOCSP(b []byte) error {
// true if the certificate is marked as revoked.
//
// TODO: We should report if there is no CRL or OCSP response embedded for this certificate
// TODO: Information about the revocation (time, reason, etc) must be extractable
// TODO: Information about the revocation (time, reason, etc) must be extractable.
func (r *InfoArchival) IsRevoked(c *x509.Certificate) bool {
// check the crl and ocsp to see if this certificate is revoked
return true
Expand All @@ -45,10 +45,10 @@ func (r *InfoArchival) IsRevoked(c *x509.Certificate) bool {
type CRL []asn1.RawValue

// OCSP contains the raw bytes of an OCSP response and can be parsed with
// x/crypto/ocsp.ParseResponse
// x/crypto/ocsp.ParseResponse.
type OCSP []asn1.RawValue

// ANS.1 Object OtherRevInfo
// ANS.1 Object OtherRevInfo.
type Other struct {
Type asn1.ObjectIdentifier
Value []byte
Expand Down
2 changes: 0 additions & 2 deletions sign/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"time"

"github.com/digitorus/pdf"

"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)

func findFirstPage(parent pdf.Value) (pdf.Value, error) {
value_type := parent.Key("Type").String()
if value_type == "/Pages" {

for i := 0; i < parent.Key("Kids").Len(); i++ {
recurse_parent, recurse_err := findFirstPage(parent.Key("Kids").Index(i))
if recurse_err == nil {
Expand Down
3 changes: 2 additions & 1 deletion sign/pdfcatalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var testFiles = []struct {
expectedCatalogs: map[CertType]string{
CertificationSignature: "17 0 obj\n<< /Type /Catalog /Pages 9 0 R /Names 6 0 R /AcroForm << /Fields [16 0 R] /NeedAppearances false /SigFlags 3 >> >>\nendobj\n",
UsageRightsSignature: "17 0 obj\n<< /Type /Catalog /Pages 9 0 R /Names 6 0 R /AcroForm << /Fields [16 0 R] /NeedAppearances false /SigFlags 1 >> >>\nendobj\n",
ApprovalSignature: "17 0 obj\n<< /Type /Catalog /Pages 9 0 R /Names 6 0 R /AcroForm << /Fields [16 0 R] /NeedAppearances false /SigFlags 3 >> >>\nendobj\n"},
ApprovalSignature: "17 0 obj\n<< /Type /Catalog /Pages 9 0 R /Names 6 0 R /AcroForm << /Fields [16 0 R] /NeedAppearances false /SigFlags 3 >> >>\nendobj\n",
},
},
}

Expand Down
2 changes: 0 additions & 2 deletions sign/pdfsignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ func (context *SignContext) createSignaturePlaceholder() (dssd string, byte_rang
signature_buffer.Write(bytes.Repeat([]byte("0"), int(context.SignatureMaxLength)))
signature_buffer.WriteString(">\n")

//if context.SignData.Signature.CertType != ApprovalSignature {
switch context.SignData.Signature.CertType {
case CertificationSignature, UsageRightsSignature:
signature_buffer.WriteString(" /Reference [\n") // start array of signature reference dictionaries
signature_buffer.WriteString(" << /Type /SigRef\n")
}

switch context.SignData.Signature.CertType {

// Certification signature (also known as an author signature)
case CertificationSignature:
signature_buffer.WriteString(" /TransformMethod /DocMDP\n")
Expand Down
6 changes: 3 additions & 3 deletions sign/pdfvisualsignature.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/digitorus/pdf"
)

// Define annotation flag constants
// Define annotation flag constants.
const (
AnnotationFlagInvisible = 1 << 0
AnnotationFlagHidden = 1 << 1
Expand Down Expand Up @@ -78,7 +78,7 @@ func (context *SignContext) createVisualSignature(visible bool, pageNumber int,
}

// Define the annotation flags for the signature field (132)
//annotationFlags := AnnotationFlagPrint | AnnotationFlagNoZoom | AnnotationFlagNoRotate | AnnotationFlagReadOnly | AnnotationFlagLockedContents
// annotationFlags := AnnotationFlagPrint | AnnotationFlagNoZoom | AnnotationFlagNoRotate | AnnotationFlagReadOnly | AnnotationFlagLockedContents
visual_signature += fmt.Sprintf(" /F %d", 132)
// Define the field type as a signature.
visual_signature += " /FT /Sig"
Expand All @@ -104,7 +104,7 @@ func (context *SignContext) createVisualSignature(visible bool, pageNumber int,
return visual_signature, nil
}

// Helper function to find a page by its number
// Helper function to find a page by its number.
func findPageByNumber(pages pdf.Value, pageNumber int) (pdf.Value, error) {
if pages.Key("Type").Name() == "Pages" {
kids := pages.Key("Kids")
Expand Down
2 changes: 2 additions & 0 deletions sign/pdfxref.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (context *SignContext) writeXref() error {
}

// writeXrefTable writes the cross-reference table to the output buffer.
//
//nolint:unused
func (context *SignContext) writeXrefTable() error {
// Seek to the start of the xref table
if _, err := context.InputFile.Seek(context.PDFReader.XrefInformation.StartPos, io.SeekStart); err != nil {
Expand Down
1 change: 0 additions & 1 deletion sign/revocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/digitorus/pdfsign/revocation"

"golang.org/x/crypto/ocsp"
)

Expand Down
4 changes: 1 addition & 3 deletions sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/digitorus/pdf"
"github.com/digitorus/pdfsign/revocation"
"github.com/digitorus/pkcs7"

"github.com/mattetti/filebuffer"
)

Expand Down Expand Up @@ -202,7 +201,6 @@ func (context *SignContext) SignPDF() error {

// If not a timestamp signature
if context.SignData.Signature.CertType != TimeStampSignature {

switch context.SignData.Certificate.SignatureAlgorithm.String() {
case "SHA1-RSA":
case "ECDSA-SHA1":
Expand Down Expand Up @@ -268,7 +266,7 @@ func (context *SignContext) SignPDF() error {
}

// Create visual signature (visible or invisible based on CertType)
//visible := context.SignData.Signature.CertType == CertificationSignature
// visible := context.SignData.Signature.CertType == CertificationSignature
// Example usage: passing page number and default rect values
visual_signature, err := context.createVisualSignature(false, 1, [4]float64{0, 0, 0, 0})
if err != nil {
Expand Down
10 changes: 1 addition & 9 deletions sign/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/digitorus/pdf"
"github.com/digitorus/pdfsign/revocation"
"github.com/digitorus/pdfsign/verify"

"github.com/mattetti/filebuffer"
)

Expand Down Expand Up @@ -124,7 +123,7 @@ func TestReaderCanReadPDF(t *testing.T) {

func TestSignPDF(t *testing.T) {
_ = os.RemoveAll("../testfiles/failed/")
_ = os.MkdirAll("../testfiles/failed/", 0777)
_ = os.MkdirAll("../testfiles/failed/", 0o777)

files, err := os.ReadDir("../testfiles/")
if err != nil {
Expand Down Expand Up @@ -169,7 +168,6 @@ func TestSignPDF(t *testing.T) {
RevocationData: revocation.InfoArchival{},
RevocationFunction: DefaultEmbedRevocationStatusFunction,
})

if err != nil {
st.Fatalf("%s: %s", f.Name(), err.Error())
}
Expand Down Expand Up @@ -209,7 +207,6 @@ func TestSignPDFFileUTF8(t *testing.T) {
Signer: pkey,
Certificate: cert,
})

if err != nil {
t.Fatalf("%s: %s", originalFileName, err.Error())
}
Expand Down Expand Up @@ -269,7 +266,6 @@ func BenchmarkSignPDF(b *testing.B) {
CertificateChains: certificateChains,
RevocationData: revocation.InfoArchival{},
})

if err != nil {
b.Fatalf("%s: %s", "testfile20.pdf", err.Error())
}
Expand Down Expand Up @@ -305,7 +301,6 @@ func TestSignPDFWithTwoApproval(t *testing.T) {
Signer: pkey,
Certificate: cert,
})

if err != nil {
t.Fatalf("%s: %s", "testfile20.pdf", err.Error())
}
Expand Down Expand Up @@ -343,7 +338,6 @@ func TestSignPDFWithCertificationApprovalAndTimeStamp(t *testing.T) {
Signer: pkey,
Certificate: cert,
})

if err != nil {
t.Fatalf("%s: %s", filepath.Base(tbsFile), err.Error())
}
Expand Down Expand Up @@ -376,7 +370,6 @@ func TestSignPDFWithCertificationApprovalAndTimeStamp(t *testing.T) {
Signer: pkey,
Certificate: cert,
})

if err != nil {
t.Fatalf("%s: %s", filepath.Base(tbsFile), err.Error())
}
Expand Down Expand Up @@ -426,7 +419,6 @@ func TestTimestampPDFFile(t *testing.T) {
URL: "http://timestamp.entrust.net/TSS/RFC3161sha2TS",
},
})

if err != nil {
t.Fatalf("%s: %s", "testfile20.pdf", err.Error())
}
Expand Down
Loading

0 comments on commit bacc810

Please sign in to comment.