1
0
Fork 0

More cleanup

master
Philip O'Toole 2 years ago
parent 220c3f9243
commit fed557c77a

@ -10,8 +10,7 @@ import (
"time" "time"
) )
// GenerateCACert generates a new CA certificate and returns the cert and key. The function // GenerateCACert generates a new CA certificate and returns the cert and key as PEM-encoded bytes.
// takes in a subject, a validity period, and a key size.
func GenerateCACert(subject pkix.Name, validFrom, validFor time.Duration, keySize int) ([]byte, []byte, error) { func GenerateCACert(subject pkix.Name, validFrom, validFor time.Duration, keySize int) ([]byte, []byte, error) {
// generate a new private key // generate a new private key
key, err := rsa.GenerateKey(rand.Reader, keySize) key, err := rsa.GenerateKey(rand.Reader, keySize)
@ -44,9 +43,9 @@ func GenerateCACert(subject pkix.Name, validFrom, validFor time.Duration, keySiz
return certPEM, keyPEM, nil return certPEM, keyPEM, nil
} }
// function that generates a new x509 certificate and returns the cert and key. The function // GenerateCert generates a new x509 certificate and returns the cert and key as PEM-encoded bytes.
// should take in a subject, a validity period, and a key size. It should optionally take in // The function should take in a subject, a validity period, and a key size. It should optionally
// a parent certificate and key. If a parent certificate and key are provided, the new // take in a parent certificate and key. If a parent certificate and key are provided, the new
// certificate should be signed by the parent. If no parent certificate and key are provided, // certificate should be signed by the parent. If no parent certificate and key are provided,
// the new certificate should be self-signed. // the new certificate should be self-signed.
func GenerateCert(subject pkix.Name, validFor time.Duration, keySize int, parent *x509.Certificate, parentKey interface{}) ([]byte, []byte, error) { func GenerateCert(subject pkix.Name, validFor time.Duration, keySize int, parent *x509.Certificate, parentKey interface{}) ([]byte, []byte, error) {

@ -5,7 +5,6 @@ import (
"crypto/x509" "crypto/x509"
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/pem" "encoding/pem"
"io/ioutil"
"testing" "testing"
"time" "time"
) )
@ -63,9 +62,6 @@ func TestGenerateCASignedCert(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
// write certPEM and keyPEM to files
ioutil.WriteFile("cert.pem", certPEM, 0644)
cert, _ := pem.Decode(certPEM) cert, _ := pem.Decode(certPEM)
if cert == nil { if cert == nil {
panic("failed to decode certificate") panic("failed to decode certificate")

Loading…
Cancel
Save