62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package sm2
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func (s *Sm2) SetError(err error) *Sm2 {
|
|
s.err = append(s.err, err)
|
|
return s
|
|
}
|
|
|
|
func (s *Sm2) encryptErrHandler() error {
|
|
if len(s.data) == 0 {
|
|
s.SetError(fmt.Errorf("data is empty"))
|
|
}
|
|
if s.publicKey == nil {
|
|
s.SetError(fmt.Errorf("publicKey is nil"))
|
|
}
|
|
return s.errHandle()
|
|
}
|
|
|
|
func (s *Sm2) decryptErrHandler() error {
|
|
if len(s.data) == 0 {
|
|
s.SetError(fmt.Errorf("data is empty"))
|
|
}
|
|
if s.privateKey == nil {
|
|
s.SetError(fmt.Errorf("privateKey is nil"))
|
|
}
|
|
return s.errHandle()
|
|
}
|
|
|
|
func (s *Sm2) verifyErrHandler() error {
|
|
if len(s.data) == 0 {
|
|
s.SetError(fmt.Errorf("data is empty"))
|
|
}
|
|
if s.publicKey == nil {
|
|
s.SetError(fmt.Errorf("publicKey is nil"))
|
|
}
|
|
return s.errHandle()
|
|
}
|
|
|
|
func (s *Sm2) signErrHandler() error {
|
|
if len(s.data) == 0 {
|
|
s.SetError(fmt.Errorf("data is empty"))
|
|
}
|
|
if s.privateKey == nil {
|
|
s.SetError(fmt.Errorf("privateKey is nil"))
|
|
}
|
|
return s.errHandle()
|
|
}
|
|
|
|
func (s *Sm2) errHandle() error {
|
|
if len(s.err) > 0 {
|
|
errStr := ""
|
|
for _, e := range s.err {
|
|
errStr += e.Error() + "\n"
|
|
}
|
|
return fmt.Errorf(errStr)
|
|
}
|
|
return nil
|
|
}
|