diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-09-04 15:34:33 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-09-04 16:05:14 +0200 |
commit | 1224d9be47e5235f39556d9118c9893ee6e68a4c (patch) | |
tree | 4eb042d56f8baa5f036e9c327226523bd9719bb5 /pdf | |
parent | 486cafa6b447d7af296411f7c50d4c078f3eac34 (diff) | |
download | pdf-simple-sign-1224d9be47e5235f39556d9118c9893ee6e68a4c.tar.gz pdf-simple-sign-1224d9be47e5235f39556d9118c9893ee6e68a4c.tar.xz pdf-simple-sign-1224d9be47e5235f39556d9118c9893ee6e68a4c.zip |
Return errors rather than mangle documents
Diffstat (limited to 'pdf')
-rw-r--r-- | pdf/pdf.go | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,5 +1,5 @@ // -// Copyright (c) 2018, Přemysl Eric Janouch <p@janouch.name> +// Copyright (c) 2018 - 2020, Přemysl Eric Janouch <p@janouch.name> // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted. @@ -32,6 +32,7 @@ import ( "crypto/ecdsa" "crypto/rsa" "crypto/x509" + "go.mozilla.org/pkcs7" "golang.org/x/crypto/pkcs12" ) @@ -1166,9 +1167,13 @@ func Sign(document []byte, return nil, errors.New("invalid or unsupported page tree") } - // XXX: Assuming this won't be an indirectly referenced array. annots := page.Dict["Annots"] if annots.Kind != Array { + // TODO(p): Indirectly referenced arrays might not be + // that hard to support. + if annots.Kind != End { + return nil, errors.New("unexpected Annots") + } annots = NewArray(nil) } annots.Array = append(annots.Array, NewReference(sigfieldN, 0)) @@ -1179,7 +1184,11 @@ func Sign(document []byte, }) // 8.6.1 Interactive Form Dictionary - // XXX: Assuming there are no forms already, overwriting everything. + if _, ok := root.Dict["AcroForm"]; ok { + return nil, errors.New("the document already contains forms, " + + "they would be overwritten") + } + root.Dict["AcroForm"] = NewDict(map[string]Object{ "Fields": NewArray([]Object{NewReference(sigfieldN, 0)}), "SigFlags": NewNumeric(3 /* SignaturesExist | AppendOnly */), |