mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-02 22:17:06 +08:00
Merge pull request #350 from adrg/v3-a5i-pdf-sign
Digital signatures refactoring
This commit is contained in:
commit
473eb5f031
@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is subject to the terms and conditions defined in
|
|
||||||
* file 'LICENSE.md', which is part of this source code package.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import "github.com/unidoc/unidoc/pdf/core"
|
|
||||||
|
|
||||||
// PdfSignatureAppearance defines a signature with a specified form field and
|
|
||||||
// annotation widget for appearance styling.
|
|
||||||
type PdfSignatureAppearance struct {
|
|
||||||
*PdfField
|
|
||||||
*PdfAnnotationWidget
|
|
||||||
|
|
||||||
Signature *PdfSignature
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPdfSignatureAppearance returns an initialized signature field appearance.
|
|
||||||
func NewPdfSignatureAppearance() *PdfSignatureAppearance {
|
|
||||||
app := &PdfSignatureAppearance{}
|
|
||||||
app.PdfField = NewPdfField()
|
|
||||||
app.PdfAnnotationWidget = NewPdfAnnotationWidget()
|
|
||||||
app.PdfField.SetContext(app)
|
|
||||||
app.PdfAnnotationWidget.SetContext(app)
|
|
||||||
app.PdfAnnotationWidget.container = app.PdfField.container
|
|
||||||
return app
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToPdfObject implements interface PdfModel.
|
|
||||||
func (app *PdfSignatureAppearance) ToPdfObject() core.PdfObject {
|
|
||||||
if app.Signature != nil {
|
|
||||||
app.V = app.Signature.ToPdfObject()
|
|
||||||
}
|
|
||||||
app.PdfAnnotation.ToPdfObject()
|
|
||||||
app.PdfField.ToPdfObject()
|
|
||||||
|
|
||||||
container := app.container
|
|
||||||
d := container.PdfObject.(*core.PdfObjectDictionary)
|
|
||||||
|
|
||||||
d.SetIfNotNil("Subtype", core.MakeName("Widget"))
|
|
||||||
d.SetIfNotNil("H", app.H)
|
|
||||||
d.SetIfNotNil("MK", app.MK)
|
|
||||||
d.SetIfNotNil("A", app.A)
|
|
||||||
d.SetIfNotNil("AA", app.PdfAnnotationWidget.AA)
|
|
||||||
d.SetIfNotNil("BS", app.BS)
|
|
||||||
d.SetIfNotNil("Parent", app.PdfAnnotationWidget.Parent)
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
|
@ -13,7 +13,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/unidoc/unidoc/common"
|
"github.com/unidoc/unidoc/common"
|
||||||
"github.com/unidoc/unidoc/pdf/core"
|
"github.com/unidoc/unidoc/pdf/core"
|
||||||
@ -381,62 +380,58 @@ func (a *PdfAppender) ReplacePage(pageNum int, page *PdfPage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sign signs a specific page with a digital signature using a specified signature handler.
|
// Sign signs a specific page with a digital signature using a specified signature handler.
|
||||||
// Returns an Acroform and PdfAppearance that can be used to customize the signature appearance.
|
// Returns a PdfFieldSignature that can be used to customize the signature appearance.
|
||||||
func (a *PdfAppender) Sign(pageNum int, handler SignatureHandler) (acroForm *PdfAcroForm, appearance *PdfSignatureAppearance, err error) {
|
func (a *PdfAppender) Sign(pageNum int, field *PdfFieldSignature) error {
|
||||||
acroForm = a.Reader.AcroForm
|
if field == nil {
|
||||||
|
return errors.New("signature field cannot be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
signature := field.V
|
||||||
|
if signature == nil {
|
||||||
|
return errors.New("field signature cannot be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a copy of the selected page.
|
||||||
|
pageIndex := pageNum - 1
|
||||||
|
if pageIndex < 0 || pageIndex > len(a.pages)-1 {
|
||||||
|
return fmt.Errorf("page %d not found", pageNum)
|
||||||
|
}
|
||||||
|
page := a.pages[pageIndex].Duplicate()
|
||||||
|
|
||||||
|
// Initialize signature.
|
||||||
|
if err := signature.Initialize(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
a.addNewObjects(signature.container)
|
||||||
|
|
||||||
|
// Add signature field annotations to the page annotations.
|
||||||
|
for _, annotation := range field.Annotations {
|
||||||
|
annotation.P = page.ToPdfObject()
|
||||||
|
page.Annotations = append(page.Annotations, annotation.PdfAnnotation)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add signature field to the form.
|
||||||
|
acroForm := a.Reader.AcroForm
|
||||||
if acroForm == nil {
|
if acroForm == nil {
|
||||||
acroForm = NewPdfAcroForm()
|
acroForm = NewPdfAcroForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
pageIndex := pageNum - 1
|
|
||||||
if pageIndex < 0 || pageIndex > len(a.pages)-1 {
|
|
||||||
return nil, nil, fmt.Errorf("page %d not found", pageNum)
|
|
||||||
}
|
|
||||||
page := a.pages[pageIndex].Duplicate()
|
|
||||||
|
|
||||||
// TODO add more checks before set the fields
|
|
||||||
acroForm.SigFlags = core.MakeInteger(3)
|
acroForm.SigFlags = core.MakeInteger(3)
|
||||||
acroForm.DA = core.MakeString("/F1 0 Tf 0 g")
|
acroForm.DA = core.MakeString("/F1 0 Tf 0 g")
|
||||||
n2ResourcesFont := core.MakeDict()
|
n2ResourcesFont := core.MakeDict()
|
||||||
n2ResourcesFont.Set("F1", DefaultFont().ToPdfObject())
|
n2ResourcesFont.Set("F1", DefaultFont().ToPdfObject())
|
||||||
acroForm.DR = NewPdfPageResources()
|
acroForm.DR = NewPdfPageResources()
|
||||||
acroForm.DR.Font = n2ResourcesFont
|
acroForm.DR.Font = n2ResourcesFont
|
||||||
sig := NewPdfSignature()
|
|
||||||
sig.M = core.MakeString(time.Now().Format("D:20060102150405-07'00'"))
|
|
||||||
//sig.M = core.MakeString("D:20150226112648Z")
|
|
||||||
sig.Type = core.MakeName("Sig")
|
|
||||||
sig.Reason = core.MakeString("Test1")
|
|
||||||
if err := handler.InitSignature(sig); err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
a.addNewObjects(sig.container)
|
|
||||||
|
|
||||||
appearance = NewPdfSignatureAppearance()
|
fields := append(acroForm.AllFields(), field.PdfField)
|
||||||
|
|
||||||
fields := append(acroForm.AllFields(), appearance.PdfField)
|
|
||||||
acroForm.Fields = &fields
|
acroForm.Fields = &fields
|
||||||
|
|
||||||
procPage(page)
|
|
||||||
|
|
||||||
appearance.V = sig.ToPdfObject()
|
|
||||||
appearance.FT = core.MakeName("Sig")
|
|
||||||
appearance.V = sig.ToPdfObject()
|
|
||||||
appearance.T = core.MakeString("Signature1")
|
|
||||||
appearance.F = core.MakeInteger(132)
|
|
||||||
appearance.P = page.ToPdfObject()
|
|
||||||
appearance.Rect = core.MakeArray(core.MakeInteger(0), core.MakeInteger(0), core.MakeInteger(0),
|
|
||||||
core.MakeInteger(0))
|
|
||||||
appearance.Signature = sig
|
|
||||||
|
|
||||||
// Add the signature appearance to the page annotations.
|
|
||||||
page.Annotations = append(page.Annotations, appearance.PdfAnnotationWidget.PdfAnnotation)
|
|
||||||
|
|
||||||
a.pages[pageIndex] = page
|
|
||||||
|
|
||||||
// Update acroform.
|
|
||||||
a.ReplaceAcroForm(acroForm)
|
a.ReplaceAcroForm(acroForm)
|
||||||
|
|
||||||
return acroForm, appearance, nil
|
// Replace original page.
|
||||||
|
procPage(page)
|
||||||
|
a.pages[pageIndex] = page
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplaceAcroForm replaces the acrobat form. It appends a new form to the Pdf which
|
// ReplaceAcroForm replaces the acrobat form. It appends a new form to the Pdf which
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"golang.org/x/crypto/pkcs12"
|
"golang.org/x/crypto/pkcs12"
|
||||||
|
|
||||||
@ -447,15 +448,33 @@ func TestAppenderSignPage4(t *testing.T) {
|
|||||||
t.Errorf("Fail: %v\n", err)
|
t.Errorf("Fail: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, appearance, err := appender.Sign(1, handler)
|
|
||||||
if err != nil {
|
// Create signature field and appearance.
|
||||||
|
signature := model.NewPdfSignature(handler)
|
||||||
|
signature.SetName("Test Appender")
|
||||||
|
signature.SetReason("TestAppenderSignPage4")
|
||||||
|
signature.SetDate(time.Now(), "")
|
||||||
|
|
||||||
|
sigField := model.NewPdfFieldSignature(signature)
|
||||||
|
sigField.T = core.MakeString("Signature1")
|
||||||
|
|
||||||
|
widget := model.NewPdfAnnotationWidget()
|
||||||
|
widget.F = core.MakeInteger(132)
|
||||||
|
widget.Rect = core.MakeArray(
|
||||||
|
core.MakeInteger(0),
|
||||||
|
core.MakeInteger(0),
|
||||||
|
core.MakeInteger(0),
|
||||||
|
core.MakeInteger(0),
|
||||||
|
)
|
||||||
|
widget.Parent = sigField.GetContainingPdfObject()
|
||||||
|
|
||||||
|
sigField.Annotations = append(sigField.Annotations, widget)
|
||||||
|
|
||||||
|
if err = appender.Sign(1, sigField); err != nil {
|
||||||
t.Errorf("Fail: %v\n", err)
|
t.Errorf("Fail: %v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
appearance.Signature.Name = core.MakeString("Test Appender")
|
|
||||||
appearance.Signature.Reason = core.MakeString("TestAppenderSignPage4")
|
|
||||||
|
|
||||||
err = appender.WriteToFile(tempFile("appender_sign_page_4.pdf"))
|
err = appender.WriteToFile(tempFile("appender_sign_page_4.pdf"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Fail: %v\n", err)
|
t.Errorf("Fail: %v\n", err)
|
||||||
@ -513,16 +532,34 @@ func TestAppenderSignMultiple(t *testing.T) {
|
|||||||
f.Close()
|
f.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, appearance, err := appender.Sign(1, handler)
|
|
||||||
if err != nil {
|
// Create signature field and appearance.
|
||||||
|
signature := model.NewPdfSignature(handler)
|
||||||
|
signature.SetName(fmt.Sprintf("Test Appender - Round %d", i+1))
|
||||||
|
signature.SetReason("TestAppenderSignPage4")
|
||||||
|
signature.SetDate(time.Now(), "")
|
||||||
|
|
||||||
|
sigField := model.NewPdfFieldSignature(signature)
|
||||||
|
sigField.T = core.MakeString("Signature1")
|
||||||
|
|
||||||
|
widget := model.NewPdfAnnotationWidget()
|
||||||
|
widget.F = core.MakeInteger(132)
|
||||||
|
widget.Rect = core.MakeArray(
|
||||||
|
core.MakeInteger(0),
|
||||||
|
core.MakeInteger(0),
|
||||||
|
core.MakeInteger(0),
|
||||||
|
core.MakeInteger(0),
|
||||||
|
)
|
||||||
|
widget.Parent = sigField.GetContainingPdfObject()
|
||||||
|
|
||||||
|
sigField.Annotations = append(sigField.Annotations, widget)
|
||||||
|
|
||||||
|
if err = appender.Sign(1, sigField); err != nil {
|
||||||
t.Errorf("Fail: %v\n", err)
|
t.Errorf("Fail: %v\n", err)
|
||||||
f.Close()
|
f.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
appearance.Signature.Name = core.MakeString(fmt.Sprintf("Test Appender - Round %d", i+1))
|
|
||||||
appearance.Signature.Reason = core.MakeString("TestAppenderSignPage4")
|
|
||||||
|
|
||||||
outPath := tempFile(fmt.Sprintf("appender_sign_multiple_%d.pdf", i+1))
|
outPath := tempFile(fmt.Sprintf("appender_sign_multiple_%d.pdf", i+1))
|
||||||
|
|
||||||
err = appender.WriteToFile(outPath)
|
err = appender.WriteToFile(outPath)
|
||||||
|
@ -433,28 +433,38 @@ func (ch *PdfFieldChoice) ToPdfObject() core.PdfObject {
|
|||||||
// the name of the signer and verifying document contents.
|
// the name of the signer and verifying document contents.
|
||||||
type PdfFieldSignature struct {
|
type PdfFieldSignature struct {
|
||||||
*PdfField
|
*PdfField
|
||||||
|
|
||||||
V *PdfSignature
|
V *PdfSignature
|
||||||
Lock *core.PdfIndirectObject
|
Lock *core.PdfIndirectObject
|
||||||
SV *core.PdfIndirectObject
|
SV *core.PdfIndirectObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPdfFieldSignature returns an initialized signature field.
|
||||||
|
func NewPdfFieldSignature(signature *PdfSignature) *PdfFieldSignature {
|
||||||
|
field := &PdfFieldSignature{
|
||||||
|
PdfField: NewPdfField(),
|
||||||
|
V: signature,
|
||||||
|
}
|
||||||
|
field.PdfField.SetContext(field)
|
||||||
|
field.FT = core.MakeName("Sig")
|
||||||
|
|
||||||
|
return field
|
||||||
|
}
|
||||||
|
|
||||||
// ToPdfObject returns an indirect object containing the signature field dictionary.
|
// ToPdfObject returns an indirect object containing the signature field dictionary.
|
||||||
func (sig *PdfFieldSignature) ToPdfObject() core.PdfObject {
|
func (sig *PdfFieldSignature) ToPdfObject() core.PdfObject {
|
||||||
// Set general field attributes
|
// Set general field attributes
|
||||||
sig.PdfField.ToPdfObject()
|
sig.PdfField.ToPdfObject()
|
||||||
container := sig.container
|
|
||||||
|
|
||||||
// Handle signature field specific attributes
|
// Handle signature field specific attributes
|
||||||
|
container := sig.container
|
||||||
|
|
||||||
d := container.PdfObject.(*core.PdfObjectDictionary)
|
d := container.PdfObject.(*core.PdfObjectDictionary)
|
||||||
d.Set("FT", core.MakeName("Sig"))
|
d.SetIfNotNil("FT", core.MakeName("Sig"))
|
||||||
|
d.SetIfNotNil("Lock", sig.Lock)
|
||||||
|
d.SetIfNotNil("SV", sig.SV)
|
||||||
if sig.V != nil {
|
if sig.V != nil {
|
||||||
d.Set("V", sig.V.ToPdfObject())
|
d.SetIfNotNil("V", sig.V.ToPdfObject())
|
||||||
}
|
|
||||||
if sig.Lock != nil {
|
|
||||||
d.Set("Lock", sig.Lock)
|
|
||||||
}
|
|
||||||
if sig.SV != nil {
|
|
||||||
d.Set("SV", sig.SV)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return container
|
return container
|
||||||
|
@ -7,6 +7,8 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/unidoc/unidoc/common"
|
"github.com/unidoc/unidoc/common"
|
||||||
"github.com/unidoc/unidoc/pdf/core"
|
"github.com/unidoc/unidoc/pdf/core"
|
||||||
@ -80,6 +82,7 @@ func (d *pdfSignDictionary) WriteString() string {
|
|||||||
type PdfSignature struct {
|
type PdfSignature struct {
|
||||||
Handler SignatureHandler
|
Handler SignatureHandler
|
||||||
container *core.PdfIndirectObject
|
container *core.PdfIndirectObject
|
||||||
|
|
||||||
// Type: Sig/DocTimeStamp
|
// Type: Sig/DocTimeStamp
|
||||||
Type *core.PdfObjectName
|
Type *core.PdfObjectName
|
||||||
Filter *core.PdfObjectName
|
Filter *core.PdfObjectName
|
||||||
@ -102,25 +105,20 @@ type PdfSignature struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewPdfSignature creates a new PdfSignature object.
|
// NewPdfSignature creates a new PdfSignature object.
|
||||||
func NewPdfSignature() *PdfSignature {
|
func NewPdfSignature(handler SignatureHandler) *PdfSignature {
|
||||||
sig := &PdfSignature{}
|
sig := &PdfSignature{
|
||||||
sigDict := &pdfSignDictionary{
|
Type: core.MakeName("Sig"),
|
||||||
|
Handler: handler,
|
||||||
|
}
|
||||||
|
|
||||||
|
dict := &pdfSignDictionary{
|
||||||
PdfObjectDictionary: core.MakeDict(),
|
PdfObjectDictionary: core.MakeDict(),
|
||||||
handler: &sig.Handler,
|
handler: &handler,
|
||||||
signature: sig,
|
signature: sig,
|
||||||
}
|
}
|
||||||
sig.container = core.MakeIndirectObject(sigDict)
|
|
||||||
return sig
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdfSignatureReference represents a signature reference dictionary.
|
sig.container = core.MakeIndirectObject(dict)
|
||||||
// (Table 253 - p. 477 in PDF32000_2008).
|
return sig
|
||||||
type PdfSignatureReference struct {
|
|
||||||
// Type: SigRef
|
|
||||||
TransformMethod *core.PdfObjectName
|
|
||||||
TransformParams *core.PdfObjectDictionary
|
|
||||||
Data core.PdfObject
|
|
||||||
DigestMethod *core.PdfObjectName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContainingPdfObject implements interface PdfModel.
|
// GetContainingPdfObject implements interface PdfModel.
|
||||||
@ -128,6 +126,34 @@ func (sig *PdfSignature) GetContainingPdfObject() core.PdfObject {
|
|||||||
return sig.container
|
return sig.container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetName sets the `Name` field of the signature.
|
||||||
|
func (sig *PdfSignature) SetName(name string) {
|
||||||
|
sig.Name = core.MakeString(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDate sets the `M` field of the signature.
|
||||||
|
func (sig *PdfSignature) SetDate(date time.Time, format string) {
|
||||||
|
if format == "" {
|
||||||
|
format = "D:20060102150405-07'00'"
|
||||||
|
}
|
||||||
|
|
||||||
|
sig.M = core.MakeString(date.Format(format))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetReason sets the `Reason` field of the signature.
|
||||||
|
func (sig *PdfSignature) SetReason(reason string) {
|
||||||
|
sig.Reason = core.MakeString(reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize initializes the PdfSignature.
|
||||||
|
func (sig *PdfSignature) Initialize() error {
|
||||||
|
if sig.Handler == nil {
|
||||||
|
return errors.New("signature handler cannot be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
return sig.Handler.InitSignature(sig)
|
||||||
|
}
|
||||||
|
|
||||||
// ToPdfObject implements interface PdfModel.
|
// ToPdfObject implements interface PdfModel.
|
||||||
func (sig *PdfSignature) ToPdfObject() core.PdfObject {
|
func (sig *PdfSignature) ToPdfObject() core.PdfObject {
|
||||||
container := sig.container
|
container := sig.container
|
||||||
@ -213,146 +239,3 @@ func (r *PdfReader) newPdfSignatureFromIndirect(container *core.PdfIndirectObjec
|
|||||||
|
|
||||||
return sig, nil
|
return sig, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdfSignatureField represents a form field that contains a digital signature.
|
|
||||||
// (12.7.4.5 - Signature Fields p. 454 in PDF32000_2008).
|
|
||||||
//
|
|
||||||
// The signature form field serves two primary purposes. 1. Define the form field that will provide the
|
|
||||||
// visual signing properties for display but may also hold information needed when the actual signing
|
|
||||||
// takes place such as signature method. This carries information from the author of the document to the
|
|
||||||
// software that later does signing.
|
|
||||||
//
|
|
||||||
// Filling in (signing) the signature field entails updating at least the V entry and usually the AP entry of the
|
|
||||||
// associated widget annotation. (Exporting a signature field exports the T, V, AP entries)
|
|
||||||
//
|
|
||||||
// The annotation rectangle (Rect) in such a dictionary shall give the position of the field on its page. Signature
|
|
||||||
// fields that are not intended to be visible shall have an annotation rectangle that has zero height and width. PDF
|
|
||||||
// processors shall treat such signatures as not visible. PDF processors shall also treat signatures as not
|
|
||||||
// visible if either the Hidden bit or the NoView bit of the F entry is true
|
|
||||||
//
|
|
||||||
// The location of a signature within a document can have a bearing on its legal meaning. For this reason,
|
|
||||||
// signature fields shall never refer to more than one annotation.
|
|
||||||
type PdfSignatureField struct {
|
|
||||||
container *core.PdfIndirectObject
|
|
||||||
|
|
||||||
V *PdfSignature
|
|
||||||
Lock *core.PdfIndirectObject
|
|
||||||
SV *core.PdfIndirectObject
|
|
||||||
Kids *core.PdfObjectArray
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPdfSignatureField prepares a PdfSignatureField from a PdfSignature.
|
|
||||||
func NewPdfSignatureField(signature *PdfSignature) *PdfSignatureField {
|
|
||||||
return &PdfSignatureField{
|
|
||||||
V: signature,
|
|
||||||
container: core.MakeIndirectObject(core.MakeDict()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ToPdfObject implements interface PdfModel.
|
|
||||||
func (sf *PdfSignatureField) ToPdfObject() core.PdfObject {
|
|
||||||
container := sf.container
|
|
||||||
dict := container.PdfObject.(*core.PdfObjectDictionary)
|
|
||||||
|
|
||||||
// Set fields.
|
|
||||||
if sf.V != nil {
|
|
||||||
dict.Set("V", sf.V.ToPdfObject())
|
|
||||||
}
|
|
||||||
|
|
||||||
dict.Set("FT", core.MakeName("Sig"))
|
|
||||||
dict.SetIfNotNil("Lock", sf.Lock)
|
|
||||||
dict.SetIfNotNil("SV", sf.SV)
|
|
||||||
dict.SetIfNotNil("Kids", sf.Kids)
|
|
||||||
// Other standard fields...
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdfSignatureFieldLock represents signature field lock dictionary.
|
|
||||||
// (Table 233 - p. 455 in PDF32000_2008).
|
|
||||||
type PdfSignatureFieldLock struct {
|
|
||||||
Type core.PdfObject
|
|
||||||
Action *core.PdfObjectName
|
|
||||||
Fields *core.PdfObjectArray
|
|
||||||
P *core.PdfObjectInteger
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdfSignatureFieldSeed represents signature field seed value dictionary.
|
|
||||||
// (Table 234 - p. 455 in PDF32000_2008).
|
|
||||||
type PdfSignatureFieldSeed struct {
|
|
||||||
container *core.PdfIndirectObject
|
|
||||||
|
|
||||||
Ff *core.PdfObjectInteger
|
|
||||||
Filter *core.PdfObjectName
|
|
||||||
SubFilter *core.PdfObjectArray
|
|
||||||
DigestMethod *core.PdfObjectArray
|
|
||||||
V *core.PdfObjectInteger
|
|
||||||
Cert core.PdfObject
|
|
||||||
Reasons *core.PdfObjectArray
|
|
||||||
MDP *core.PdfObjectDictionary
|
|
||||||
TimeStamp *core.PdfObjectDictionary
|
|
||||||
LegalAttestation *core.PdfObjectArray
|
|
||||||
AddRevInfo *core.PdfObjectBool
|
|
||||||
LockDocument *core.PdfObjectName
|
|
||||||
AppearanceFilter *core.PdfObjectString
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pss *PdfSignatureFieldSeed) ToPdfObject() core.PdfObject {
|
|
||||||
container := pss.container
|
|
||||||
dict := container.PdfObject.(*core.PdfObjectDictionary)
|
|
||||||
|
|
||||||
dict.SetIfNotNil("Ff", pss.Ff)
|
|
||||||
dict.SetIfNotNil("Filter", pss.Filter)
|
|
||||||
dict.SetIfNotNil("SubFilter", pss.SubFilter)
|
|
||||||
dict.SetIfNotNil("DigestMethod", pss.DigestMethod)
|
|
||||||
dict.SetIfNotNil("V", pss.V)
|
|
||||||
dict.SetIfNotNil("Cert", pss.Cert)
|
|
||||||
dict.SetIfNotNil("Reasons", pss.Reasons)
|
|
||||||
dict.SetIfNotNil("MDP", pss.MDP)
|
|
||||||
dict.SetIfNotNil("TimeStamp", pss.TimeStamp)
|
|
||||||
dict.SetIfNotNil("LegalAttestation", pss.LegalAttestation)
|
|
||||||
dict.SetIfNotNil("AddRevInfo", pss.AddRevInfo)
|
|
||||||
dict.SetIfNotNil("LockDocument", pss.LockDocument)
|
|
||||||
dict.SetIfNotNil("AppearanceFilter", pss.AppearanceFilter)
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdfCertificateSeed represents certificate seed value dictionary.
|
|
||||||
// (Table 235 - p. 457 in PDF32000_2008).
|
|
||||||
type PdfCertificateSeed struct {
|
|
||||||
container *core.PdfIndirectObject
|
|
||||||
// Type
|
|
||||||
Ff *core.PdfObjectInteger
|
|
||||||
Subject *core.PdfObjectArray
|
|
||||||
SignaturePolicyOID *core.PdfObjectString
|
|
||||||
SignaturePolicyHashValue *core.PdfObjectString
|
|
||||||
SignaturePolicyHashAlgorithm *core.PdfObjectName
|
|
||||||
SignaturePolicyCommitmentType *core.PdfObjectArray
|
|
||||||
SubjectDN *core.PdfObjectArray
|
|
||||||
KeyUsage *core.PdfObjectArray
|
|
||||||
Issuer *core.PdfObjectArray
|
|
||||||
OID *core.PdfObjectArray
|
|
||||||
URL *core.PdfObjectString
|
|
||||||
URLType *core.PdfObjectName
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pcs *PdfCertificateSeed) ToPdfObject() core.PdfObject {
|
|
||||||
container := pcs.container
|
|
||||||
dict := container.PdfObject.(*core.PdfObjectDictionary)
|
|
||||||
|
|
||||||
dict.SetIfNotNil("Ff", pcs.Ff)
|
|
||||||
dict.SetIfNotNil("Subject", pcs.Subject)
|
|
||||||
dict.SetIfNotNil("SignaturePolicyOID", pcs.SignaturePolicyOID)
|
|
||||||
dict.SetIfNotNil("SignaturePolicyHashValue", pcs.SignaturePolicyHashValue)
|
|
||||||
dict.SetIfNotNil("SignaturePolicyHashAlgorithm", pcs.SignaturePolicyHashAlgorithm)
|
|
||||||
dict.SetIfNotNil("SignaturePolicyCommitmentType", pcs.SignaturePolicyCommitmentType)
|
|
||||||
dict.SetIfNotNil("SubjectDN", pcs.SubjectDN)
|
|
||||||
dict.SetIfNotNil("KeyUsage", pcs.KeyUsage)
|
|
||||||
dict.SetIfNotNil("Issuer", pcs.Issuer)
|
|
||||||
dict.SetIfNotNil("OID", pcs.OID)
|
|
||||||
dict.SetIfNotNil("URL", pcs.URL)
|
|
||||||
dict.SetIfNotNil("URLType", pcs.URLType)
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user