clash/common/net/tls.go

20 lines
501 B
Go
Raw Normal View History

2022-12-03 06:14:15 +00:00
package net
import (
"crypto/tls"
"fmt"
)
2022-12-04 15:05:13 +00:00
func ParseCert(certificate, privateKey string) (tls.Certificate, error) {
2022-12-03 06:14:15 +00:00
cert, painTextErr := tls.X509KeyPair([]byte(certificate), []byte(privateKey))
if painTextErr == nil {
return cert, nil
}
cert, loadErr := tls.LoadX509KeyPair(certificate, privateKey)
if loadErr != nil {
2022-12-04 15:05:13 +00:00
return tls.Certificate{}, fmt.Errorf("parse certificate failed, maybe format error:%s, or path error: %s", painTextErr.Error(), loadErr.Error())
2022-12-03 06:14:15 +00:00
}
return cert, nil
2022-12-04 15:05:13 +00:00
}