mirror of
https://github.com/usual2970/certimate.git
synced 2025-10-05 22:14:53 +00:00
feat: add aws acm uploader
This commit is contained in:
@@ -14,6 +14,10 @@ import (
|
||||
// 出参:
|
||||
// - 是否相同。
|
||||
func EqualCertificate(a, b *x509.Certificate) bool {
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return string(a.Signature) == string(b.Signature) &&
|
||||
a.SignatureAlgorithm == b.SignatureAlgorithm &&
|
||||
a.SerialNumber.String() == b.SerialNumber.String() &&
|
||||
|
@@ -8,6 +8,27 @@ import (
|
||||
xerrors "github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// 将 x509.Certificate 对象转换为 PEM 编码的字符串。
|
||||
//
|
||||
// 入参:
|
||||
// - cert: x509.Certificate 对象。
|
||||
//
|
||||
// 出参:
|
||||
// - certPem: 证书 PEM 内容。
|
||||
// - err: 错误。
|
||||
func ConvertCertificateToPEM(cert *x509.Certificate) (certPem string, err error) {
|
||||
if cert == nil {
|
||||
return "", xerrors.New("cert is nil")
|
||||
}
|
||||
|
||||
block := &pem.Block{
|
||||
Type: "CERTIFICATE",
|
||||
Bytes: cert.Raw,
|
||||
}
|
||||
|
||||
return string(pem.EncodeToMemory(block)), nil
|
||||
}
|
||||
|
||||
// 将 ecdsa.PrivateKey 对象转换为 PEM 编码的字符串。
|
||||
//
|
||||
// 入参:
|
||||
@@ -17,6 +38,10 @@ import (
|
||||
// - privkeyPem: 私钥 PEM 内容。
|
||||
// - err: 错误。
|
||||
func ConvertECPrivateKeyToPEM(privkey *ecdsa.PrivateKey) (privkeyPem string, err error) {
|
||||
if privkey == nil {
|
||||
return "", xerrors.New("privkey is nil")
|
||||
}
|
||||
|
||||
data, err := x509.MarshalECPrivateKey(privkey)
|
||||
if err != nil {
|
||||
return "", xerrors.Wrap(err, "failed to marshal EC private key")
|
||||
|
Reference in New Issue
Block a user