]> 127.0.0.1 Git - part/.git/commitdiff
1 v0.28.20240821214042 v0.28.20240821214546
authorqydysky <qydysky@foxmail.com>
Wed, 21 Aug 2024 21:40:12 +0000 (05:40 +0800)
committerqydysky <qydysky@foxmail.com>
Wed, 21 Aug 2024 21:40:12 +0000 (05:40 +0800)
crypto/EasyCrypt.go

index 4906d870325b1f644d4c7c7ea6fb042c36b5626c..bc3694e8e140163665cd8d1cc639aace6f99509a 100644 (file)
@@ -6,6 +6,7 @@ import (
        "crypto/rand"
        "encoding/pem"
        "errors"
+       "io"
 
        "golang.org/x/crypto/chacha20poly1305"
 )
@@ -80,6 +81,9 @@ func Decrypt(b, priKey []byte) (msg []byte, e error) {
        if pb, _ := pem.Decode(priKey); pb.Type != pemType+` PRIVATE KEY` {
                e = ErrPemType
                return
+       } else if 4+pemLen > len(b) {
+               e = io.EOF
+               return
        } else if p2, e = ecdh.X25519().NewPrivateKey(pb.Bytes); e != nil {
                return
        } else if q1, e = ecdh.X25519().NewPublicKey(b[4 : 4+pemLen]); e != nil {