gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/x509/certinfo_test.go (about) 1 package x509_test 2 3 import ( 4 "fmt" 5 "gitee.com/ks-custle/core-gm/x509" 6 "testing" 7 ) 8 9 func TestCertinfo(t *testing.T) { 10 certPath := "testdata/sm2_sign_cert.cer" 11 12 cert, _ := x509.ReadCertificateFromPemFile(certPath) 13 14 certText, err := x509.CertificateText(cert) 15 if err != nil { 16 t.Fatal(err) 17 } 18 fmt.Println(certText) 19 } 20 21 func TestCertificateText(t *testing.T) { 22 type args struct { 23 certPath string 24 } 25 tests := []struct { 26 name string 27 args args 28 }{ 29 { 30 name: "sm2 sign cert", 31 args: args{ 32 certPath: "testdata/sm2_sign_cert.cer", 33 }, 34 }, 35 { 36 name: "ecdsa sign cert", 37 args: args{ 38 certPath: "testdata/ecdsa_sign_cert.cer", 39 }, 40 }, 41 { 42 name: "ecdsaext sign cert", 43 args: args{ 44 certPath: "testdata/ecdsaext_sign_cert.cer", 45 }, 46 }, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 cert, _ := x509.ReadCertificateFromPemFile(tt.args.certPath) 51 certText, err := x509.CertificateText(cert) 52 if err != nil { 53 t.Fatal(err) 54 } 55 fmt.Println(certText) 56 }) 57 } 58 }