github.com/pdfcpu/pdfcpu@v0.11.1/pkg/api/test/sign_test.go (about) 1 /* 2 Copyright 2025 The pdf Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package test 18 19 import ( 20 "fmt" 21 "path/filepath" 22 "testing" 23 24 "github.com/pdfcpu/pdfcpu/pkg/api" 25 ) 26 27 func logResults(ss []string) { 28 for _, s := range ss { 29 fmt.Println(s) 30 } 31 } 32 33 func TestValidateSignature_X509_RSA_SHA1(t *testing.T) { 34 msg := "ValidateSignature_X509_RSA_SHA1" 35 36 // You may provide your signed PDFs in this dir. 37 dir := filepath.Join(samplesDir, "signatures", "adbe.x509.rsa_sha1") 38 39 for _, fn := range AllPDFs(t, dir) { 40 inFile := filepath.Join(dir, fn) 41 fmt.Println("\nvalidate signatures of " + inFile) 42 all := true 43 full := false 44 ss, err := api.ValidateSignaturesFile(inFile, all, full, conf) 45 if err != nil { 46 t.Fatalf("%s: %v\n", msg, err) 47 } 48 logResults(ss) 49 } 50 } 51 52 func TestValidateSignature_PKCS7_SHA1(t *testing.T) { 53 msg := "ValidateSignature_PKCS7_SHA1" 54 55 // You may provide your signed PDFs in this dir. 56 dir := filepath.Join(samplesDir, "signatures", "adbe.pkcs7.sha1") 57 58 for _, fn := range AllPDFs(t, dir) { 59 inFile := filepath.Join(dir, fn) 60 fmt.Println("validate signatures of " + inFile) 61 all := true 62 full := false 63 ss, err := api.ValidateSignaturesFile(inFile, all, full, conf) 64 if err != nil { 65 t.Fatalf("%s: %v\n", msg, err) 66 } 67 logResults(ss) 68 } 69 } 70 71 func TestValidateSignature_PKCS7_Detached(t *testing.T) { 72 msg := "ValidateSignature_PKCS7_Detached" 73 74 // You may provide your signed PDFs in this dir. 75 dir := filepath.Join(samplesDir, "signatures", "adbe.pkcs7.detached") 76 77 for _, fn := range AllPDFs(t, dir) { 78 inFile := filepath.Join(dir, fn) 79 fmt.Println("\nvalidate signatures of " + inFile) 80 all := true 81 full := true 82 ss, err := api.ValidateSignaturesFile(inFile, all, full, conf) 83 if err != nil { 84 t.Fatalf("%s: %v\n", msg, err) 85 } 86 logResults(ss) 87 } 88 } 89 90 func TestValidateSignature_ETSI_CAdES_Detached(t *testing.T) { 91 msg := "ValidateSignature_ETSI_CAdES_Detached" 92 93 // You may provide your signed PDFs in this dir. 94 dir := filepath.Join(samplesDir, "signatures", "ETSI.CAdES.detached") 95 96 for _, fn := range AllPDFs(t, dir) { 97 inFile := filepath.Join(dir, fn) 98 fmt.Println("\nvalidate signatures of " + inFile) 99 all := true 100 full := true 101 ss, err := api.ValidateSignaturesFile(inFile, all, full, conf) 102 if err != nil { 103 t.Fatalf("%s: %v\n", msg, err) 104 } 105 logResults(ss) 106 } 107 }