-
Notifications
You must be signed in to change notification settings - Fork 30
/
authticket.go
59 lines (52 loc) · 1.76 KB
/
authticket.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package sdk
import (
"encoding/base64"
"encoding/json"
"github.com/0chain/gosdk/core/common"
"github.com/0chain/gosdk/zboxcore/fileref"
"github.com/0chain/gosdk/zboxcore/marker"
)
type AuthTicket struct {
b64Ticket string
}
func InitAuthTicket(authTicket string) *AuthTicket {
at := &AuthTicket{}
at.b64Ticket = authTicket
return at
}
func (at *AuthTicket) IsDir() (bool, error) {
sEnc, err := base64.StdEncoding.DecodeString(at.b64Ticket)
if err != nil {
return false, common.NewError("auth_ticket_decode_error", "Error decoding the auth ticket."+err.Error())
}
authTicket := &marker.AuthTicket{}
err = json.Unmarshal(sEnc, authTicket)
if err != nil {
return false, common.NewError("auth_ticket_decode_error", "Error unmarshaling the auth ticket."+err.Error())
}
return authTicket.RefType == fileref.DIRECTORY, nil
}
func (at *AuthTicket) GetFileName() (string, error) {
sEnc, err := base64.StdEncoding.DecodeString(at.b64Ticket)
if err != nil {
return "", common.NewError("auth_ticket_decode_error", "Error decoding the auth ticket."+err.Error())
}
authTicket := &marker.AuthTicket{}
err = json.Unmarshal(sEnc, authTicket)
if err != nil {
return "", common.NewError("auth_ticket_decode_error", "Error unmarshaling the auth ticket."+err.Error())
}
return authTicket.FileName, nil
}
func (at *AuthTicket) GetLookupHash() (string, error) {
sEnc, err := base64.StdEncoding.DecodeString(at.b64Ticket)
if err != nil {
return "", common.NewError("auth_ticket_decode_error", "Error decoding the auth ticket."+err.Error())
}
authTicket := &marker.AuthTicket{}
err = json.Unmarshal(sEnc, authTicket)
if err != nil {
return "", common.NewError("auth_ticket_decode_error", "Error unmarshaling the auth ticket."+err.Error())
}
return authTicket.FilePathHash, nil
}