Skip to content

Commit 597c644

Browse files
committed
update
1 parent 5941d86 commit 597c644

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

rsa.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@ type RSA struct {
99
privateKey *RSAPrivateKey
1010
}
1111

12-
func (r *RSA) SetPublicKey(publicKey []byte) (err error) {
12+
func (r *RSA) SetPublicKeyBytes(publicKey []byte) (err error) {
1313
r.publicKey, err = NewRSAPublicKey(publicKey)
1414
return err
1515
}
1616

17+
func (r *RSA) SetPublicKey(publicKey *RSAPublicKey) *RSA {
18+
r.publicKey = publicKey
19+
return r
20+
}
21+
1722
func (r *RSA) PublicKey() *RSAPublicKey {
1823
return r.publicKey
1924
}
2025

21-
func (r *RSA) SetPrivateKey(privateKey []byte) (err error) {
26+
func (r *RSA) SetPrivateKeyBytes(privateKey []byte) (err error) {
2227
r.privateKey, err = NewRSAPrivateKey(privateKey)
2328
return err
2429
}
2530

31+
func (r *RSA) SetPrivateKey(privateKey *RSAPrivateKey) *RSA {
32+
r.privateKey = privateKey
33+
return r
34+
}
35+
2636
func (r *RSA) PrivateKey() *RSAPrivateKey {
2737
return r.privateKey
2838
}

rsa_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ func Test_SetPrivateKey(t *testing.T) {
6161
// 公钥加密私钥解密
6262
func Test_PubENCTYPTPriDECRYPT(t *testing.T) {
6363
a := NewRSA()
64-
if err := a.SetPublicKey(testPubkey); err != nil {
64+
if err := a.SetPublicKeyBytes(testPubkey); err != nil {
6565
t.Error(err)
6666
}
67-
if err := a.SetPrivateKey(testPrivatekey); err != nil {
67+
if err := a.SetPrivateKeyBytes(testPrivatekey); err != nil {
6868
t.Error(err)
6969
}
7070
pubenctypt, err := a.PublicKey().Encrypt([]byte(`hello world`))
@@ -84,10 +84,10 @@ func Test_PubENCTYPTPriDECRYPT(t *testing.T) {
8484
// 公钥解密私钥加密
8585
func Test_PriENCTYPTPubDECRYPT(t *testing.T) {
8686
a := NewRSA()
87-
if err := a.SetPublicKey(testPubkey); err != nil {
87+
if err := a.SetPublicKeyBytes(testPubkey); err != nil {
8888
t.Error(err)
8989
}
90-
if err := a.SetPrivateKey(testPrivatekey); err != nil {
90+
if err := a.SetPrivateKeyBytes(testPrivatekey); err != nil {
9191
t.Error(err)
9292
}
9393
prienctypt, err := a.PrivateKey().Encrypt([]byte(`hello world`))

0 commit comments

Comments
 (0)