Skip to content
Snippets Groups Projects
Commit 421687c4 authored by Loïck Bonniot's avatar Loïck Bonniot
Browse files

[auth] Add example for x509.Verify

parent 16e5afff
No related branches found
No related tags found
1 merge request!3Add crypto library and CI
Pipeline #
...@@ -2,6 +2,7 @@ package auth ...@@ -2,6 +2,7 @@ package auth
import ( import (
"crypto/rsa" "crypto/rsa"
"crypto/x509"
"fmt" "fmt"
"os" "os"
"testing" "testing"
...@@ -151,10 +152,28 @@ func ExampleGetCertificate() { ...@@ -151,10 +152,28 @@ func ExampleGetCertificate() {
if cert == nil || err != nil { if cert == nil || err != nil {
fmt.Println(err) fmt.Println(err)
} else { } else {
fmt.Println("OK") fmt.Println("Certificate generated")
}
// Check certificate validity
roots := x509.NewCertPool()
roots.AddCert(signerCertificate)
signeeCertificate, _ := PEMToCertificate(cert)
_, err = signeeCertificate.Verify(x509.VerifyOptions{
Roots: roots,
})
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Certificate authenticated")
} }
// Output: // Output:
// OK // Certificate generated
// Certificate authenticated
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment