go-mail/util_test.go

35 lines
827 B
Go
Raw Normal View History

package mail
import (
"crypto/rsa"
2024-09-26 16:43:58 +02:00
"crypto/tls"
2024-09-26 17:08:38 +02:00
"crypto/x509"
)
2024-09-26 16:43:58 +02:00
const (
2024-09-26 17:08:38 +02:00
certFilePath = "dummy-chain-cert.pem"
keyFilePath = "dummy-child-key.pem"
2024-09-26 16:43:58 +02:00
)
// getDummyCryptoMaterial loads a certificate and a private key form local disk for testing purposes
func getDummyCryptoMaterial() (*rsa.PrivateKey, *x509.Certificate, *x509.Certificate, error) {
2024-09-26 16:43:58 +02:00
keyPair, err := tls.LoadX509KeyPair(certFilePath, keyFilePath)
if err != nil {
return nil, nil, nil, err
}
privateKey := keyPair.PrivateKey.(*rsa.PrivateKey)
2024-09-26 17:08:38 +02:00
certificate, err := x509.ParseCertificate(keyPair.Certificate[0])
if err != nil {
return nil, nil, nil, err
}
intermediateCertificate, err := x509.ParseCertificate(keyPair.Certificate[1])
if err != nil {
return nil, nil, nil, err
}
return privateKey, certificate, intermediateCertificate, nil
}