Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
421687c4
Commit
421687c4
authored
Dec 03, 2015
by
Loïck Bonniot
Browse files
[auth] Add example for x509.Verify
parent
16e5afff
Pipeline
#38
passed with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
auth/cert_test.go
View file @
421687c4
...
...
@@ -2,6 +2,7 @@ package auth
import
(
"crypto/rsa"
"crypto/x509"
"fmt"
"os"
"testing"
...
...
@@ -151,10 +152,28 @@ func ExampleGetCertificate() {
if
cert
==
nil
||
err
!=
nil
{
fmt
.
Println
(
err
)
}
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:
// OK
// Certificate generated
// Certificate authenticated
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment