aboutsummaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2021-12-08 20:49:06 +0100
committerPřemysl Eric Janouch <p@janouch.name>2021-12-08 20:49:06 +0100
commitd8171b9ac4edf0fb040b5eee0950a72316058526 (patch)
treed23882b9af4e2c1718077fb2fe0225ba4fe3863a /pdf
parentbcb24af9265133a4d562c4b2ebbf5f54649639af (diff)
downloadpdf-simple-sign-d8171b9ac4edf0fb040b5eee0950a72316058526.tar.gz
pdf-simple-sign-d8171b9ac4edf0fb040b5eee0950a72316058526.tar.xz
pdf-simple-sign-d8171b9ac4edf0fb040b5eee0950a72316058526.zip
Go: improve error handling
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdf.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/pdf/pdf.go b/pdf/pdf.go
index e004429..cf7f9a8 100644
--- a/pdf/pdf.go
+++ b/pdf/pdf.go
@@ -766,8 +766,6 @@ func (u *Updater) Version(root *Object) int {
// Get retrieves an object by its number and generation--may return
// Nil or End with an error.
-//
-// TODO(p): We should fix all uses of this not to eat the error.
func (u *Updater) Get(n, generation uint) (Object, error) {
if n >= u.xrefSize {
return New(Nil), nil
@@ -907,8 +905,8 @@ func NewDate(ts time.Time) Object {
// GetFirstPage retrieves the first page of the given page (sub)tree reference,
// or returns a Nil object if unsuccessful.
func (u *Updater) GetFirstPage(nodeN, nodeGeneration uint) Object {
- obj, _ := u.Get(nodeN, nodeGeneration)
- if obj.Kind != Dict {
+ obj, err := u.Get(nodeN, nodeGeneration)
+ if err != nil || obj.Kind != Dict {
return New(Nil)
}
@@ -1128,7 +1126,10 @@ func Sign(document []byte, key crypto.PrivateKey, certs []*x509.Certificate,
if !ok || rootRef.Kind != Reference {
return nil, errors.New("trailer does not contain a reference to Root")
}
- root, _ := pdf.Get(rootRef.N, rootRef.Generation)
+ root, err := pdf.Get(rootRef.N, rootRef.Generation)
+ if err != nil {
+ return nil, fmt.Errorf("Root dictionary retrieval failed: %s", err)
+ }
if root.Kind != Dict {
return nil, errors.New("invalid Root dictionary reference")
}