Skip to content

Commit b02072a

Browse files
author
yutingzeng
committed
增加构造userbuf
1 parent c8fca88 commit b02072a

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

TLSSigAPITest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ func main() {
1717
} else {
1818
fmt.Println(sig)
1919
}
20-
sig, err = tencentyun.GenSigWithUserBuf(sdkappid, key, "xiaojun", 86400*180, []byte("abc"))
20+
var userbuf []byte = tencentyun.GetUserBuf("xiaojun",sdkappid,10000,86400*180,255,0);
21+
sig, err = tencentyun.GenSigWithUserBuf(sdkappid, key, "xiaojun", 86400*180, userbuf)
2122
if err != nil {
2223
fmt.Println(err.Error())
2324
} else {

tencentyun/TLSSigAPI.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,75 @@ import (
1010
"strconv"
1111
"time"
1212
)
13+
func GetUserBuf(account string, dwSdkappid uint32,dwAuthID uint32,
14+
dwExpTime uint32,dwPrivilegeMap uint32,dwAccountType uint32) []byte{
1315

16+
offset := 0;
17+
length := 1+2+len(account)+20;
18+
userBuf := make([]byte,length);
19+
20+
userBuf[offset]= 0;
21+
offset++;
22+
userBuf[offset] = (byte)((len(account) & 0xFF00) >> 8);
23+
offset++;
24+
userBuf[offset] = (byte)(len(account) & 0x00FF);
25+
offset++;
26+
27+
for ; offset < len(account) + 3; offset++{
28+
userBuf[offset] = account[offset-3];
29+
}
30+
31+
//dwSdkAppid
32+
userBuf[offset] = (byte)((dwSdkappid & 0xFF000000) >> 24);
33+
offset++;
34+
userBuf[offset] = (byte)((dwSdkappid & 0x00FF0000) >> 16);
35+
offset++;
36+
userBuf[offset] = (byte)((dwSdkappid & 0x0000FF00) >> 8);
37+
offset++;
38+
userBuf[offset] = (byte)(dwSdkappid & 0x000000FF);
39+
offset++;
40+
41+
//dwAuthId
42+
userBuf[offset] = (byte)((dwAuthID & 0xFF000000) >> 24);
43+
offset++;
44+
userBuf[offset] = (byte)((dwAuthID & 0x00FF0000) >> 16);
45+
offset++;
46+
userBuf[offset] = (byte)((dwAuthID & 0x0000FF00) >> 8);
47+
offset++;
48+
userBuf[offset] = (byte)(dwAuthID & 0x000000FF);
49+
offset++;
50+
51+
//dwExpTime 不确定是直接填还是当前s数加上超时时间
52+
userBuf[offset] = (byte)((dwExpTime & 0xFF000000) >> 24);
53+
offset++;
54+
userBuf[offset] = (byte)((dwExpTime & 0x00FF0000) >> 16);
55+
offset++;
56+
userBuf[offset] = (byte)((dwExpTime & 0x0000FF00) >> 8);
57+
offset++;
58+
userBuf[offset] = (byte)(dwExpTime & 0x000000FF);
59+
offset++;
60+
61+
//dwPrivilegeMap
62+
userBuf[offset] = (byte)((dwPrivilegeMap & 0xFF000000) >> 24);
63+
offset++;
64+
userBuf[offset] = (byte)((dwPrivilegeMap & 0x00FF0000) >> 16);
65+
offset++;
66+
userBuf[offset] = (byte)((dwPrivilegeMap & 0x0000FF00) >> 8);
67+
offset++;
68+
userBuf[offset] = (byte)(dwPrivilegeMap & 0x000000FF);
69+
offset++;
70+
71+
//dwAccountType
72+
userBuf[offset] = (byte)((dwAccountType & 0xFF000000) >> 24);
73+
offset++;
74+
userBuf[offset] = (byte)((dwAccountType & 0x00FF0000) >> 16);
75+
offset++;
76+
userBuf[offset] = (byte)((dwAccountType & 0x0000FF00) >> 8);
77+
offset++;
78+
userBuf[offset] = (byte)(dwAccountType & 0x000000FF);
79+
offset++;
80+
return userBuf;
81+
}
1482
func hmacsha256(sdkappid int, key string, identifier string, currTime int64, expire int, base64UserBuf *string) string {
1583
var contentToBeSigned string
1684
contentToBeSigned = "TLS.identifier:" + identifier + "\n"

0 commit comments

Comments
 (0)