Compare commits

..

2 commits

Author SHA1 Message Date
theexiile1305
46cf2ed498
fix: part boundray and message encoding 2024-09-29 16:46:30 +02:00
theexiile1305
79f22fb722
feat: specific error if certificate is invalid 2024-09-26 17:28:24 +02:00
2 changed files with 13 additions and 4 deletions

View file

@ -138,6 +138,10 @@ func (mw *msgWriter) writeMsg(msg *Msg) {
if msg.hasMixed() {
mw.stopMP()
}
if msg.hasSMime() {
mw.stopMP()
}
}
// writeGenHeader writes out all generic headers to the msgWriter
@ -341,7 +345,7 @@ func (mw *msgWriter) writeBody(writeFunc func(io.Writer) (int64, error), encodin
encodedWriter = quotedprintable.NewWriter(&writeBuffer)
} else if encoding == EncodingB64 && !singingWithSMime {
encodedWriter = base64.NewEncoder(base64.StdEncoding, &lineBreaker)
} else if encoding == NoEncoding {
} else if encoding == NoEncoding || singingWithSMime {
_, err = writeFunc(&writeBuffer)
if err != nil {
mw.err = fmt.Errorf("bodyWriter function: %w", err)

11
sime.go
View file

@ -16,6 +16,9 @@ var (
// ErrInvalidKeyPair should be used if key pair is invalid
ErrInvalidKeyPair = errors.New("invalid key pair")
// ErrInvalidCertificate should be used if a certificate is invalid
ErrInvalidCertificate = errors.New("invalid certificate")
// ErrCouldNotInitialize should be used if the signed data could not initialize
ErrCouldNotInitialize = errors.New("could not initialize signed data")
@ -46,7 +49,7 @@ func newSMime(keyPair *tls.Certificate) (*SMime, error) {
for _, cert := range keyPair.Certificate[1:] {
c, err := x509.ParseCertificate(cert)
if err != nil {
return nil, err
return nil, ErrInvalidCertificate
}
parentCertificates = append(parentCertificates, c)
}
@ -102,8 +105,10 @@ func encodeToPEM(msg []byte) (*string, error) {
}
r := arrayBuffer.String()
r = strings.ReplaceAll(r, "-----BEGIN -----\n", "")
r = strings.ReplaceAll(r, "-----END -----\n", "")
r = strings.TrimPrefix(r, "-----BEGIN -----")
r = strings.Trim(r, "\n")
r = strings.TrimSuffix(r, "-----END -----")
r = strings.Trim(r, "\n")
return &r, nil
}