@@ -11,19 +11,22 @@ import (
1111 "time"
1212)
1313
14- func hmacsha256 (sdkappid int , key string , identifier string , currTime int64 , expire int ) string {
14+ func hmacsha256 (sdkappid int , key string , identifier string , currTime int64 , expire int , base64UserBuf * string ) string {
1515 var contentToBeSigned string
1616 contentToBeSigned = "TLS.identifier:" + identifier + "\n "
1717 contentToBeSigned += "TLS.sdkappid:" + strconv .Itoa (sdkappid ) + "\n "
1818 contentToBeSigned += "TLS.time:" + strconv .FormatInt (currTime , 10 ) + "\n "
1919 contentToBeSigned += "TLS.expire:" + strconv .Itoa (expire ) + "\n "
20+ if nil != base64UserBuf {
21+ contentToBeSigned += "TLS.userbuf:" + * base64UserBuf + "\n "
22+ }
2023
2124 h := hmac .New (sha256 .New , []byte (key ))
2225 h .Write ([]byte (contentToBeSigned ))
2326 return base64 .StdEncoding .EncodeToString (h .Sum (nil ))
2427}
2528
26- func GenSig (sdkappid int , key string , identifier string , expire int ) (string , error ) {
29+ func genSig (sdkappid int , key string , identifier string , expire int , userbuf [] byte ) (string , error ) {
2730 currTime := time .Now ().Unix ()
2831 var sigDoc map [string ]interface {}
2932 sigDoc = make (map [string ]interface {})
@@ -32,7 +35,14 @@ func GenSig(sdkappid int, key string, identifier string, expire int) (string, er
3235 sigDoc ["TLS.sdkappid" ] = sdkappid
3336 sigDoc ["TLS.expire" ] = expire
3437 sigDoc ["TLS.time" ] = currTime
35- sigDoc ["TLS.sig" ] = hmacsha256 (sdkappid , key , identifier , currTime , expire )
38+ var base64UserBuf string
39+ if nil != userbuf {
40+ base64UserBuf = base64 .StdEncoding .EncodeToString (userbuf )
41+ sigDoc ["TLS.userbuf" ] = base64UserBuf
42+ sigDoc ["TLS.sig" ] = hmacsha256 (sdkappid , key , identifier , currTime , expire , & base64UserBuf )
43+ } else {
44+ sigDoc ["TLS.sig" ] = hmacsha256 (sdkappid , key , identifier , currTime , expire , nil )
45+ }
3646
3747 data , err := json .Marshal (sigDoc )
3848 if err != nil {
@@ -45,3 +55,12 @@ func GenSig(sdkappid int, key string, identifier string, expire int) (string, er
4555 w .Close ()
4656 return base64urlEncode (b .Bytes ()), nil
4757}
58+
59+ func GenSig (sdkappid int , key string , identifier string , expire int ) (string , error ) {
60+ return genSig (sdkappid , key , identifier , expire , nil )
61+ }
62+
63+ func GenSigWithUserBuf (sdkappid int , key string , identifier string , expire int , userbuf []byte ) (string , error ) {
64+ return genSig (sdkappid , key , identifier , expire , userbuf )
65+ }
66+
0 commit comments