forked from qjfoidnh/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sign.go
41 lines (35 loc) · 753 Bytes
/
sign.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package panhome
import (
"github.com/qjfoidnh/Baidu-Login/bdcrypto"
"github.com/qjfoidnh/BaiduPCS-Go/baidupcs/netdisksign"
"github.com/qjfoidnh/BaiduPCS-Go/pcsutil/converter"
)
type (
// SignRes 签名结果
SignRes interface {
Sign() string
Timestamp() string
}
signRes struct {
sign string
timestamp string
}
)
func (sr *signRes) Sign() string {
return sr.sign
}
func (sr *signRes) Timestamp() string {
return sr.timestamp
}
func (ph *PanHome) Signature() (sign SignRes, err error) {
err = ph.getSignInfo()
if err != nil {
return nil, err
}
o := netdisksign.Sign2(ph.sign3, ph.sign1)
signed := bdcrypto.Base64Encode(o)
return &signRes{
sign: converter.ToString(signed),
timestamp: ph.timestamp,
}, nil
}